Skip to content

Instantly share code, notes, and snippets.

@foxiepaws
Created November 10, 2015 20:58
Show Gist options
  • Select an option

  • Save foxiepaws/0d184dde5b96789fecc1 to your computer and use it in GitHub Desktop.

Select an option

Save foxiepaws/0d184dde5b96789fecc1 to your computer and use it in GitHub Desktop.
// HRT
function getTextNumber (n) {
var textuals = [ "a", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" ];
if (n < 12 && n > 0) {
return textuals[n-1];
} else {
return n;
}
}
document.getElementById('hrt').innerHTML =
"I've been on HRT for " +
(function(){
current = new Date();
start = new Date(2014,10,10,00,20,00,00);
months = (current.getMonth() - start.getMonth() + (12* (current.getFullYear() - start.getFullYear())));
years = Math.floor(months / 12);
return (years > 0 ?
(getTextNumber(years) + " year" + (years > 1 ? "s" : "") +
((months-(years*12)) > 0 ?
' and ' + getTextNumber(months-(years*12)) + ' month' + ((months-(years*12) ? "s" : "")) : "")) :
getTextNumber(months) + ' month' + ((months>1) ? "s" : ""))})() + ' now.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment