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

Added support for escaping within parsing formats #290

Merged
merged 5 commits into from
Mar 23, 2016
Merged

Added support for escaping within parsing formats #290

merged 5 commits into from
Mar 23, 2016

Conversation

ownaginatious
Copy link

It is currently impossible to parse dates which contain data matching an internal pattern used by arrow.

For example, Thursday, December 10, 2015 at 5:09pm -0700. A format string for arrow to parse this would be, MMMM D, YYYY at h:mma Z.

Unfortunately, this doesn't work because the a in at gets interpreted as the marker for am/pm parsing in accordance with the documentation here.

This pull request offers a workaround by escaping anything that is square bracketed within a format and interpreting it as only text.

This fixes the above pattern: MMMM D, YYYY [at] h:mma Z

Arrow can now successfully parse the expression:

>>> import arrow
>>> DATE_FORMAT = "MMMM D, YYYY [at] h:mma Z"
>>> my_date = "Thursday, December 10, 2015 at 5:09pm -0700" 
>>> arrow.get(my_date, DATE_FORMAT)
'<Arrow [2015-12-10T17:09:00-07:00]>'

The only caveat as that # must be escaped in all parsing formats with [#], as it's used as the replacement character when the expression is being built.

@andrewelkins andrewelkins merged commit 02894c5 into arrow-py:master Mar 23, 2016
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.

2 participants