Question

Is there any library for JavaScript which I can use to check if the day light saving is in effect for a specific time in a specific location.

For example, I would like to know for a date, say "July 1 05:30:00 UTC+0500 2009" in the time zone code, for example 110, if the day light saving is in effect. Additional information is always acceptable.

The time zone codes can be found here - http://msdn.microsoft.com/en-us/library/bb887715.aspx

Thanks for your help in advance.

Greets!

Was it helpful?

Solution

Javascript doesn't know anything about CRM time zone codes.

There aren't even any good libraries for JavaScript that can work with Windows time zone identifiers, like the ones you'd find when using TimeZoneInfo from .NET, or browsing through your Windows registry.

If you need to work with time zones in JavaScript, you'll need to convert to an IANA/Olson time zone identifier, and then use one of the libraries I mentioned here.

If you can work in .NET on the server, you could use this method to convert from a CRM Time Zone Id to a Windows Time Zone Id. You could then use this method to convert from Windows to IANA time zones. But if you're going to do that much work on the server anyway, I don't see why you wouldn't just do your data conversions there also.

If you're looking for a pure JavaScript solution that will work directly from the CRM time zone IDs, I'm sorry but as far as I know, that doesn't exist. You'd have to build it yourself and maintain it as timezone data changes.

OTHER TIPS

This will return true or false when given a timezone as input:

function stdTimezoneOffset() {
    var d = new Date();
    var jan = new Date(d.getFullYear(), 0, 1);
    var jul = new Date(d.getFullYear(), 6, 1);
    return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
function dst(offset) {
    var d = new Date(); // create Date object for the current location
    var utc = d.getTime() + (d.getTimezoneOffset() * 60000); // get UTC time in milliseconds
    var nd = new Date(utc + (3600000 * offset)); // Create net Date() for city with offset
    return d.getTimezoneOffset() < stdTimezoneOffset();
}
alert(dst('-5.0')); //New York
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top