Skip to content

Instantly share code, notes, and snippets.

@kosso
Created May 17, 2013 01:24
Show Gist options
  • Save kosso/5596339 to your computer and use it in GitHub Desktop.
Save kosso/5596339 to your computer and use it in GitHub Desktop.
Is BST in effect?
function isBSTinEffect(){
var d = new Date();
var lSoM;
// Loop over the 31 days of March for the current year
for(var i=31; i>0; i--){
var tmp = new Date(d.getFullYear(), 2, i);
// If it's Sunday
if(tmp.getDay() == 0){
// last Sunday of March
lSoM = tmp;
// And stop the loop
break;
}
}
// Loop over the 31 days of October for the current year
for(var i=31; i>0; i--){
var tmp = new Date(d.getFullYear(), 9, i);
// If it's Sunday
if(tmp.getDay() == 0){
// last Sunday of October
lSoO = tmp;
// And stop the loop
break;
}
}
// 0 = DST off (GMT)
// 1 = DST on (BST)
if(d < lSoM || d > lSoO){
is_bst = false;
//Ti.API.info('isBSTinEffect BST FALSE');
return false;
} else {
is_bst = true;
//Ti.API.info('isBSTinEffect BST TRUE');
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment