Skip to content
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

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

bsweger
Copy link
Collaborator

@bsweger bsweger commented Oct 9, 2024

Resolve #33

See the linked issue for details. Essentially, this PR modifies two cases when setting sequence_as_of and tree_as_of dates for CladeTime 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.

@bsweger bsweger requested a review from elray1 October 9, 2024 20:50
return self._sequence_as_of

@sequence_as_of.setter
def sequence_as_of(self, date) -> None:
Copy link
Collaborator Author

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.

Copy link
Collaborator

@elray1 elray1 left a 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.

pyproject.toml Show resolved Hide resolved
src/cladetime/cladetime.py Outdated Show resolved Hide resolved
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)
Copy link
Collaborator

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...

Copy link
Collaborator

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)

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)
Copy link
Collaborator

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

bsweger and others added 2 commits October 10, 2024 15:11
Fix logic that gets the current datetime for the UTC timezone.
Also ensure that CladeTime treats all incoming dates as UTC.
Copy link
Collaborator

@elray1 elray1 left a 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!

@bsweger bsweger merged commit 92f9e46 into main Oct 10, 2024
1 check passed
@bsweger bsweger deleted the bsweger/update-cladetime-date-validations/33 branch October 25, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update timestamp validations when instantiating CladeTime class
2 participants