Skip to content

Instantly share code, notes, and snippets.

@alexmahan
Last active December 28, 2015 19:29
Show Gist options
  • Save alexmahan/7550815 to your computer and use it in GitHub Desktop.
Save alexmahan/7550815 to your computer and use it in GitHub Desktop.
Oh so you wanna conditionally output some day/month/time-related shit in JS without using a library? This is some wack shit you could use. Could be good if you are making a website for a shop that has no back-end logic for open/close times.
getDate: {
init: function() {
var dateContainer = document.getElementById('date'),
today = new Date(),
dayNames= ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
monthNames = ['January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December'],
dayText = dayNames[today.getDay()],
monthText = monthNames[today.getMonth()],
dateText = today.getDate(),
weekday = today.getDay();
if ([3,4,5,6].indexOf(weekday) > -1) {
var hours = '12-7PM';
} else if (weekday === 0) {
var hours = '12-5PM';
} else {
var hours = 'closed';
}
// outputs something like TUESDAY, NOVEMBER 19, CLOSED
dateContainer.innerHTML('' + dayText + ', ' + monthText + ' ' + dateText + ', ' + hours + '');
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment