|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;(function() { |
|
|
|
var DefaultLocale = { |
|
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], |
|
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], |
|
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], |
|
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], |
|
AM: 'AM', |
|
PM: 'PM', |
|
am: 'am', |
|
pm: 'pm', |
|
formats: { |
|
D: '%m/%d/%y', |
|
F: '%Y-%m-%d', |
|
R: '%H:%M', |
|
T: '%H:%M:%S', |
|
X: '%T', |
|
c: '%a %b %d %X %Y', |
|
r: '%I:%M:%S %p', |
|
v: '%e-%b-%Y', |
|
x: '%D' |
|
} |
|
}, |
|
defaultStrftime = new Strftime(DefaultLocale, 0, false), |
|
isCommonJS = typeof module !== 'undefined', |
|
namespace; |
|
|
|
|
|
if (isCommonJS) { |
|
namespace = module.exports = adaptedStrftime; |
|
namespace.strftime = deprecatedStrftime; |
|
} |
|
|
|
else { |
|
|
|
namespace = (function() { return this || (1,eval)('this'); }()); |
|
namespace.strftime = adaptedStrftime; |
|
} |
|
|
|
|
|
var _require = isCommonJS ? "require('strftime')" : "strftime"; |
|
var _deprecationWarnings = {}; |
|
function deprecationWarning(name, instead) { |
|
if (!_deprecationWarnings[name]) { |
|
if (typeof console !== 'undefined' && typeof console.warn == 'function') { |
|
console.warn("[WARNING] " + name + " is deprecated and will be removed in version 1.0. Instead, use `" + instead + "`."); |
|
} |
|
_deprecationWarnings[name] = true; |
|
} |
|
} |
|
|
|
namespace.strftimeTZ = deprecatedStrftimeTZ; |
|
namespace.strftimeUTC = deprecatedStrftimeUTC; |
|
namespace.localizedStrftime = deprecatedStrftimeLocalized; |
|
|
|
|
|
function adaptForwards(fn) { |
|
fn.localize = defaultStrftime.localize.bind(defaultStrftime); |
|
fn.timezone = defaultStrftime.timezone.bind(defaultStrftime); |
|
fn.utc = defaultStrftime.utc.bind(defaultStrftime); |
|
} |
|
|
|
adaptForwards(adaptedStrftime); |
|
function adaptedStrftime(fmt, d, locale) { |
|
|
|
if (d && d.days) { |
|
locale = d; |
|
d = undefined; |
|
} |
|
if (locale) { |
|
deprecationWarning("`" + _require + "(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])"); |
|
} |
|
var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime; |
|
return strftime(fmt, d); |
|
} |
|
|
|
adaptForwards(deprecatedStrftime); |
|
function deprecatedStrftime(fmt, d, locale) { |
|
if (locale) { |
|
deprecationWarning("`" + _require + ".strftime(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])"); |
|
} |
|
else { |
|
deprecationWarning("`" + _require + ".strftime(format, [date])`", _require + "(format, [date])"); |
|
} |
|
var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime; |
|
return strftime(fmt, d); |
|
} |
|
|
|
function deprecatedStrftimeTZ(fmt, d, locale, timezone) { |
|
|
|
if ((typeof locale == 'number' || typeof locale == 'string') && timezone == null) { |
|
timezone = locale; |
|
locale = undefined; |
|
} |
|
|
|
if (locale) { |
|
deprecationWarning("`" + _require + ".strftimeTZ(format, date, locale, tz)`", "var s = " + _require + ".localize(locale).timezone(tz); s(format, [date])` or `var s = " + _require + ".localize(locale); s.timezone(tz)(format, [date])"); |
|
} |
|
else { |
|
deprecationWarning("`" + _require + ".strftimeTZ(format, date, tz)`", "var s = " + _require + ".timezone(tz); s(format, [date])` or `" + _require + ".timezone(tz)(format, [date])"); |
|
} |
|
|
|
var strftime = (locale ? defaultStrftime.localize(locale) : defaultStrftime).timezone(timezone); |
|
return strftime(fmt, d); |
|
} |
|
|
|
var utcStrftime = defaultStrftime.utc(); |
|
function deprecatedStrftimeUTC(fmt, d, locale) { |
|
if (locale) { |
|
deprecationWarning("`" + _require + ".strftimeUTC(format, date, locale)`", "var s = " + _require + ".localize(locale).utc(); s(format, [date])"); |
|
} |
|
else { |
|
deprecationWarning("`" + _require + ".strftimeUTC(format, [date])`", "var s = " + _require + ".utc(); s(format, [date])"); |
|
} |
|
var strftime = locale ? utcStrftime.localize(locale) : utcStrftime; |
|
return strftime(fmt, d); |
|
} |
|
|
|
function deprecatedStrftimeLocalized(locale) { |
|
deprecationWarning("`" + _require + ".localizedStrftime(locale)`", _require + ".localize(locale)"); |
|
return defaultStrftime.localize(locale); |
|
} |
|
|
|
|
|
|
|
if (typeof Date.now !== 'function') { |
|
Date.now = function() { |
|
return +new Date(); |
|
}; |
|
} |
|
|
|
function Strftime(locale, customTimezoneOffset, useUtcTimezone) { |
|
var _locale = locale || DefaultLocale, |
|
_customTimezoneOffset = customTimezoneOffset || 0, |
|
_useUtcBasedDate = useUtcTimezone || false, |
|
|
|
|
|
|
|
|
|
|
|
_cachedDateTimestamp = 0, |
|
_cachedDate; |
|
|
|
function _strftime(format, date) { |
|
var timestamp; |
|
|
|
if (!date) { |
|
var currentTimestamp = Date.now(); |
|
if (currentTimestamp > _cachedDateTimestamp) { |
|
_cachedDateTimestamp = currentTimestamp; |
|
_cachedDate = new Date(_cachedDateTimestamp); |
|
|
|
timestamp = _cachedDateTimestamp; |
|
|
|
if (_useUtcBasedDate) { |
|
|
|
|
|
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset); |
|
} |
|
} |
|
else { |
|
timestamp = _cachedDateTimestamp; |
|
} |
|
date = _cachedDate; |
|
} |
|
else { |
|
timestamp = date.getTime(); |
|
|
|
if (_useUtcBasedDate) { |
|
date = new Date(date.getTime() + getTimestampToUtcOffsetFor(date) + _customTimezoneOffset); |
|
} |
|
} |
|
|
|
return _processFormat(format, date, _locale, timestamp); |
|
} |
|
|
|
function _processFormat(format, date, locale, timestamp) { |
|
var resultString = '', |
|
padding = null, |
|
isInScope = false, |
|
length = format.length, |
|
extendedTZ = false; |
|
|
|
for (var i = 0; i < length; i++) { |
|
|
|
var currentCharCode = format.charCodeAt(i); |
|
|
|
if (isInScope === true) { |
|
|
|
if (currentCharCode === 45) { |
|
padding = ''; |
|
continue; |
|
} |
|
|
|
else if (currentCharCode === 95) { |
|
padding = ' '; |
|
continue; |
|
} |
|
|
|
else if (currentCharCode === 48) { |
|
padding = '0'; |
|
continue; |
|
} |
|
|
|
else if (currentCharCode === 58) { |
|
if (extendedTZ) { |
|
if (typeof console !== 'undefined' && typeof console.warn == 'function') { |
|
console.warn("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime"); |
|
} |
|
} |
|
extendedTZ = true; |
|
continue; |
|
} |
|
|
|
switch (currentCharCode) { |
|
|
|
|
|
|
|
|
|
|
|
case 65: |
|
resultString += locale.days[date.getDay()]; |
|
break; |
|
|
|
|
|
|
|
case 66: |
|
resultString += locale.months[date.getMonth()]; |
|
break; |
|
|
|
|
|
|
|
case 67: |
|
resultString += padTill2(Math.floor(date.getFullYear() / 100), padding); |
|
break; |
|
|
|
|
|
|
|
case 68: |
|
resultString += _processFormat(locale.formats.D, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 70: |
|
resultString += _processFormat(locale.formats.F, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 72: |
|
resultString += padTill2(date.getHours(), padding); |
|
break; |
|
|
|
|
|
|
|
case 73: |
|
resultString += padTill2(hours12(date.getHours()), padding); |
|
break; |
|
|
|
|
|
|
|
case 76: |
|
resultString += padTill3(Math.floor(timestamp % 1000)); |
|
break; |
|
|
|
|
|
|
|
case 77: |
|
resultString += padTill2(date.getMinutes(), padding); |
|
break; |
|
|
|
|
|
|
|
case 80: |
|
resultString += date.getHours() < 12 ? locale.am : locale.pm; |
|
break; |
|
|
|
|
|
|
|
case 82: |
|
resultString += _processFormat(locale.formats.R, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 83: |
|
resultString += padTill2(date.getSeconds(), padding); |
|
break; |
|
|
|
|
|
|
|
case 84: |
|
resultString += _processFormat(locale.formats.T, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 85: |
|
resultString += padTill2(weekNumber(date, 'sunday'), padding); |
|
break; |
|
|
|
|
|
|
|
case 87: |
|
resultString += padTill2(weekNumber(date, 'monday'), padding); |
|
break; |
|
|
|
|
|
|
|
case 88: |
|
resultString += _processFormat(locale.formats.X, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 89: |
|
resultString += date.getFullYear(); |
|
break; |
|
|
|
|
|
|
|
case 90: |
|
if (_useUtcBasedDate && _customTimezoneOffset === 0) { |
|
resultString += "GMT"; |
|
} |
|
else { |
|
|
|
var tzString = date.toString().match(/\(([\w\s]+)\)/); |
|
resultString += tzString && tzString[1] || ''; |
|
} |
|
break; |
|
|
|
|
|
|
|
case 97: |
|
resultString += locale.shortDays[date.getDay()]; |
|
break; |
|
|
|
|
|
|
|
case 98: |
|
resultString += locale.shortMonths[date.getMonth()]; |
|
break; |
|
|
|
|
|
|
|
case 99: |
|
resultString += _processFormat(locale.formats.c, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 100: |
|
resultString += padTill2(date.getDate(), padding); |
|
break; |
|
|
|
|
|
|
|
case 101: |
|
resultString += padTill2(date.getDate(), padding == null ? ' ' : padding); |
|
break; |
|
|
|
|
|
|
|
case 104: |
|
resultString += locale.shortMonths[date.getMonth()]; |
|
break; |
|
|
|
|
|
|
|
case 106: |
|
var y = new Date(date.getFullYear(), 0, 1); |
|
var day = Math.ceil((date.getTime() - y.getTime()) / (1000 * 60 * 60 * 24)); |
|
resultString += padTill3(day); |
|
break; |
|
|
|
|
|
|
|
case 107: |
|
resultString += padTill2(date.getHours(), padding == null ? ' ' : padding); |
|
break; |
|
|
|
|
|
|
|
case 108: |
|
resultString += padTill2(hours12(date.getHours()), padding == null ? ' ' : padding); |
|
break; |
|
|
|
|
|
|
|
case 109: |
|
resultString += padTill2(date.getMonth() + 1, padding); |
|
break; |
|
|
|
|
|
|
|
case 110: |
|
resultString += '\n'; |
|
break; |
|
|
|
|
|
|
|
case 111: |
|
resultString += String(date.getDate()) + ordinal(date.getDate()); |
|
break; |
|
|
|
|
|
|
|
case 112: |
|
resultString += date.getHours() < 12 ? locale.AM : locale.PM; |
|
break; |
|
|
|
|
|
|
|
case 114: |
|
resultString += _processFormat(locale.formats.r, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 115: |
|
resultString += Math.floor(timestamp / 1000); |
|
break; |
|
|
|
|
|
|
|
case 116: |
|
resultString += '\t'; |
|
break; |
|
|
|
|
|
|
|
case 117: |
|
var day = date.getDay(); |
|
resultString += day === 0 ? 7 : day; |
|
break; |
|
|
|
|
|
|
|
case 118: |
|
resultString += _processFormat(locale.formats.v, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 119: |
|
resultString += date.getDay(); |
|
break; |
|
|
|
|
|
|
|
case 120: |
|
resultString += _processFormat(locale.formats.x, date, locale, timestamp); |
|
break; |
|
|
|
|
|
|
|
case 121: |
|
resultString += ('' + date.getFullYear()).slice(2); |
|
break; |
|
|
|
|
|
|
|
case 122: |
|
if (_useUtcBasedDate && _customTimezoneOffset === 0) { |
|
resultString += extendedTZ ? "+00:00" : "+0000"; |
|
} |
|
else { |
|
var off; |
|
if (_customTimezoneOffset !== 0) { |
|
off = _customTimezoneOffset / (60 * 1000); |
|
} |
|
else { |
|
off = -date.getTimezoneOffset(); |
|
} |
|
var sign = off < 0 ? '-' : '+'; |
|
var sep = extendedTZ ? ':' : ''; |
|
var hours = Math.floor(Math.abs(off / 60)); |
|
var mins = Math.abs(off % 60); |
|
resultString += sign + padTill2(hours) + sep + padTill2(mins); |
|
} |
|
break; |
|
|
|
default: |
|
resultString += format[i]; |
|
break; |
|
} |
|
|
|
padding = null; |
|
isInScope = false; |
|
continue; |
|
} |
|
|
|
|
|
if (currentCharCode === 37) { |
|
isInScope = true; |
|
continue; |
|
} |
|
|
|
resultString += format[i]; |
|
} |
|
|
|
return resultString; |
|
} |
|
|
|
var strftime = _strftime; |
|
|
|
strftime.localize = function(locale) { |
|
return new Strftime(locale || _locale, _customTimezoneOffset, _useUtcBasedDate); |
|
}; |
|
|
|
strftime.timezone = function(timezone) { |
|
var customTimezoneOffset = _customTimezoneOffset; |
|
var useUtcBasedDate = _useUtcBasedDate; |
|
|
|
var timezoneType = typeof timezone; |
|
if (timezoneType === 'number' || timezoneType === 'string') { |
|
useUtcBasedDate = true; |
|
|
|
|
|
if (timezoneType === 'string') { |
|
var sign = timezone[0] === '-' ? -1 : 1, |
|
hours = parseInt(timezone.slice(1, 3), 10), |
|
minutes = parseInt(timezone.slice(3, 5), 10); |
|
|
|
customTimezoneOffset = sign * ((60 * hours) + minutes) * 60 * 1000; |
|
|
|
} |
|
else if (timezoneType === 'number') { |
|
customTimezoneOffset = timezone * 60 * 1000; |
|
} |
|
} |
|
|
|
return new Strftime(_locale, customTimezoneOffset, useUtcBasedDate); |
|
}; |
|
|
|
strftime.utc = function() { |
|
return new Strftime(_locale, _customTimezoneOffset, true); |
|
}; |
|
|
|
return strftime; |
|
} |
|
|
|
function padTill2(numberToPad, paddingChar) { |
|
if (paddingChar === '' || numberToPad > 9) { |
|
return numberToPad; |
|
} |
|
if (paddingChar == null) { |
|
paddingChar = '0'; |
|
} |
|
return paddingChar + numberToPad; |
|
} |
|
|
|
function padTill3(numberToPad) { |
|
if (numberToPad > 99) { |
|
return numberToPad; |
|
} |
|
if (numberToPad > 9) { |
|
return '0' + numberToPad; |
|
} |
|
return '00' + numberToPad; |
|
} |
|
|
|
function hours12(hour) { |
|
if (hour === 0) { |
|
return 12; |
|
} |
|
else if (hour > 12) { |
|
return hour - 12; |
|
} |
|
return hour; |
|
} |
|
|
|
|
|
|
|
|
|
function weekNumber(date, firstWeekday) { |
|
firstWeekday = firstWeekday || 'sunday'; |
|
|
|
|
|
|
|
var weekday = date.getDay(); |
|
if (firstWeekday === 'monday') { |
|
if (weekday === 0) |
|
weekday = 6; |
|
else |
|
weekday--; |
|
} |
|
|
|
var firstDayOfYearUtc = Date.UTC(date.getFullYear(), 0, 1), |
|
dateUtc = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()), |
|
yday = Math.floor((dateUtc - firstDayOfYearUtc) / 86400000), |
|
weekNum = (yday + 7 - weekday) / 7; |
|
|
|
return Math.floor(weekNum); |
|
} |
|
|
|
|
|
function ordinal(number) { |
|
var i = number % 10; |
|
var ii = number % 100; |
|
|
|
if ((ii >= 11 && ii <= 13) || i === 0 || i >= 4) { |
|
return 'th'; |
|
} |
|
switch (i) { |
|
case 1: return 'st'; |
|
case 2: return 'nd'; |
|
case 3: return 'rd'; |
|
} |
|
} |
|
|
|
function getTimestampToUtcOffsetFor(date) { |
|
return (date.getTimezoneOffset() || 0) * 60000; |
|
} |
|
|
|
}()); |
|
|