//email us at 6pm central and then back to call us at 8am
jQuery(document).ready(function() {
var $btn = $('#contact-us');
var centralOffset = -5;
//define holidays with begin and end moment in an array [[$start1, $end1],[$start2, $end2], ...]
var $holidays = [
[moment("2015-05-01 18:00:00").utcOffset(centralOffset),
moment("2015-05-03 08:00:00").utcOffset(centralOffset)],
[moment("2015-05-12 18:00:00").utcOffset(centralOffset),
moment("2015-05-26 08:00:00").utcOffset(centralOffset)]];
var $now = moment().utcOffset(centralOffset);
// today 08:00:00
var $start = moment().utcOffset(centralOffset).hours(8).minutes(0).seconds(0);
// today 18:00:00
var $end = moment().utcOffset(centralOffset).hours(18).minutes(0).seconds(0);
//check if we are in holiday
var $inHoliday = false;
//go through all the holidays
for (var $x = 0; $x < $holidays.length; $x++) {
if ($now.isBetween($holidays[$x][0], $holidays[$x][1])) {
$inHoliday = true;
}
}
if ( $inHoliday || !$now.isBetween($start, $end) ) {
$btn.html('Email us');
} else {
$btn.html('Call us');
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.