There are many solutions available in javascript to check whether the date is in daylight or not [ How to check if the DST (Daylight Saving Time) is in effect and if it is what's the offset? ].
But that solutions work only when someone is in the same time zone where daylight effect is applicable, ex. Suppose my current browser (client) is in IST (Indian standard - where there is no daylight time change) and I want to check whether the date is in daylight or not for ET (Eastern time - where daylight is -5 and standard is -4). Above solution (from link) would give me correct result only if my systems time zone is in ET not IST.
How can I calculate it?
To check if DST (Daylight Saving time) is in effect:Use the getTimezoneOffset() method to get the timezone offset for the 2 dates. Check if the greater of the two values is not equal to the offset for the original date.
We can solve this problem in simple 5 steps. Obtain the current UTC time, by adding the local time zone offset to the local time. Obtain the destination city's UTC offset in hours, convert it to milliseconds and add it to UTC time. Convert final msec value into new Date string.
Test transition of DST, i.e. when you are currently in summer time, select a time value from winter. Test boundary cases, such as a timezone that is UTC+12, with DST, making the local time UTC+13 in summer and even places that are UTC+13 in winter.
pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime. tzinfo ).
If you use moment.js
and it's companion timezome
script, they make checking for DST pretty easy:
Check out their docs for isDST()
Just for grins, here's a fiddle testing each timezone
if( moment.tz("America/New_York").isDST() ){
$('#test').append('NY is currently in DST');
}
else{
$('#test').append('NY is NOT currently in DST');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<script src="http://momentjs.com/downloads/moment-timezone-with-data.min.js"></script>
<div id="test"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With