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

Better automatic date parsing for DateList[] #555

Merged
merged 6 commits into from
Sep 20, 2016
Merged

Conversation

poke1024
Copy link
Contributor

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

Copy link
Member

@sn6uv sn6uv left a 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*')
Copy link
Member

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?
Copy link
Member

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

Copy link
Member

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[]]',
Copy link
Member

@sn6uv sn6uv Sep 17, 2016

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=="]]',

@sn6uv sn6uv merged commit 6b14846 into mathics:master Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants