Skip to content

Instantly share code, notes, and snippets.

@furf
Created April 21, 2009 18:14
Show Gist options
  • Save furf/99287 to your computer and use it in GitHub Desktop.
Save furf/99287 to your computer and use it in GitHub Desktop.
/**
* isDST
* Returns true if the supplied date (default Today) is DST
*/
var isDST = function(date) {
date = date ? new Date(date) : new Date();
var winter = new Date(date.getFullYear(), 0, 1);
return (date.getTimezoneOffset() !== winter.getTimezoneOffset());
};
/**
* hasDST
* Returns true if the supplied time zone (via date) observes DST
*/
var hasDST = function() {
return isDST(new Date((new Date()).getFullYear(), 6, 1, 0, 0, 0, 0));
};
/**
* Sample usage:
*
* console.log('hasDST', hasDST());
*
* console.log('Today', isDST());
* console.log('3/7/2009', isDST('3/7/2009'));
* console.log('3/8/2009', isDST('3/8/2009'));
* console.log('3/9/2009', isDST('3/9/2009'));
*
* console.log('10/31/2009', isDST('10/31/2009'));
* console.log('11/1/2009', isDST('11/1/2009'));
* console.log('11/2/2009', isDST('11/2/2009'));
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment