Moment-timezone: Parse date using timezone return different values based on format

Created on 18 Oct 2019  路  2Comments  路  Source: moment/moment-timezone

Parsing date using timezone returns different output if used with and without date format.

Current result:

moment.tz("18 Oct 2019, 15:40:42", "Europe/London").valueOf()
1571413242000
moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "Europe/London").valueOf()
1571409642000

Expected result:

moment.tz("18 Oct 2019, 15:40:42", "Europe/London").valueOf()
1571409642000
moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "Europe/London").valueOf()
1571409642000

This does not look like expected behaviour.
Result of converting date based on timezone should not be dependent on date formatting.

bug

Most helpful comment

The problem is that moment-timezone only accepts auto parse for RFC2822 or ISO format.

var moment1 = moment.tz("2019-10-18T15:40:42", "America/New_York").valueOf();
var moment2 = moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "America/New_York").valueOf();

All 2 comments

The problem is that moment-timezone only accepts auto parse for RFC2822 or ISO format.

var moment1 = moment.tz("2019-10-18T15:40:42", "America/New_York").valueOf();
var moment2 = moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "America/New_York").valueOf();

This is the same bug as https://github.com/moment/moment-timezone/issues/807 - @todo fix it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edu2004eu picture edu2004eu  路  6Comments

palindrom615 picture palindrom615  路  4Comments

SathyaChenniappan picture SathyaChenniappan  路  4Comments

guidsen picture guidsen  路  4Comments

mj1856 picture mj1856  路  5Comments