Created
May 17, 2013 01:24
-
-
Save kosso/5596339 to your computer and use it in GitHub Desktop.
Is BST in effect?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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