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
Stepping through days is not correct for Asia/Beirut. #4152
Comments
https://timezonedb.com/time-zones/Asia/Beirut 2015-03-29 there starts at 1am, not 12am. Basically when you add 1 day to You may want to do something like const moment = require('moment-timezone');
const tzStart = moment("2015-03-27T19:21:24.000Z").tz('Asia/Beirut');
const tzEnd = moment("2015-03-30T19:21:24.000Z").tz('Asia/Beirut');
const iterator = tzStart.clone().hour(12);
const end = tzEnd.clone().hour(12);
console.log('startOfDay: ' + iterator.clone().startOf('day').format());
console.log('endOfDay: ' + iterator.clone().endOf('day').format());
while (iterator <= end) {
console.log(' ');
// Move to next day.
iterator.add(1, 'days')
console.log('startOfDay: ' + iterator.clone().startOf('day').format());
console.log('endOfDay: ' + iterator.clone().endOf('day').format());
} output:
...but as you can see it says In any case, having DST taking place at 12am is what's causing trouble here. |
@sirxemic, thanks for pointing that out. Our app depends on stepping through days like this, so this causes our app to break. |
Yes, there are multiple open bugs related to moment.tz("2015-03-28T00:00:00+02:00", "Asia/Beirut").add(1, 'day').startOf('day').format()
//=> "2015-03-28T00:00:00+02:00" should be "2015-03-29T01:00:00+03:00"
moment.tz("2015-03-28T01:00:00+03:00", "Asia/Beirut").add(1, 'day').endOf('day').format()
//=> "2015-03-28T22:59:59+02:00" should be "2015-03-29T23:59:59+02:00" To work around this bug: moment.tz("2015-03-28T00:00:00+02:00", "Asia/Beirut").hour(12).add(1, 'day').startOf('day').format()
//=> "2015-03-29T01:00:00+03:00"
moment.tz("2015-03-28T01:00:00+03:00", "Asia/Beirut").hour(12).add(2, 'days').startOf('day').subtract(1, 'ms').format()
//=> "2015-03-29T23:59:59+03:00" In your case, adjust your sample code as follows: const tzStart = moment("2015-03-27T19:21:24.000Z").tz('Asia/Beirut');
const tzEnd = moment("2015-03-30T19:21:24.000Z").tz('Asia/Beirut');
const startOfDay = tzStart.clone().startOf('day');
const endOfDay = tzStart.clone().hour(12).add(1, 'day').startOf('day').subtract(1, 'ms');
while (endOfDay.isBefore(tzEnd)) {
console.log('startOfDay: ' + startOfDay.format());
console.log('endOfDay: ' + endOfDay.format());
console.log(' ');
// Move to next day.
startOfDay.hour(12).add(1, 'days').startOf('day');
endOfDay.hour(12).add(2, 'days').startOf('day').subtract(1, 'ms');
} |
@mj1856, thanks for your workaround. After the workaround is applied, our internal test that was broken is not reporting the issue. Although many other of our tests are still broken, which I might file GitHub issues on later. |
I found that there is no test cases covering such scenarios in either moment's repo or moment-timezone's repo. I think at least there should be some tests to cover all supported timezones. |
@mj1856 Is this a bug in Moment or moment-timezone (or, possibly a combination)? I'm wondering if it needs to be moved to other repository? |
Description of the Issue and Steps to Reproduce:
I am seeing some strange behavior while using moment to step through each day between a moment range in timezone Asia/Beirut. I have created a minimal test case to demonstrate this behavior:
Please include the values of all variables used.
The above script produces:
startOfDay: 2015-03-27T21:21:24+02:00
endOfDay: 2015-03-27T23:59:59+02:00
startOfDay: 2015-03-28T00:00:00+02:00
endOfDay: 2015-03-28T23:59:59+02:00
startOfDay: 2015-03-28T00:00:00+02:00
endOfDay: 2015-03-29T23:59:59+03:00
startOfDay: 2015-03-28T00:00:00+02:00
endOfDay: 2015-03-30T23:59:59+03:00
This doesn't seem correct to me, as startOfDay in last 2 groups (in bold) stay on 2015-03-28, rather than moving to the next day.
If I change the timezone to another one like Asia/Shanghai, it produces:
startOfDay: 2015-03-28T03:21:24+08:00
endOfDay: 2015-03-28T23:59:59+08:00
startOfDay: 2015-03-29T00:00:00+08:00
endOfDay: 2015-03-29T23:59:59+08:00
startOfDay: 2015-03-30T00:00:00+08:00
endOfDay: 2015-03-30T23:59:59+08:00
startOfDay: 2015-03-31T00:00:00+08:00
endOfDay: 2015-03-31T23:59:59+08:00
Which is correct.
Environment:
Node.JS v6.10.3 on Ubuntu 16.0.4
Other information that may be helpful:
If you are reporting an issue, please run the following code in the environment you are using and include the output:
The text was updated successfully, but these errors were encountered: