moment-timezone icon indicating copy to clipboard operation
moment-timezone copied to clipboard

defaulting to current date-time uses UTC (ignores timezone)

Open vishnukumarnekkanti opened this issue 4 years ago • 3 comments

Moment created from formatting time sets the date as the UTC date rather than the date of the default timezone EX:

m = require('moment-timezone') _ = m.tz.setDefault("Asia/Kolkata") console.log(m()) console.log(m("T22:00","THH:mm"))

Output: moment.parseZone("2020-07-20T03:33:18.943+05:30") moment.parseZone("2020-07-19T22:00:00.000+05:30")

vishnukumarnekkanti avatar Jul 19 '20 22:07 vishnukumarnekkanti

I'm pretty sure I'm seeing some behaviour related to this. It's currently 2020-07-27 in Sydney, however UTC is still the 26th. Any value I have tried from 00:00 to 23:59 gives a date on the 26th.

moment.tz("Australia/Sydney").format()
-> "2020-07-27T02:24:03+10:00"

moment.tz("00:00", "H:m", "Australia/Sydney").format()
-> "2020-07-26T00:00:00+10:00"
moment.tz("23:59", "H:m", "Australia/Sydney").format()
-> "2020-07-26T23:59:00+10:00"

If I however advance my clock to a point where Sydney and UTC are both in the same day(27th), I get stamps for the 27th as I would expect.

Tugzrida avatar Jul 26 '20 16:07 Tugzrida

Yep, I can reproduce this issue on latest moment + moment-timezone. Some mechanism to request "current local time" from moment to moment-timezone might be required.

ichernev avatar Aug 26 '22 13:08 ichernev

can you assign this project to me

Junaid20001 avatar Oct 08 '22 08:10 Junaid20001