-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update CladeTime tree_as_of and sequence_as_of date handling #34
Conversation
return self._sequence_as_of | ||
|
||
@sequence_as_of.setter | ||
def sequence_as_of(self, date) -> None: |
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.
The logic for setting sequence_as_of
and tree_as_of
default values is no longer the same, so created a setter for each of these properties.
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.
1 minor change suggested.
src/cladetime/cladetime.py
Outdated
if date is None: | ||
sequence_as_of = datetime.now() | ||
sequence_as_of = self._validate_as_of_date(date) | ||
utc_now = datetime.now().replace(tzinfo=timezone.utc) |
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.
might this actually end up pointing to a past time?
>>> now = datetime.now()
>>> utc_now = now.replace(tzinfo=timezone.utc)
>>> # Create a timezone object for Eastern Time (UTC-4)
>>> eastern_tz = timezone(timedelta(hours=-4))
>>> eastern_now = now.replace(tzinfo=eastern_tz)
>>>
>>> now
datetime.datetime(2024, 10, 10, 13, 50, 2, 440530)
>>> utc_now
datetime.datetime(2024, 10, 10, 13, 50, 2, 440530, tzinfo=datetime.timezone.utc)
>>> eastern_now
datetime.datetime(2024, 10, 10, 13, 50, 2, 440530, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)))
>>>
>>> eastern_now > utc_now
True
It seems like replace
here does not calculate the time corresponding to "now" in UTC...
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.
Maybe the operation we want is
utc_now = datetime.now(tz=timezone.utc)
src/cladetime/cladetime.py
Outdated
tree_as_of = self.sequence_as_of | ||
else: | ||
tree_as_of = self._validate_as_of_date(date) | ||
utc_now = datetime.now().replace(tzinfo=timezone.utc) |
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.
flagging same discussion as above
Co-authored-by: Evan Ray <[email protected]>
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.
this all looks good to me, thanks!
Resolve #33
See the linked issue for details. Essentially, this PR modifies two cases when setting
sequence_as_of
andtree_as_of
dates forCladeTime
objects:if no tree_as_of parameter is specified when instantiating CladeTime, tree_as_of should default to the sequence_as_of value.
if either tree_as_of or sequence_as_of is a future date, CladeTime instantiation should give a warning and use the current datetime value instead.