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

Issue detecting invalid months in dates entered in other languages. #409

Closed
brksrly opened this issue Aug 23, 2012 · 3 comments
Closed

Issue detecting invalid months in dates entered in other languages. #409

brksrly opened this issue Aug 23, 2012 · 3 comments
Labels

Comments

@brksrly
Copy link

brksrly commented Aug 23, 2012

Not sure that there is a real bug here, but perhaps someone could spare some advice and help with a work around.

My users have free form input into date field and i am having some issues detecting if their input is invalid. DD-MMM-YYYY is the standard format in my world.

I noticed this behavior:
moment('01-Aug-2012','DD-MMM-YYYY')._d;

Wed Aug 01 2012 00:00:00 GMT-0600 (MDT)

moment('01-Nam-2012','DD-MMM-YYYY')._d;

Sun Jan 01 2012 00:00:00 GMT-0700 (MST)

Unfortunately moment seems to assume that it hasn't received a month and assumes January. I don't think this is ideal. It would be nice if this could be fixed or if the isValid() call could return false in this case.

I worked around this by just checking without the format
moment('01-Nam-2012').isValid();

false

But my application is internationalized and the moment(String) call would not consider the current global language when parsing.

moment.lang("fr",{Excluded for Brevity});
moment('01-Fev-2012').isValid();

false

Beyond manually parsing user input myself I can't think of a way that I can tell if a french user entered a valid month (01-Fev-2012) or and invalid month (01-Nam-2012) with this library.

Thanks

@timrwood
Copy link
Member

As far as the first issue goes, we should add in something to set a flag that the month is invalid if none of the month names are found.

Probably on this line. I'm working on another fix for isValid in #389 so I'll make sure this gets in as well.

@timrwood
Copy link
Member

The commit above has passing tests for invalid months.

@timrwood
Copy link
Member

timrwood commented Oct 1, 2012

This has been released with 1.7.1. #384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants