hedera-web/js/vn/date.js

128 lines
1.9 KiB
JavaScript
Raw Normal View History

/**
* Date handling utilities.
2016-12-20 09:32:17 +00:00
*/
Date.prototype.clone = function ()
{
return new Date (this.getTime ());
}
2016-09-26 09:28:47 +00:00
module.exports =
{
WDays:
[
'Sunday'
,'Monday'
,'Tuesday'
,'Wednesday'
,'Thursday'
,'Friday'
,'Saturday'
]
,AbrWDays:
[
'Su'
,'Mo'
,'Tu'
,'We'
,'Th'
,'Fr'
,'Sa'
]
,Months:
[
'January'
,'February'
,'March'
,'April'
,'May'
,'June'
,'July'
,'August'
,'September'
,'October'
,'November'
,'December'
]
,AbrMonths:
[
'Jan'
,'Feb'
,'Mar'
,'Apr'
,'May'
,'Jun'
,'Jul'
,'Ago'
,'Sep'
,'Oct'
,'Nov'
,'Dec'
]
,tokenD: '%A, %B %e'
,regexp: new RegExp ('%[a-zA-Z]', 'g')
,pad: function (number)
{
if (number < 10)
return '0'+ number.toString ();
return number.toString ();
}
,regexpFunc: function (d, token)
{
switch (token.charAt (1))
{
// Minutes with 2 digits
case 'M': return this.pad (d.getMinutes ());
// Hour with 2 digits in 24 hour format
case 'H': return this.pad (d.getHours ());
// Complete time
case 'T': return d.toLocaleTimeString ();
// Complete week day name
case 'A': return _(this.WDays[d.getDay ()]);
// Abreviated week day name
case 'a': return _(this.AbrWDays[d.getDay ()]);
// Day of month with 2 digits
case 'd': return this.pad (d.getDate ());
// Day of month
case 'e': return d.getDate ();
// Complete month name
case 'B': return _(this.Months[d.getMonth ()]);
// Abreviated month name
case 'b': return _(this.AbrMonths[d.getMonth ()]);
// Month number with 2 digits
case 'm': return this.pad (d.getMonth () + 1);
// Year with 4 digits
case 'Y': return d.getFullYear ();
// Complete date without year
case 'D': return _(this.tokenD).replace (this.regexp, this.regexpFunc.bind (this, d));
}
return token;
}
,strftime: function (date, format)
{
if (!date)
return '';
return format.replace (this.regexp, this.regexpFunc.bind (this, date));
}
};