You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we take the exact moment when the timezone change occurs, Moment Timezone advances us one hour forward due to the timezone change. In the week 2023-09-03 to 2023-09-09, in Chile, on the date 2023-09-03, the timezone change occurs. If we stand on any date this week and perform a start of week operation, it will return the time 2023-09-03 but at 00:00 hours. If we clone this time, the clone moves it one hour forward, causing issues when we use the add function and convert it to UTC, generating incorrect dates. However, if we apply start of week after cloning, the problem is resolved, and it correctly processes the additions we want to make but from week 1 onwards. If we want to do it in the same week (week 0), it becomes misaligned when converted to UTC.
To Reproduce
Steps to reproduce the behavior:
Create a file named script.ts.
Paste the code written below.
import * as moment from "moment-timezone";
const dateString = "2023-09-09T00:00:00";
//Time when the daylight saving time change occurs.
console.log( moment.tz( "2023-09-03T00:00:00", "America/Santiago"))
//Date in timezone America/Santiago -3
let date = moment.tz(dateString, "America/Santiago");
//Date when the daylight saving time change occurs getting with a start of week
console.log(date.startOf("week"))
//at this point the start is applied
// Clone the date and see how it modifies the value due to the timezone change.
console.log(date.clone());
//clone the date and apply the start of week
console.log(date.clone().startOf('week'))
//add 0 week and 3 days and 8 hours without apply start of week before clone
console.log(date.clone().add(0, "week").add(3, "day").add(8, "hour"));
console.log(date.clone().add(0, "week").add(3, "day").add(8, "hour").utc());//utc
//add 0 week and 3 days and 8 hours with start of week applied before clone
console.log(date.clone().startOf("week").add(0, "week").add(3, "day").add(8, "hour"));
console.log(date.clone().startOf("week").add(0, "week").add(3, "day").add(8, "hour").utc());//utc
//add 1 week and 3 days and 8 hours without apply start of week before clone
console.log(date.clone().add(1, "week").add(3, "day").add().add(8, "hour"));
console.log(date.clone().add(1, "week").add(3, "day").add().add(8, "hour").utc());//utc
//add 1 week and 3 days and 8 hours with start of week applied before clone
console.log(date.clone().startOf("week").add(1, "week").add(3, "day").add(8, "hour"));
console.log(date.clone().startOf("week").add(1, "week").add(3, "day").add(8, "hour").utc());//utc
Validate this output (it should be the same as long as the bug exists).
Notice that when you use clone after using a start of week, it changes the hour and moves it one hour forward. This causes it to always be one hour ahead, both in the specific timezone and in UTC, when you add weeks, days, and hours.
"Note that when you apply a start of the week to the cloned time, it removes the offset. However, if you use add to move within the same week, the offset persists. But if you move to the next week using add(1, "week"), it works correctly and delivers the time correctly."
Expected behavior
What you should expect is that when you clone the time, the hour should retain exactly the state it had, even at a moment when a timezone change occurs.
That when I use an 'add' from a date where the timezone change occurs, it generates the jumps correctly using 'add,' not as it happens in the code from the previous point.
Screenshots
Look, in Chile, during these dates, 8 am is 11 am in UTC. However, due to the clone issue, it's delivering it at 12 am.
I've attached an image and link of the daylight saving time changes.
Desktop (please complete the following information):
OS: Ubuntu 22.04.3 LTS
Node JS app
Node v18.1.0
moment "^2.29.4"
moment-timezone "0.5.43"
Moment-specific environment
America/Bogota
2023/09/07
typescript
Please run the following code in your environment and include the output:
Additional context
I only tested it with this specific timezone change; it was not tested with another timezone change elsewhere in the world or within Chile.
The text was updated successfully, but these errors were encountered:
Describe the bug
When we take the exact moment when the timezone change occurs, Moment Timezone advances us one hour forward due to the timezone change. In the week 2023-09-03 to 2023-09-09, in Chile, on the date 2023-09-03, the timezone change occurs. If we stand on any date this week and perform a start of week operation, it will return the time 2023-09-03 but at 00:00 hours. If we clone this time, the clone moves it one hour forward, causing issues when we use the add function and convert it to UTC, generating incorrect dates. However, if we apply start of week after cloning, the problem is resolved, and it correctly processes the additions we want to make but from week 1 onwards. If we want to do it in the same week (week 0), it becomes misaligned when converted to UTC.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Screenshots
Look, in Chile, during these dates, 8 am is 11 am in UTC. However, due to the clone issue, it's delivering it at 12 am.
![image](https://private-user-images.githubusercontent.com/18221796/266461736-2626799e-f6d8-44ea-b7a2-7afd6b756323.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ3MTcyNzUsIm5iZiI6MTcyNDcxNjk3NSwicGF0aCI6Ii8xODIyMTc5Ni8yNjY0NjE3MzYtMjYyNjc5OWUtZjZkOC00NGVhLWI3YTItN2FmZDZiNzU2MzIzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI3VDAwMDI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMwYTU3ZDMzOTljMmM0OTE3NDBlMTVlZjFkNGM3MWFhZWEwZDk3ZWIzNDJiNWVlYWQ5YzFjOTg4MWNmYTk2ZjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.dkR2zjQudYeWuRl9mAs4iNuDmOnYgL_JyW4aqY3UJf8)
I've attached an image and link of the daylight saving time changes.
Desktop (please complete the following information):
Moment-specific environment
Please run the following code in your environment and include the output:
Additional context
I only tested it with this specific timezone change; it was not tested with another timezone change elsewhere in the world or within Chile.
The text was updated successfully, but these errors were encountered: