Code Monkey home page Code Monkey logo

Comments (3)

devbww avatar devbww commented on May 17, 2024 1

Right ... %Y will happily continue to consume digits for the year, and there is no backtracking to retry failed matches with less greediness.

If you know that your year spans exactly four digits, use the %E4Y specifier. That is "%E4Y%m%d" will successfully parse "20140304" as 2014-03-04.

Aside: "%Y%m%d" on "20140304" doesn't return 1970-01-01 ... it fails (returns false) and leaves the output time_point alone.

from cctz.

Siesh1oo avatar Siesh1oo commented on May 17, 2024

Great to know, thank you!

I wonder whether this may possibly become a somewhat frequent issue when adopted as standard ("%Y" is quite common after all, as are time formats without delimiters), the format strings might better be kept backwards-compatible to strftime()/strptime(), and extensions should be pure extensions, without breaking traditional, expected behavior?

A possible backwards-compatible format could be:

"%Y" -- strptime()-like four-digit year YYYY
"%E#Y" -- Year with # digits of fractional precision
"%EY" -- Year with arbitrary fractional precision

What do you think?

from cctz.

devbww avatar devbww commented on May 17, 2024

Hi,

Thanks for the suggestion. We agree with you that this might be a not-totally-uncommon transition issue. However, we also think that the current greedy %Y is the "best" behavior.

So, for the time being we'll add something more prominent to time_zone.h where %Y is described. However we will certainly raise this question during any standardization process.

Thanks again.

from cctz.

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.