-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable default timezone information #197
Conversation
Sorry, lost in notification spam. Tagging for review. |
I would like to clarify whether the Czech datetime extractor is injecting tzinfo in all the scenarios where @JarbasAl's logic does so in the other files. |
Hi, @ChanceNCounter when I did a Czech support, I took a English files and did 1:1 copy. If You need to change something, write what an I will look into it. 🙂 |
lingua_franca/internal.py
Outdated
# Check if we need to add timezone awareness to any datetime object | ||
if config.inject_timezones: | ||
for key, value in kwargs.items(): | ||
if isinstance(value, datetime) and value.tzinfo is None: | ||
kwargs[key] = to_local(value) | ||
for idx, value in enumerate(args): | ||
if isinstance(value, datetime) and value.tzinfo is None: | ||
args = args[:idx] + (to_local(value),) + args[idx + 1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@krisgesling I am confused by this tuple's tupleyness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I did a double take on it at first too.
('a')
provides a string; whilst
('a',)
provides a single item tuple
I've switched it out to use iterable unpacking:
args = (*args[:idx], to_local(value), *args[idx + 1:])
hopefully this is more readable, though I also don't see it being used a lot so may still confuse some people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's significantly more readable, in that I thought the outer type was a list, but now I'm wondering why args
is a tuple 👅
@Tony763 I see that now, thanks! I was just as confused by the snippet's absence from the English parser, but I've checked, and all paths add tzinfo to that temp var. |
Apart from the remaining question on |
dt = datetime.datetime(2017, 1, 31, | ||
13, 22, 3) | ||
dt = datetime.datetime(2017, 1, 31, | ||
13, 22, 3, tzinfo=default_timezone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small note, i think its good to be explicit here, but passing this is fully optional, part of what this PR does is handle this transparently
the tests only need tzinfo added in returned results, all input dates will get it appended internally
in a sense this last commit adding all those tzinfos in optional places is now removing the testing for the functionality added by this PR
as i said i think it's good to be explicit in what is being tested, this comment is merely informative, not a request for a change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is an issue I think.
With the naive datetimes having UTC tzinfo added, from memory the tests will fail if that's not your configured default unless you explicitly pass an aware object. So it is a bit of a patch job - we really need more detailed testing that checks those different scenarios.
I've just added an attempted test for using an explicitly different timezone. However it also suggests that one of the dot points from the PR description is false:
This is also what the docstring says, but it possibly should be:
|
I agree, and had been reading,
We definitely don't want to clobber tz-aware datetimes back to the configured tz! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought I pressed approve on my previous comment. Whoops =)
- Switch None checks from == to is - Add default tzinfo to tests - remove stray commented code - improve readability of tuple - add test for extracting datetime in non-default timezone
b5fbb29
to
63ece83
Compare
What about we just remove the word "user's":
becomes
|
That'd work. |
Description
Adds configurable default timezone information for use by
lingua_franca.time.set_default_tz
now_local
foranchorDate
nice_time()
Extends and replaces PR #180 - squashed commits and fixed failing tests.
Type of PR
Testing
Unit tests have been updated.