![]() ![]() This is discouraged and will be removed in upcoming major release. But how to do so?ĭeprecation warning: moment construction falls back to js Date. I get the same error as I am trying to convert from "9:00 AM" format to "00:00:00" format so I can store it as a TIME type in MySQL database. If we remove the Date constructor fall-back, we can actually make the ISO parser less strict, since it won't be preempting a better parse.We could make moment(string) extensible, and then someone could create a plugin that either uses a list of well-known formats or just the Date constructor to parse them.If you really want to use the date constructor, you can always just use the date constructor and pass the date into Moment.So even if you test all your browsers, did you test all your locales? It's terrible for us to even pretend this stuff works. new Date("") is May 6 in American browsers but June 5 in English browsers. I'm pretty sure the constructor works differently in different locales for the same browser.moment('') doesn't use the Date constructor anyway). The most reliable way of using the Date string constructor was always new Date(''), which is now handled by the ISO parser anyway (i.e.That a string might go into the Date constructor or the ISO parser is ugly and confusing.We should start issuing a deprecation warning right away. Every other case is just silently waiting to break at some point. The only use-case for using Date to parse input is when a) it is entered by a web user (moment's user's user :)) and b) the web user can see how we're interpreting the date entered. I think it should be clear to users when they're hitting this case, and that it might not work well on all browsers. You'd pass a string only, hoping that it would hit one of the predefined formats, but instead it hits Date and it sort-of works, sometimes. I've debugged that numerous times thank to our old friend IE6 and friends. So I think we need an option to disable it, for tests at the very least. ![]() Using Date to create a moment from string, passed from the user is extremely unpredictable, and it turns out to work somewhat and then bite you in an edge case when you're not careful Read below for the rationale about the changeĪs described in #1403 (comment), but also recent debugging c4d9f6e and 94d6c90 caused by brings me to the conclusion that If you really want that behavior just do moment(new Date("random string that contains date")), but moment won't be responsible for such convertions. In the upcoming releases a few more well defined formats might be added, but the general idea of using any random string to construct a date is no more. moment ( "5" ) > moment ( "Thu 12:32:21 GMT-0700 (PDT)" ) > moment ( "some random string that looks like date" ) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |