You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The last failing test I have in Thoth.Json currently are related to DateTime/DateTimeOffset and I work on a fix for that. While working on it, I discovered that the parse function is using dateutil which is not a Python standard API and so that function doesn't work.
Currently, I am doing something really naive to use the native API and support at least a subset of the .NET formatting date:
defparse(string: str, detectUTC: bool=False) ->datetime:
# from dateutil import parsertry:
returndatetime.fromisoformat(string)
exceptValueError:
try:
returndatetime.strptime(string, "%H:%M:%S")
exceptValueError:
try:
returndatetime.strptime(string, "%I:%M:%S %p")
exceptValueError:
# IMPORTANT: This format needs to be tested after %I:%M:%S %p# Otherwise, it happens that %H:%M:%S %p incorrectly parses some# of the string that can overlap with %I:%M:%S %p# Example: 1:5:34 PMtry:
returndatetime.strptime(string, "%H:%M:%S %p")
exceptValueError:
raiseValueError("Unsupported format by Fable")
Really ugly, I know ^^. This is just a temporary solution instead of something that crash rightnow.
If we want to use dateutil, we need to publish fable-library to PyPi (or whatever is the package repository in Python) and check if this doesn't create others issues like we discussed on Slack regarding the Rust distribution of the library.
Or embed the dateutil source code inside of Fable, like it has been done in the past for BigInt in JavaScript.
How do you envision the DateTime/DateTimeOffset parsing functions to be implemented?
The text was updated successfully, but these errors were encountered:
@MangelMaxime I would be happy if we could get rid of the dateutil dependency. Here's a copilot refactor of your code:
defparse(string: str, detectUTC: bool=False) ->datetime:
formats= {
# Matches a date-time string in the format "YYYY-MM-DDTHH:MM:SS"r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}": "%Y-%m-%dT%H:%M:%S",
# Matches a time string in 24-hour format "HH:MM:SS"r"\d{2}:\d{2}:\d{2}": "%H:%M:%S",
# Matches a time string in 12-hour format with AM/PM "HH:MM:SS AM" or "HH:MM:SS PM"r"\d{2}:\d{2}:\d{2} [AP]M": "%I:%M:%S %p",
}
forpattern, formatinformats.items():
ifre.fullmatch(pattern, string):
returndatetime.strptime(string, format)
raiseValueError("Unsupported format by Fable")
Description
Hello @dbrattli,
The last failing test I have in Thoth.Json currently are related to DateTime/DateTimeOffset and I work on a fix for that. While working on it, I discovered that the parse function is using
dateutil
which is not a Python standard API and so that function doesn't work.Fable/src/fable-library-py/fable_library/date.py
Lines 226 to 229 in 9276528
Currently, I am doing something really naive to use the native API and support at least a subset of the .NET formatting date:
Really ugly, I know ^^. This is just a temporary solution instead of something that crash rightnow.
If we want to use
dateutil
, we need to publish fable-library to PyPi (or whatever is the package repository in Python) and check if this doesn't create others issues like we discussed on Slack regarding the Rust distribution of the library.Or embed the
dateutil
source code inside of Fable, like it has been done in the past forBigInt
in JavaScript.How do you envision the DateTime/DateTimeOffset parsing functions to be implemented?
The text was updated successfully, but these errors were encountered: