Git Product home page Git Product logo

Comments (7)

rupert avatar rupert commented on July 24, 2024

python-dateutil 2.5.3 parses the above correctly.

However there's another issue with the day and month being swapped:

>>> from delorean import parse
>>> parse('2015-01-02').date
datetime.date(2015, 2, 1)
>>> parse('2015-01-13').date
datetime.date(2015, 1, 13)

Downgrading to 2.5.1 is a temporary workaround.

from delorean.

rupert avatar rupert commented on July 24, 2024

Looks like there is a bug with the dayfirst argument to dateutil.parser.parse.

In python-dateutil 2.5.1:

>>> from dateutil.parser import parse
>>> parse('2015-01-02')
datetime.datetime(2015, 1, 2, 0, 0)
>>> parse('2015-01-02', dayfirst=True)
datetime.datetime(2015, 1, 2, 0, 0)

In python-dateutil 2.5.3:

>>> from dateutil.parser import parse
>>> parse('2015-01-02')
datetime.datetime(2015, 1, 2, 0, 0)
>>> parse('2015-01-02', dayfirst=True)
datetime.datetime(2015, 2, 1, 0, 0)

dateutil bug: dateutil/dateutil#233 (comment)

from delorean.

rupert avatar rupert commented on July 24, 2024

In the latest version of dateutil (2.5.3) with dayfirst=True and yearfirst=True (the delorean defaults), XXXX-XX-XX will be parsed as YYYY-DD-MM (unless the last part is > 12 where it will be parsed as YYYY-MM-DD).

Might want to consider defaulting dayfirst=False so ISO 8601 dates are handled correctly.

from delorean.

myusuf3 avatar myusuf3 commented on July 24, 2024

@rupert any chance you want to make this switch add tests and update documentation?

from delorean.

rupert avatar rupert commented on July 24, 2024

Unfortunately I don't think you can handle ISO 8601 dates and something like DD/MM/YYYY (sensible default rather than MM/DD/YYYY) with the same datefirst argument in dateutil 2.5.3.

dayfirst=False parses ISO 8601 dates correctly but of course parses DD/MM/YYYY as MM/DD/YYYY:

>>> parse('2003-02-01', dayfirst=False)
datetime.datetime(2003, 2, 1, 0, 0)
>>> parse('01/02/2003', dayfirst=False) # wrong
datetime.datetime(2003, 1, 2, 0, 0)

dayfirst=True parses DD/MM/YYYY correctly but not ISO 8601 dates:

>>> parse('2003-02-01', dayfirst=True) # wrong
datetime.datetime(2003, 1, 2, 0, 0)
>>> parse('01/02/2003', dayfirst=True)
datetime.datetime(2003, 2, 1, 0, 0)

Possibly you could attempt to parse the date with the iso8601 library first and fallback to dateutil with dayfirst=True if that fails.

As an aside I'm actually not using delorean for parsing anymore as I think it's better to be explicit about which formats your program will accept.

This is a duplicate of #84.

from delorean.

rupert avatar rupert commented on July 24, 2024

Another option is pinning dateutil to <=2.5.1 and waiting for the new parsing interface in 2.6.

See this comment: dateutil/dateutil#229 (comment)

from delorean.

myusuf3 avatar myusuf3 commented on July 24, 2024

@rupert dateutil2.6 has been released as @gordol pointed out. Mine checking to see if it fixes the issues you name above?

from delorean.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.