Skip to content
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

The DST calculation does not take effect. #1077

Closed
fengnian7 opened this issue Oct 19, 2023 · 3 comments
Closed

The DST calculation does not take effect. #1077

fengnian7 opened this issue Oct 19, 2023 · 3 comments

Comments

@fengnian7
Copy link

Hello, excuse me. We are using the latest version 0.5.43, which was released on March 31st. Since April 17th, Egypt has re-implemented DST. We find that the software cannot correctly calculate the DST in this region. Is it because the time zone database used by the software is not updated? Do you have an update plan later? We look forward to your reply. Thank you very much.

@gilmoreorless
Copy link
Member

Egypt's DST actually started on April 28 (see https://www.timeanddate.com/time/change/egypt), and this change was implemented in version 0.5.42: #1047

Do you have an example of some code that isn't working for you?

@fengnian7
Copy link
Author

Do you have an example of some code that isn't working for you?

Thank you for your reply. I do see that 0.5.42 has considered the restart of DST in Egypt. Unfortunately, our DST didn't work, so I'll show the code below.
The following is a code snippet. The timestamp variable indicates the timestamp returned from the server, the formation variable indicates the time format displayed on the foreground page, and the timezone variable indicates the current time zone. Any questions can be answered, I will answer the first time, thank you again.

let date = moment(timestamp).format(formation);
 let isDST:boolean;
  if (moment(timestamp).tz(timezone)) {
    isDST = moment(timestamp).tz(timezone).isDST();
    if (isDST) {
      if (dstOffset === '0') {
        const offset = moment.tz(timezone)._offset;
        const timeZone = parseOffset(offset / 60 - 1);
        const timeSplit = date.split(' ');
        date = `${timeSplit[0]} ${timeSplit[1]} ${timeZone}`;
      }
      date = `${date} DST`;
    }
  }

@gilmoreorless
Copy link
Member

It's hard to tell what the problem would be without any example inputs or outputs. However, there are a couple of things I noticed:

  1. Don't use any properties prefixed with an underscore (._offset). These are internal properties that are not part of the official API, and could change without warning. In this case, you should use .utcOffset().
  2. The line const offset = moment.tz(timezone)._offset; is not using timestamp as an input. That means it will use the current date/time, which might have a different offset from the input timestamp, giving the wrong value for the formatted date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants