Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Date.getTimezoneOffset() not observing daylight savings

I'm trying to create a clock face with an arc that shows sunrise and sunset times. When trying to calculate the angles, I have the following code to determine whether daylight savings is in effect:

 

 

Date.prototype.stdTimezoneOffset = function () {
    var jan = new Date(this.getFullYear(), 0, 1);
    var jul = new Date(this.getFullYear(), 6, 1);
    console.log(jan + " : " + jul);
    console.log(jan.getTimezoneOffset() + " : " + jul.getTimezoneOffset());
    return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}

 

 

However, the console returns the following:
 

 

[3:44:47 PM] App: Fri Jan 01 2021 00:00:00 GMT-05:00 : Thu Jul 01 2021 00:00:00 GMT-05:00 (app/index.js:150,1)
[3:44:47 PM] App: 300 : 300 (app/index.js:150,1)

 

 
I am in the US Central timezone, so the offset for January should by 360 or GMT -06:00. How can I check if daylight savings is currently in effect?
Best Answer
0 Votes
1 REPLY 1

Hi @AidanBlack I've moved your post out of hardware support and into clock/app development support 

Best Answer