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

There doesn't seem to be a way to handle either 2 or 4 digit years #2343

Closed
sjmeverett opened this issue Apr 23, 2015 · 11 comments
Closed

There doesn't seem to be a way to handle either 2 or 4 digit years #2343

sjmeverett opened this issue Apr 23, 2015 · 11 comments

Comments

@sjmeverett
Copy link

I feel that the following snippet:

moment('23/4/14', 'D/M/YYYY')

ought to return the date 2014-04-23 (using ISO for the avoidance of doubt), but instead it returns 0014-04-23, which is pretty unlikely to have been what the user intended.

The opposite way round:

moment('23/4/2014', 'D/M/YY')

gives you 2020-04-23, which isn't likely to have been what the user meant either...

To maintain backwards compatibility, perhaps there should be another format specifier, e.g. a single Y that doesn't care whether it gets a 2 digit year or a 4 digit year, and returns something sensible either way.

I.e., I want to be able to parse the user input and not care whether they used a 4 digit year or a 2 digit year, and use some sensible rules to return the date the user expected.

@mattjohnsonpint
Copy link
Contributor

👍 This would be a very good feature.

@sjmeverett
Copy link
Author

Cool, thanks. Any idea when it might appear?

@mattjohnsonpint
Copy link
Contributor

We're all volunteers here, so its hard to pin a timeline on anything. If it's urgent for you, feel free to make the modifications yourself and send a pull request. Thanks.

@sjmeverett
Copy link
Author

Sorry if that sounded like hassling, it wasn't my intention. Yes, I normally would have made a pull request already actually, but it's going to take me a little while to understand what to change on this one!

If I get there before you I'll submit a pull request :)

@mattjohnsonpint
Copy link
Contributor

😄

@icambron
Copy link
Member

icambron commented May 2, 2015

Very odd; I could have sworn this would default to use 2000.

@mattjohnsonpint
Copy link
Contributor

If we are to take that approach, then should't it use the moment.parseTwoDigitYear function? Currently, only YY will enter that function at all. We would need to change the parser to call whenever a two-digit year is present, regardless of being used with YY or YYYY. This may also have a small perf impact.

@ppoisson
Copy link

In Firefox using moment("6/12/15").format("M/D/YYYY h:mm:ss A") I get 6/12/1915 instead of 6/12/2015? How do I fix this?

@icambron
Copy link
Member

@ppoisson parse it with an explicit format string as the second arg; right now you're just using the native Date constructor.

@ppoisson
Copy link

Thanks!

@lizzzzard
Copy link

Would love to see it to, maybe as an additional langue-aware format. I'm currently using "l" and "L", but both use 4-digit-years, so I have to do manual checks for those formats additionally - which makes the locale-aware-formats kind of useless to me.

sjmeverett pushed a commit to sjmeverett/moment that referenced this issue Jul 20, 2015
Two digit years will use the parseTwoDigitYear function when parsing with the YYYY format.
Closes moment#2343
sjmeverett pushed a commit to sjmeverett/moment that referenced this issue Jul 21, 2015
Two digit years will use the parseTwoDigitYear function when parsing with the YYYY format.
Closes moment#2343
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants