Skip to content

Instantly share code, notes, and snippets.

@little9
Last active August 29, 2015 14:01
Show Gist options
  • Save little9/4cdd617cc254424d5672 to your computer and use it in GitHub Desktop.
Save little9/4cdd617cc254424d5672 to your computer and use it in GitHub Desktop.
CHC check exceptions
// Extend the Javascript Date() object to use full month names
Date.prototype.getMonthName = function(lang) {
lang = lang && (lang in Date.locale) ? lang : 'en';
return Date.locale[lang].month_names[this.getMonth()];
};
Date.prototype.getMonthNameShort = function(lang) {
lang = lang && (lang in Date.locale) ? lang : 'en';
return Date.locale[lang].month_names_short[this.getMonth()];
};
Date.locale = {
en: {
month_names: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
month_names_short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
}
};
// then..
// Request the CHC hours page
jQuery.ajax({ url: 'http://library.miami.edu/chc/hoursdirections/', dataType: 'html',
success: function(response)
{
// Get the current date and format it like: May 26
var date = new Date();
var currentDate = date.getMonthName() + " " + date.getDate();
// Get the days that have different hours from the table on the hours page
var exceptions = jQuery(response).find('.item_listing').eq(1).find('td');
// Go through each of the exceptions
jQuery(exceptions).each(function (exception) {
var exceptionDate = jQuery(this).html();
if (exceptionDate.indexOf(currentDate) > 0) {
// Check if the exception matches todays date
// If there is an exception change the text of the link
var exceptionText = jQuery(this).next().html();
jQuery('.hours').find('a').text(exceptionText);
} else {
// No exceptions today
}
});
} });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment