1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-28 15:27:43 +00:00

An update!

This commit is contained in:
SirStendec 2015-06-10 18:46:04 -04:00
parent 6264da62fc
commit b184fc74b2
15 changed files with 905 additions and 125 deletions

View file

@ -5,6 +5,12 @@ var FFZ = window.FrankerFaceZ,
var sanitize_cache = {},
sanitize_el = document.createElement('span'),
pluralize = function(value, singular, plural) {
plural = plural || 's';
singular = singular || '';
return value === 1 ? singular : plural;
},
place_string = function(num) {
if ( num == 1 ) return '1st';
else if ( num == 2 ) return '2nd';
@ -52,7 +58,9 @@ var sanitize_cache = {},
if ( ! parts )
return null;
var unix = Date.UTC(parts[1], parts[2] - 1, parts[3], parts[4], parts[5], parts[6], parts[7] || 0);
parts[7] = (parts[7] && parts[7].length) ? parts[7].substr(0, 3) : 0;
var unix = Date.UTC(parts[1], parts[2] - 1, parts[3], parts[4], parts[5], parts[6], parts[7]);
// Check Offset
if ( parts[9] ) {
@ -121,6 +129,34 @@ module.exports = {
return date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate();
},
pluralize: pluralize,
human_time: function(elapsed) {
elapsed = Math.floor(elapsed);
var years = Math.floor(elapsed / 31536000);
if ( years )
return years + ' year' + pluralize(years);
var days = Math.floor((elapsed %= 31536000) / 86400);
if ( days )
return days + ' day' + pluralize(days);
var hours = Math.floor((elapsed %= 86400) / 3600);
if ( hours )
return hours + ' hour' + pluralize(hours);
var minutes = Math.floor((elapsed %= 3600) / 60);
if ( minutes )
return minutes + ' minute' + pluralize(minutes);
var seconds = elapsed % 60;
if ( seconds )
return seconds + ' second' + pluralize(seconds);
return 'less than a second';
},
time_to_string: function(elapsed, separate_days, days_only) {
var seconds = elapsed % 60,
minutes = Math.floor(elapsed / 60),