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

parser doesn't seem to properly parse exif formatted datetime #101

Closed
jMyles opened this issue Mar 16, 2017 · 5 comments
Closed

parser doesn't seem to properly parse exif formatted datetime #101

jMyles opened this issue Mar 16, 2017 · 5 comments

Comments

@jMyles
Copy link

jMyles commented Mar 16, 2017

Hey there. Thanks for pendulum.

It seems that pendulum.parse() does the wrong thing for strings gleaned by PIL's ExifTags interface.

For example, on a Canon S-series camera, the string for the key 'DateTime" is:
'2016:12:26 15:45:28'

By pendulum parses this into this Pendulum object:
2017-03-16T11:21:27+00:00

@sdispater
Copy link
Owner

Well, the thing is the string is not really standard (the : separator is mostly reserved for time information) so pendulum will fallback on the dateutil parser which produces the error:

>>> from dateutil.parser import parse

>>> parse('2016:12:26 15:45:28')
datetime.datetime(2017, 3, 16, 15, 45, 28)

To make it work you have to use from_format():

>>> import pendulum

>>> pendulum.from_format('2016:12:26 15:45:28', '%Y:%m:%d %H:%M:%S')
# <Pendulum [2016-12-26T15:45:28+00:00]>

@jMyles
Copy link
Author

jMyles commented Mar 16, 2017

Roger. I agree it's an odd format, but to the degree that parse() is generally applicable for datetime representations to be found in the wild: do you think that Exif data from Canon cameras is common enough to warrant special logic?

If so, I can work on a pull request.

@sethmlarson
Copy link

I'm +1 on this having dealt with EXIF data in the past.

emattiza added a commit to emattiza/pendulum that referenced this issue Mar 17, 2017
Per [jMyles](sdispater#101) this
adds a test in pytest format with a single example
@emattiza
Copy link
Contributor

+1 on the issue as well. implemented a unit test for the single case presented above, and a slight modification to the COMMON regex used in the parser for YYYY:MM:DD separators. from_format does look to be the appropriate parse option though fwiw. PR this?

emattiza added a commit to emattiza/pendulum that referenced this issue Mar 20, 2017
Implemented changes to regex parser for common date formats to include
semicolon dates separated by YYYY:MM:DD per [Issue
101](sdispater#101)

Signed-off-by: Evan Mattiza <emattiza@gmail.com>
emattiza added a commit to emattiza/pendulum that referenced this issue Mar 21, 2017
Per [jMyles](sdispater#101) this
adds a test in pytest format with a single example. Alters COMMON
regex to include : as date-separator

Signed-off-by: Evan Mattiza <emattiza@gmail.com>
sdispater pushed a commit that referenced this issue Mar 21, 2017
Per [jMyles](#101) this
adds a test in pytest format with a single example. Alters COMMON
regex to include : as date-separator

Signed-off-by: Evan Mattiza <emattiza@gmail.com>
@sdispater
Copy link
Owner

Version 1.2.0 has just been released with this feature included.

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

No branches or pull requests

4 participants