-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Better automatic date parsing for DateList[] #555
Conversation
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.
As a non-American I don't approve of choosing MM/DD/YYYY
when it's ambiguous but I guess I'll survive.
'fmt': '`1` is not a valid date format.', | ||
} | ||
|
||
automatic = re.compile(r'^([0-9]{1,4})([^0-9]+)([0-9]{1,2})\2([0-9]{1,4})\s*') |
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.
I'm wondering if repeating the separator is ideal, I'm thinking of e.g. 2016 09 17
(two spaces then one).
is_ambiguous = False | ||
else: | ||
month_day = '%m %d' | ||
is_ambiguous = not(i2 > 12 or i1 == i2) # is i2 not clearly a day? |
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.
Nice! I would have forgotten the 2016/09/09
case.
>> DateList["1/10/1991"] | ||
: The interpretation of 1/10/1991 is ambiguous. | ||
= {1991, 1, 10, 0, 0, 0.} | ||
|
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.
Can we also add
#> DateList["2016-09-09"]
#> DateList["7/8/9"]
@@ -303,18 +354,15 @@ class DateList(_DateFormat): | |||
= {..., 5, 18, 0, 0, 0.} | |||
#> DateList[{"5/18", {"Month", "Day"}}][[1]] == DateList[][[1]] | |||
= True | |||
#> Quiet[DateList[abc]] | |||
= DateList[abc] | |||
""" | |||
# TODO: Somehow check that the current year is correct | |||
|
|||
rules = { | |||
'DateList[]': 'DateList[AbsoluteTime[]]', |
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.
I'd suggest we add the rule:
'DateList["02/27/2013"]': 'Import[Uncompress["eJxTyigpKSi20tfPzE0v1qvITk7RS87P1QfizORi/czi/HgLMwNDvYK8dCUATpsOzQ=="]]',
Adds more careful handling of different date formats for the completely automatic
DateList[s_String]
case.This now gives a warning if the date cannot be unambiguously determined (also a test case now).