-
Notifications
You must be signed in to change notification settings - Fork 9
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
Use only timezones for datetime parser #108
Use only timezones for datetime parser #108
Conversation
def datetime_parser(string: str) -> datetime: | ||
if string == "now": | ||
return datetime.now() | ||
for format in DATETIME_SUPPORTED_FORMATS: | ||
try: | ||
return datetime.strptime(string, format) | ||
except ValueError: | ||
pass | ||
return datetime.now(tz=timezone.utc).replace(tzinfo=None) | ||
try: | ||
return ( | ||
datetime.fromisoformat(string) | ||
.astimezone(timezone.utc) | ||
.replace(tzinfo=None) | ||
) | ||
except ValueError: | ||
for format in DATETIME_SUPPORTED_FORMATS: | ||
try: | ||
return datetime.strptime(string, format) | ||
except ValueError: | ||
pass |
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.
so this basically ensures that all strings are setted with a timezone to UTC. But do we know if all the 'dates' are being held first as strings?
Should we check that all dates are set with a certain 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.
# now
>>> datetime_parser("now")
datetime.datetime(2024, 8, 8, 7, 58, 37, 248673)
# with timezone in the name
>>> datetime_parser("2024-06-18T13:00:00.000+02:00")
datetime.datetime(2024, 6, 18, 11, 0)
# full date in the timezone of the computer
>>> datetime_parser("2024-06-18T13:00:00.000")
datetime.datetime(2024, 6, 18, 11, 0)
# full date UTC
>>> datetime_parser("2024-06-18T13:00:00.000Z")
datetime.datetime(2024, 6, 18, 13, 0)
# year month day WRONG
>>> datetime_parser("2024-06-18")
datetime.datetime(2024, 6, 17, 22, 0)
So yeah I will look a bit more into it
Then, for any date that is being played with, should be passed within this function, no? Should we review the code or it0s already done and we keep in mind for the following implementations? |
bf04505
to
3d27ae3
Compare
take into account the timezone when parsing datetime and getting the time from the computer
take into account the timezone when parsing datetime and getting the time from the computer
take into account the timezone when parsing datetime and getting the time from the computer
take into account the timezone when parsing datetime and getting the time from the computer
take into account the timezone when parsing datetime and getting the time from the computer
Fix CMT-64