Coder Social home page Coder Social logo

Comments (6)

johnnyNcsu avatar johnnyNcsu commented on July 23, 2024

I am also seeing this issue with date strings of form '09-15' -> DD-D; expected MM-DD (moment treats as MM-DD).

Similarly, inputs for '09' -> DD (moment treats as MM) and '12' -> D (moment treats as MM).

And 'March 28, 2001' -> MMMM D, YYYY (this may be technically ok but I would think a better result would be MMMM DD, YYYY).

from moment-parseformat.

gr2m avatar gr2m commented on July 23, 2024

I don’t think that 09-15 or 09 would be useful input to be parsed with this library. I’d be okay to add proper parsing for YYYY M D / YYYY MM DD, although I have never seen this date format myself and given the issue is open for so long and nobody adding their +1s, it’s maybe too much of an edge case to be considered.

from moment-parseformat.

johnnyNcsu avatar johnnyNcsu commented on July 23, 2024

@gr2m Thanks for the quick reply. I think I misunderstood the purpose of this library. I am looking for a library that exposes the internal momentjs format string used to interpret the input if it (momentjs) determines that input to be a valid date string (i.e. return a format string consistent with a valid momentjs date string - which can be more forgiving than strict ISO8601 strings). Do I understand correctly that this is not the intention of moment-parseformat?

from moment-parseformat.

gr2m avatar gr2m commented on July 23, 2024

I am looking for a library that exposes the internal momentjs format string used to interpret the input if it (momentjs) determines that input to be a valid date string

I think momentjs is just passing the string to the native Date object that might or might not be able to parse the string correctly, it’s different based on the JavaScript runtime environment. I don’t think you can get access to the input format used to parse the string. This library is doing all the parsing by hand with lots and lots of regex :)

I use parseFormat to parse dates entered by humans. The idea is that someone can enter a date in a free text form and the app can understand both the entered date/time as well as the preferred date format of the user.

from moment-parseformat.

johnnyNcsu avatar johnnyNcsu commented on July 23, 2024

I think momentjs is just passing the string to the native Date object that might or might not be able to parse the string correctly

@gr2m Thanks. Yes, this makes sense and likely explains why momentjs does not seem to expose parsed date fields - even though they appear to have some notion of this in their parse flags object (_pf.parsedDateParts). It seems to be an empty array every time I check it.

I will spend more time with momentjs to try too understand it a bit better. There do appear to be cases where momentjs is making some attempt to interpret date strings before calling Date on the string (e.g. a string of "2001" is interpreted as the year 2001 by momentjs but native Date will interpret this as 2001 milliseconds). Perhaps this is a feature request better placed with momentjs - although the opaqueness of the native Date object may impose significant challenges for fulfilling this request.

Thanks again!

from moment-parseformat.

gr2m avatar gr2m commented on July 23, 2024

Keep me posted :) I’ll close this issue for the time being, maybe open a new issue if you have a plan™️

from moment-parseformat.

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.