gr2m / moment-parseformat

A moment.js plugin to extract the format of a date/time string
http://gr2m.github.io/moment-parseformat
Apache License 2.0
45 stars 30 forks source link

06-24-2014 00:28 → YY-MM-DDD H:mm #7

Closed keminming closed 10 years ago

keminming commented 10 years ago

moment.parseFormat('06-24-2014 00:28') parsed to YY-MM-DDD H:mm, I expected: <MM-DD-YYYY H:mm>

gr2m commented 10 years ago

Yes, that's a tough one, it's a known problem. For Month-Day-Year, you have to use the / separator, for example try 06/24/2014 00:28. We could check if the day is > 12 and then react on it, but that's not very reliable.

Would be good to find a smarter way though, didn't came up with one yet

keminming commented 10 years ago

i like your parser. recognizing most format. i think there should be some difficulty even for human to read. what about recognize 4 digit as year at highest priority. by the way seems moment.js dont have a good solution to parse time zone like "pdt", does it? i think many time format include that. but didnt find authors answer. On Jun 24, 2014 2:32 AM, "Gregor Martynus" notifications@github.com wrote:

Yes, that's a tough one, it's a known problem. For Month-Day-Year, you have to use the / separator, for example try 06/24/2014 00:28. We could check if the day is > 12 and then react on it, but that's not very reliable.

Would be good to find a smarter way though, didn't came up with one yet

— Reply to this email directly or view it on GitHub https://github.com/gr2m/moment.parseFormat/issues/7#issuecomment-46940161 .

gr2m commented 10 years ago

moment has a whole module dedicated to time zones, maybe that helps? http://momentjs.com/timezone/

Regarding time zones and parseFormat: that is out of scope for me. parseFormat is intended to be used on human input, and I can't think of when a human would add a time zone acronym or add something like +02:00, that's more a machine thing I'd say.

I just realized I misunderstood the problem you where reporting. moment.parseFormat('06-24-2014 00:28') definitely should parse the year first, I'll get back to it

keminming commented 10 years ago

yeah, i have checked their new time zone model. but not what i want. the thing im working on is parsing a time from a web page, like the date on a news report and make it easy to add into calendar. so the time zone is also important to me. On Jun 24, 2014 2:50 AM, "Gregor Martynus" notifications@github.com wrote:

moment has a whole module dedicated to time zones, maybe that helps? http://momentjs.com/timezone/

Regarding time zones and parseFormat: that is out of scope for me. parseFormat is intended to be used on human input, and I can't think of when a human would add a time zone acronym or add something like +02:00, that's more a machine thing I'd say.

I just realized I misunderstood the problem you where reporting. moment.parseFormat('06-24-2014 00:28') definitely should parse the year first, I'll get back to it

— Reply to this email directly or view it on GitHub https://github.com/gr2m/moment.parseFormat/issues/7#issuecomment-46941448 .

gr2m commented 10 years ago

If you just need to understand the date/time, moment.parseFormat might not be the right tool, as it extracts the date/time format so you can use it e.g. as a user default setting.

keminming commented 10 years ago

i just thougt it could help me to avoid writing a lot of format myself. my program can learn some new format from user.. On Jun 24, 2014 2:57 AM, "Gregor Martynus" notifications@github.com wrote:

If you just need to understand the date/time, moment.parseFormat might not be the right tool, as it extracts the date/time format so you can use it e.g. as a user default setting.

— Reply to this email directly or view it on GitHub https://github.com/gr2m/moment.parseFormat/issues/7#issuecomment-46942112 .

gr2m commented 10 years ago

Yeah sure, feel free to send a pull request to add support for time zones, I just wanted to point out that parseFormat is not optimized for your use case, that's all :)

keminming commented 10 years ago

ok, cool. i will keep using these two libraries and try to find something useful. On Jun 24, 2014 3:02 AM, "Gregor Martynus" notifications@github.com wrote:

Yeah sure, feel free to send a pull request to add support for time zones, I just wanted to point out that parseFormat is not optimized for your use case, that's all :)

— Reply to this email directly or view it on GitHub https://github.com/gr2m/moment.parseFormat/issues/7#issuecomment-46942506 .