Skip to content

Instantly share code, notes, and snippets.

@thedeeno
Created August 2, 2010 21:01
Show Gist options
  • Save thedeeno/505300 to your computer and use it in GitHub Desktop.
Save thedeeno/505300 to your computer and use it in GitHub Desktop.
if (todayIsInRange('1/1', '3/20')){
gotoAndStop("winter");
}
else if (todayIsInRange('3/21', '5/17')){
gotoAndStop("spring");
}
else if (todayIsInRange('5/18', '5/31')){
gotoAndStop("memorial");
}
else if (todayIsInRange('6/1', '7/4')){
gotoAndStop("july4th");
}
else if (todayIsInRange('7/5', '8/22')){
gotoAndStop("summer");
}
else if (todayIsInRange('8/23', '9/6')){
gotoAndStop("laborday");
}
else if (todayIsInRange('9/7', '10/31'){
gotoAndStop("fall");
}
else if (todayIsInRange('11/1', '12/31')){
gotoAndStop("holiday");
}
else {
// If we get here, today's date didn't
// fall in any range listed above.
// You should put the error, or the default action here.
}
// helper functions
// returns true if today is on or between the start and end month/day
function todayIsInRange(start, end) {
var today = new Date();
var current_year = today.getYear();
var start_date = getDateFromShortHand(start, current_year);
var end_date = getDateFromShortHand(end, current_year);
return (start_date <= today) && (today <= end_date);
}
// turns strings in the 'month/day' format into actual dates for the specified year.
// for example:
// getDateFromShortHand('11/2', 2010);
// returns:
// the date type for '2/11/2010'
function getDateFromShortHand(monthDayShorthand, year){
var array = monthDayShorthand.split("/");
var month = array[0];
var day = array[1];
return new Date(year, month - 1, day);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment