Socket
Socket
Sign inDemoInstall

d3-time-format

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-time-format - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

484

build/timeFormat.js

@@ -26,37 +26,26 @@ if (typeof Map === "undefined") {

var pads = {"-": "", "_": " ", "0": "0"};
function utcDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
date.setUTCFullYear(d.y);
return date;
}
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
}
var LocalDate = Date;
function localDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
date.setFullYear(d.y);
return date;
}
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
}
var date = Date;
var pads = {"-": "", "_": " ", "0": "0"};
function UtcDate() {
this._ = new date(arguments.length > 1 ? date.UTC.apply(this, arguments) : arguments[0]);
function newYear(y) {
return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
}
var proto = date.prototype;
UtcDate.prototype = {
getDate: function() { return this._.getUTCDate(); },
getDay: function() { return this._.getUTCDay(); },
getFullYear: function() { return this._.getUTCFullYear(); },
getHours: function() { return this._.getUTCHours(); },
getMilliseconds: function() { return this._.getUTCMilliseconds(); },
getMinutes: function() { return this._.getUTCMinutes(); },
getMonth: function() { return this._.getUTCMonth(); },
getSeconds: function() { return this._.getUTCSeconds(); },
getTime: function() { return this._.getTime(); },
getTimezoneOffset: function() { return 0; },
valueOf: function() { return this._.valueOf(); },
setDate: function() { return proto.setUTCDate.apply(this._, arguments); },
setDay: function() { return proto.setUTCDay.apply(this._, arguments); },
setFullYear: function() { return proto.setUTCFullYear.apply(this._, arguments); },
setHours: function() { return proto.setUTCHours.apply(this._, arguments); },
setMilliseconds: function() { return proto.setUTCMilliseconds.apply(this._, arguments); },
setMinutes: function() { return proto.setUTCMinutes.apply(this._, arguments); },
setMonth: function() { return proto.setUTCMonth.apply(this._, arguments); },
setSeconds: function() { return proto.setUTCSeconds.apply(this._, arguments); },
setTime: function() { return proto.setTime.apply(this._, arguments); }
};
var percentRe = /^%/;

@@ -102,3 +91,3 @@

function parseDay(d, string, i) {
function parseDayOfMonth(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));

@@ -110,6 +99,5 @@ return n ? (d.d = +n[0], i + n[0].length) : -1;

var n = numberRe.exec(string.slice(i, i + 3));
return n ? (d.j = +n[0], i + n[0].length) : -1;
return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
}
// Note: we don't validate that the hour is in the range [0,23] or [1,12].
function parseHour24(d, string, i) {

@@ -140,2 +128,10 @@ var n = numberRe.exec(string.slice(i, i + 2));

function formatLiteralPercent() {
return "%";
}
function formatUTCZone() {
return "+0000";
}
function pad(value, fill, width) {

@@ -148,9 +144,14 @@ var sign = value < 0 ? "-" : "",

function formatZone(d) {
var z = d.getTimezoneOffset();
return (z > 0 ? "-" : (z *= -1, "+"))
+ pad(z / 60 | 0, "0", 2)
+ pad(z % 60, "0", 2);
function formatUTCFullYear(d, p) {
return pad(d.getUTCFullYear() % 10000, p, 4);
}
function formatUTCYear(d, p) {
return pad(d.getUTCFullYear() % 100, p, 2);
}
var t1 = new Date;
var t0 = new Date;
function newInterval(floori, offseti, count) {

@@ -184,3 +185,3 @@

step = step == null ? 1 : Math.floor(step);
if (!(start < stop)) return range; // also handles Invalid Date
if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
offseti(start, 1), floori(start);

@@ -201,6 +202,5 @@ if (start < stop) range.push(new Date(+start));

if (count) interval.count = function(start, end) {
start = new Date(+start);
end = new Date(+end);
floori(start), floori(end);
return Math.floor(count(start, end));
t0.setTime(+start), t1.setTime(+end);
floori(t0), floori(t1);
return Math.floor(count(t0, t1));
};

@@ -211,2 +211,93 @@

var utcYear = newInterval(function(date) {
date.setUTCHours(0, 0, 0, 0);
date.setUTCMonth(0, 1);
}, function(date, offset) {
date.setUTCFullYear(date.getUTCFullYear() + offset);
}, function(start, end) {
return end.getUTCFullYear() - start.getUTCFullYear();
});
function utcWeekday(i) {
return newInterval(function(date) {
date.setUTCHours(0, 0, 0, 0);
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
}, function(date, offset) {
date.setUTCDate(date.getUTCDate() + offset * 7);
}, function(start, end) {
return (end - start) / 6048e5;
});
}
var utcMonday = utcWeekday(1);
function formatUTCWeekNumberMonday(d, p) {
return pad(utcMonday.count(utcYear(d), d), p, 2);
}
function formatUTCWeekdayNumber(d) {
return d.getUTCDay();
}
var utcSunday = utcWeekday(0);
function formatUTCWeekNumberSunday(d, p) {
return pad(utcSunday.count(utcYear(d), d), p, 2);
}
function formatUTCSeconds(d, p) {
return pad(d.getUTCSeconds(), p, 2);
}
function formatUTCMinutes(d, p) {
return pad(d.getUTCMinutes(), p, 2);
}
function formatUTCMonthNumber(d, p) {
return pad(d.getUTCMonth() + 1, p, 2);
}
function formatUTCMilliseconds(d, p) {
return pad(d.getUTCMilliseconds(), p, 3);
}
var utcDay = newInterval(function(date) {
date.setUTCHours(0, 0, 0, 0);
}, function(date, offset) {
date.setUTCDate(date.getUTCDate() + offset);
}, function(start, end) {
return (end - start) / 864e5;
});
function formatUTCDayOfYear(d, p) {
return pad(1 + utcDay.count(utcYear(d), d), p, 3);
}
function formatUTCHour12(d, p) {
return pad(d.getUTCHours() % 12 || 12, p, 2);
}
function formatUTCHour24(d, p) {
return pad(d.getUTCHours(), p, 2);
}
function formatUTCDayOfMonth(d, p) {
return pad(d.getUTCDate(), p, 2);
}
function formatZone(d) {
var z = d.getTimezoneOffset();
return (z > 0 ? "-" : (z *= -1, "+"))
+ pad(z / 60 | 0, "0", 2)
+ pad(z % 60, "0", 2);
}
function formatFullYear(d, p) {
return pad(d.getFullYear() % 10000, p, 4);
}
function formatYear(d, p) {
return pad(d.getFullYear() % 100, p, 2);
}
var year = newInterval(function(date) {

@@ -234,4 +325,32 @@ date.setHours(0, 0, 0, 0);

function formatWeekNumberMonday(d, p) {
return pad(monday.count(year(d), d), p, 2);
}
function formatWeekdayNumber(d) {
return d.getDay();
}
var sunday = weekday(0);
function formatWeekNumberSunday(d, p) {
return pad(sunday.count(year(d), d), p, 2);
}
function formatSeconds(d, p) {
return pad(d.getSeconds(), p, 2);
}
function formatMinutes(d, p) {
return pad(d.getMinutes(), p, 2);
}
function formatMonthNumber(d, p) {
return pad(d.getMonth() + 1, p, 2);
}
function formatMilliseconds(d, p) {
return pad(d.getMilliseconds(), p, 3);
}
var day = newInterval(function(date) {

@@ -245,2 +364,18 @@ date.setHours(0, 0, 0, 0);

function formatDayOfYear(d, p) {
return pad(1 + day.count(year(d), d), p, 3);
}
function formatHour12(d, p) {
return pad(d.getHours() % 12 || 12, p, 2);
}
function formatHour24(d, p) {
return pad(d.getHours(), p, 2);
}
function formatDayOfMonth(d, p) {
return pad(d.getDate(), p, 2);
}
function formatLookup(names) {

@@ -267,4 +402,4 @@ var map = new Map, i = -1, n = names.length;

locale_periods = locale.periods,
locale_days = locale.days,
locale_shortDays = locale.shortDays,
locale_weekdays = locale.days,
locale_shortWeekdays = locale.shortDays,
locale_months = locale.months,

@@ -274,46 +409,73 @@ locale_shortMonths = locale.shortMonths;

var periodLookup = formatLookup(locale_periods),
dayRe = formatRe(locale_days),
dayLookup = formatLookup(locale_days),
dayAbbrevRe = formatRe(locale_shortDays),
dayAbbrevLookup = formatLookup(locale_shortDays),
weekdayRe = formatRe(locale_weekdays),
weekdayLookup = formatLookup(locale_weekdays),
shortWeekdayRe = formatRe(locale_shortWeekdays),
shortWeekdayLookup = formatLookup(locale_shortWeekdays),
monthRe = formatRe(locale_months),
monthLookup = formatLookup(locale_months),
monthAbbrevRe = formatRe(locale_shortMonths),
monthAbbrevLookup = formatLookup(locale_shortMonths);
shortMonthRe = formatRe(locale_shortMonths),
shortMonthLookup = formatLookup(locale_shortMonths);
var formats = {
"a": function(d) { return locale_shortDays[d.getDay()]; },
"A": function(d) { return locale_days[d.getDay()]; },
"b": function(d) { return locale_shortMonths[d.getMonth()]; },
"B": function(d) { return locale_months[d.getMonth()]; },
"c": newFormat(locale_dateTime),
"d": function(d, p) { return pad(d.getDate(), p, 2); },
"e": function(d, p) { return pad(d.getDate(), p, 2); },
"H": function(d, p) { return pad(d.getHours(), p, 2); },
"I": function(d, p) { return pad(d.getHours() % 12 || 12, p, 2); },
"j": function(d, p) { return pad(1 + day.count(year(d), d), p, 3); },
"L": function(d, p) { return pad(d.getMilliseconds(), p, 3); },
"m": function(d, p) { return pad(d.getMonth() + 1, p, 2); },
"M": function(d, p) { return pad(d.getMinutes(), p, 2); },
"p": function(d) { return locale_periods[+(d.getHours() >= 12)]; },
"S": function(d, p) { return pad(d.getSeconds(), p, 2); },
"U": function(d, p) { return pad(sunday.count(year(d), d), p, 2); },
"w": function(d) { return d.getDay(); },
"W": function(d, p) { return pad(monday.count(year(d), d), p, 2); },
"x": newFormat(locale_date),
"X": newFormat(locale_time),
"y": function(d, p) { return pad(d.getFullYear() % 100, p, 2); },
"Y": function(d, p) { return pad(d.getFullYear() % 10000, p, 4); },
"a": formatShortWeekday,
"A": formatWeekday,
"b": formatShortMonth,
"B": formatMonth,
"c": null,
"d": formatDayOfMonth,
"e": formatDayOfMonth,
"H": formatHour24,
"I": formatHour12,
"j": formatDayOfYear,
"L": formatMilliseconds,
"m": formatMonthNumber,
"M": formatMinutes,
"p": formatPeriod,
"S": formatSeconds,
"U": formatWeekNumberSunday,
"w": formatWeekdayNumber,
"W": formatWeekNumberMonday,
"x": null,
"X": null,
"y": formatYear,
"Y": formatFullYear,
"Z": formatZone,
"%": function() { return "%"; }
"%": formatLiteralPercent
};
var utcFormats = {
"a": formatUTCShortWeekday,
"A": formatUTCWeekday,
"b": formatUTCShortMonth,
"B": formatUTCMonth,
"c": null,
"d": formatUTCDayOfMonth,
"e": formatUTCDayOfMonth,
"H": formatUTCHour24,
"I": formatUTCHour12,
"j": formatUTCDayOfYear,
"L": formatUTCMilliseconds,
"m": formatUTCMonthNumber,
"M": formatUTCMinutes,
"p": formatUTCPeriod,
"S": formatUTCSeconds,
"U": formatUTCWeekNumberSunday,
"w": formatUTCWeekdayNumber,
"W": formatUTCWeekNumberMonday,
"x": null,
"X": null,
"y": formatUTCYear,
"Y": formatUTCFullYear,
"Z": formatUTCZone,
"%": formatLiteralPercent
};
var parses = {
"a": parseWeekdayAbbrev,
"a": parseShortWeekday,
"A": parseWeekday,
"b": parseMonthAbbrev,
"b": parseShortMonth,
"B": parseMonth,
"c": parseLocaleDateTime,
"d": parseDay,
"e": parseDay,
"d": parseDayOfMonth,
"e": parseDayOfMonth,
"H": parseHour24,

@@ -325,3 +487,3 @@ "I": parseHour24,

"M": parseMinutes,
"p": parseAmPm,
"p": parsePeriod,
"S": parseSeconds,

@@ -339,6 +501,12 @@ "U": parseWeekNumberSunday,

function newFormat(specifier) {
specifier += "";
// These recursive directive definitions must be deferred.
formats.x = newFormat(locale_date, formats);
formats.X = newFormat(locale_time, formats);
formats.c = newFormat(locale_dateTime, formats);
utcFormats.x = newFormat(locale_date, utcFormats);
utcFormats.X = newFormat(locale_time, utcFormats);
utcFormats.c = newFormat(locale_dateTime, utcFormats);
function format(date) {
function newFormat(specifier, formats) {
return function(date) {
var string = [],

@@ -364,6 +532,8 @@ i = -1,

return string.join("");
}
};
}
format.parse = function(string) {
var d = {y: 1900, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0, Z: null},
function newParse(specifier, newDate) {
return function(string) {
var d = newYear(1900),
i = parseSpecifier(d, specifier, string, 0);

@@ -375,59 +545,25 @@ if (i != string.length) return null;

// If a time zone is specified, it is always relative to UTC;
// we need to use UtcDate if we aren’t already.
var localZ = d.Z != null && Date !== UtcDate,
date = new (localZ ? UtcDate : Date);
// Set year, month, date.
if ("j" in d) {
date.setFullYear(d.y, 0, d.j);
} else if ("w" in d && ("W" in d || "U" in d)) {
date.setFullYear(d.y, 0, 1);
date.setFullYear(d.y, 0, "W" in d
? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7
: d.w + d.U * 7 - (date.getDay() + 6) % 7);
} else {
date.setFullYear(d.y, d.m, d.d);
// If a time zone is specified, all fields are interpreted as UTC and then
// offset according to the specified time zone.
if ("Z" in d) {
if ("w" in d && ("W" in d || "U" in d)) {
var day = utcDate(newYear(d.y)).getUTCDay();
if ("W" in d) d.U = d.W, d.w = (d.w + 6) % 7, --day;
d.m = 0;
d.d = d.w + d.U * 7 - (day + 6) % 7;
}
d.H += d.Z / 100 | 0;
d.M += d.Z % 100;
return utcDate(d);
}
// Set hours, minutes, seconds and milliseconds.
date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
return localZ ? date._ : date;
};
format.toString = function() {
return specifier;
};
return format;
}
function newUtcFormat(specifier) {
var local = newFormat(specifier);
function format(date) {
try {
Date = UtcDate;
var utc = new Date;
utc._ = date;
return local(utc);
} finally {
Date = LocalDate;
// Otherwise, all fields are in local time.
if ("w" in d && ("W" in d || "U" in d)) {
var day = newDate(newYear(d.y)).getDay();
if ("W" in d) d.U = d.W, d.w = (d.w + 6) % 7, --day;
d.m = 0;
d.d = d.w + d.U * 7 - (day + 6) % 7;
}
}
format.parse = function(string) {
try {
Date = UtcDate;
var date = local.parse(string);
return date && date._;
} finally {
Date = LocalDate;
}
return newDate(d);
};
format.toString = local.toString;
return format;
}

@@ -457,15 +593,15 @@

function parseWeekdayAbbrev(d, string, i) {
var n = dayAbbrevRe.exec(string.slice(i));
return n ? (d.w = dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
function parseShortWeekday(d, string, i) {
var n = shortWeekdayRe.exec(string.slice(i));
return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
}
function parseWeekday(d, string, i) {
var n = dayRe.exec(string.slice(i));
return n ? (d.w = dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
var n = weekdayRe.exec(string.slice(i));
return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
}
function parseMonthAbbrev(d, string, i) {
var n = monthAbbrevRe.exec(string.slice(i));
return n ? (d.m = monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
function parseShortMonth(d, string, i) {
var n = shortMonthRe.exec(string.slice(i));
return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
}

@@ -490,3 +626,3 @@

function parseAmPm(d, string, i) {
function parsePeriod(d, string, i) {
var n = periodLookup.get(string.slice(i, i += 2).toLowerCase());

@@ -496,5 +632,55 @@ return n == null ? -1 : (d.p = n, i);

function formatShortWeekday(d) {
return locale_shortWeekdays[d.getDay()];
}
function formatWeekday(d) {
return locale_weekdays[d.getDay()];
}
function formatShortMonth(d) {
return locale_shortMonths[d.getMonth()];
}
function formatMonth(d) {
return locale_months[d.getMonth()];
}
function formatPeriod(d) {
return locale_periods[+(d.getHours() >= 12)];
}
function formatUTCShortWeekday(d) {
return locale_shortWeekdays[d.getUTCDay()];
}
function formatUTCWeekday(d) {
return locale_weekdays[d.getUTCDay()];
}
function formatUTCShortMonth(d) {
return locale_shortMonths[d.getUTCMonth()];
}
function formatUTCMonth(d) {
return locale_months[d.getUTCMonth()];
}
function formatUTCPeriod(d) {
return locale_periods[+(d.getUTCHours() >= 12)];
}
return {
format: newFormat,
utcFormat: newUtcFormat
format: function(specifier) {
var f = newFormat(specifier += "", formats);
f.parse = newParse(specifier, localDate);
f.toString = function() { return specifier; };
return f;
},
utcFormat: function(specifier) {
var f = newFormat(specifier += "", utcFormats);
f.parse = newParse(specifier, utcDate);
f.toString = function() { return specifier; };
return f;
}
};

@@ -501,0 +687,0 @@ }

@@ -1,1 +0,1 @@

"undefined"==typeof Map?(Map=function(){this.clear()},Map.prototype={set:function(t,e){return this._[t]=e,this},get:function(t){return this._[t]},has:function(t){return t in this._},"delete":function(t){return t in this._&&delete this._[t]},clear:function(){this._=Object.create(null)},get size(){var t=0;for(var e in this._)++t;return t},forEach:function(t){for(var e in this._)t(this._[e],e,this)}}):function(){var t=new Map;t.set(0,0)!==t&&(t=t.set,Map.prototype.set=function(){return t.apply(this,arguments),this})}(),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.timeFormat={})}(this,function(t){"use strict";function e(){this._=new x(arguments.length>1?x.UTC.apply(this,arguments):arguments[0])}function n(t,e,n){var r=H.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function r(t,e,n){return/^[+-]\d{4}$/.test(e=e.slice(n,n+5))?(t.Z=-e,n+5):-1}function u(t,e,n){var r=Y.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function i(t,e,n){var r=Y.exec(e.slice(n));return r?(t.U=+r[0],n+r[0].length):-1}function o(t,e,n){var r=Y.exec(e.slice(n));return r?(t.W=+r[0],n+r[0].length):-1}function a(t,e,n){var r=Y.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function c(t,e,n){var r=Y.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function s(t,e,n){var r=Y.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function f(t,e,n){var r=Y.exec(e.slice(n,n+3));return r?(t.j=+r[0],n+r[0].length):-1}function l(t,e,n){var r=Y.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function g(t,e,n){var r=Y.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function h(t,e,n){var r=Y.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function p(t,e,n){var r=Y.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function y(t,e,n){var r=Y.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function m(t,e,n){var r=0>t?"-":"",u=(r?-t:t)+"",i=u.length;return r+(n>i?new Array(n-i+1).join(e)+u:u)}function d(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+m(e/60|0,"0",2)+m(e%60,"0",2)}function D(t,e,n){function r(e){return t(e=new Date(+e)),e}return r.floor=r,r.round=function(n){var r=new Date(+n),u=new Date(n-1);return t(r),t(u),e(u,1),u-n>n-r?r:u},r.ceil=function(n){return t(n=new Date(n-1)),e(n,1),n},r.offset=function(t,n){return e(t=new Date(+t),null==n?1:Math.floor(n)),t},r.range=function(n,r,u){var i=[];if(n=new Date(n-1),r=new Date(+r),u=null==u?1:Math.floor(u),!(r>n))return i;for(e(n,1),t(n),r>n&&i.push(new Date(+n));e(n,u),t(n),r>n;)i.push(new Date(+n));return i},r.filter=function(n){return D(function(e){for(;t(e),!n(e);)e.setTime(e-1)},function(t,r){for(;--r>=0;)for(;e(t,1),!n(t););})},n&&(r.count=function(e,r){return e=new Date(+e),r=new Date(+r),t(e),t(r),Math.floor(n(e,r))}),r}function v(t){return D(function(e){e.setHours(0,0,0,0),e.setDate(e.getDate()-(e.getDay()+7-t)%7)},function(t,e){t.setDate(t.getDate()+7*e)},function(t,e){return(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/6048e5})}function M(t){for(var e=new Map,n=-1,r=t.length;++n<r;)e.set(t[n].toLowerCase(),n);return e}function T(t){return t.replace(L,"\\$&")}function w(t){return new RegExp("^(?:"+t.map(T).join("|")+")","i")}function _(t){function D(t){function n(e){for(var n,r,u,i=[],o=-1,a=0,c=t.length;++o<c;)37===t.charCodeAt(o)&&(i.push(t.slice(a,o)),null!=(r=S[n=t.charAt(++o)])&&(n=t.charAt(++o)),(u=tt[n])&&(n=u(e,null==r?"e"===n?" ":"0":r)),i.push(n),a=o+1);return i.push(t.slice(a,o)),i.join("")}return t+="",n.parse=function(n){var r={y:1900,m:0,d:1,H:0,M:0,S:0,L:0,Z:null},u=T(r,t,n,0);if(u!=n.length)return null;"p"in r&&(r.H=r.H%12+12*r.p);var i=null!=r.Z&&Date!==e,o=new(i?e:Date);return"j"in r?o.setFullYear(r.y,0,r.j):"w"in r&&("W"in r||"U"in r)?(o.setFullYear(r.y,0,1),o.setFullYear(r.y,0,"W"in r?(r.w+6)%7+7*r.W-(o.getDay()+5)%7:r.w+7*r.U-(o.getDay()+6)%7)):o.setFullYear(r.y,r.m,r.d),o.setHours(r.H+(r.Z/100|0),r.M+r.Z%100,r.S,r.L),i?o._:o},n.toString=function(){return t},n}function v(t){function n(t){try{Date=e;var n=new Date;return n._=t,r(n)}finally{Date=F}}var r=D(t);return n.parse=function(t){try{Date=e;var n=r.parse(t);return n&&n._}finally{Date=F}},n.toString=r.toString,n}function T(t,e,n,r){for(var u,i,o=0,a=e.length,c=n.length;a>o;){if(r>=c)return-1;if(u=e.charCodeAt(o++),37===u){if(u=e.charAt(o++),i=et[u in S?e.charAt(o++):u],!i||(r=i(t,n,r))<0)return-1}else if(u!=n.charCodeAt(r++))return-1}return r}function _(t,e,n){var r=k.exec(e.slice(n));return r?(t.w=q.get(r[0].toLowerCase()),n+r[0].length):-1}function C(t,e,n){var r=P.exec(e.slice(n));return r?(t.w=R.get(r[0].toLowerCase()),n+r[0].length):-1}function x(t,e,n){var r=Q.exec(e.slice(n));return r?(t.m=V.get(r[0].toLowerCase()),n+r[0].length):-1}function U(t,e,n){var r=G.exec(e.slice(n));return r?(t.m=K.get(r[0].toLowerCase()),n+r[0].length):-1}function H(t,e,n){return T(t,W,e,n)}function Y(t,e,n){return T(t,z,e,n)}function L(t,e,n){return T(t,J,e,n)}function Z(t,e,n){var r=E.get(e.slice(n,n+=2).toLowerCase());return null==r?-1:(t.p=r,n)}var W=t.dateTime,z=t.date,J=t.time,I=t.periods,N=t.days,X=t.shortDays,$=t.months,B=t.shortMonths,E=M(I),P=w(N),R=M(N),k=w(X),q=M(X),G=w($),K=M($),Q=w(B),V=M(B),tt={a:function(t){return X[t.getDay()]},A:function(t){return N[t.getDay()]},b:function(t){return B[t.getMonth()]},B:function(t){return $[t.getMonth()]},c:D(W),d:function(t,e){return m(t.getDate(),e,2)},e:function(t,e){return m(t.getDate(),e,2)},H:function(t,e){return m(t.getHours(),e,2)},I:function(t,e){return m(t.getHours()%12||12,e,2)},j:function(t,e){return m(1+j.count(A(t),t),e,3)},L:function(t,e){return m(t.getMilliseconds(),e,3)},m:function(t,e){return m(t.getMonth()+1,e,2)},M:function(t,e){return m(t.getMinutes(),e,2)},p:function(t){return I[+(t.getHours()>=12)]},S:function(t,e){return m(t.getSeconds(),e,2)},U:function(t,e){return m(b.count(A(t),t),e,2)},w:function(t){return t.getDay()},W:function(t,e){return m(O.count(A(t),t),e,2)},x:D(z),X:D(J),y:function(t,e){return m(t.getFullYear()%100,e,2)},Y:function(t,e){return m(t.getFullYear()%1e4,e,4)},Z:d,"%":function(){return"%"}},et={a:_,A:C,b:x,B:U,c:H,d:s,e:s,H:l,I:l,j:f,L:p,m:c,M:g,p:Z,S:h,U:i,w:u,W:o,x:Y,X:L,y:a,Y:y,Z:r,"%":n};return{format:D,utcFormat:v}}function C(t){return t.toISOString()}var S={"-":"",_:" ",0:"0"},F=Date,x=Date,U=x.prototype;e.prototype={getDate:function(){return this._.getUTCDate()},getDay:function(){return this._.getUTCDay()},getFullYear:function(){return this._.getUTCFullYear()},getHours:function(){return this._.getUTCHours()},getMilliseconds:function(){return this._.getUTCMilliseconds()},getMinutes:function(){return this._.getUTCMinutes()},getMonth:function(){return this._.getUTCMonth()},getSeconds:function(){return this._.getUTCSeconds()},getTime:function(){return this._.getTime()},getTimezoneOffset:function(){return 0},valueOf:function(){return this._.valueOf()},setDate:function(){return U.setUTCDate.apply(this._,arguments)},setDay:function(){return U.setUTCDay.apply(this._,arguments)},setFullYear:function(){return U.setUTCFullYear.apply(this._,arguments)},setHours:function(){return U.setUTCHours.apply(this._,arguments)},setMilliseconds:function(){return U.setUTCMilliseconds.apply(this._,arguments)},setMinutes:function(){return U.setUTCMinutes.apply(this._,arguments)},setMonth:function(){return U.setUTCMonth.apply(this._,arguments)},setSeconds:function(){return U.setUTCSeconds.apply(this._,arguments)},setTime:function(){return U.setTime.apply(this._,arguments)}};var H=/^%/,Y=/^\s*\d+/,A=D(function(t){t.setHours(0,0,0,0),t.setMonth(0,1)},function(t,e){t.setFullYear(t.getFullYear()+e)},function(t,e){return e.getFullYear()-t.getFullYear()}),O=v(1),b=v(0),j=D(function(t){t.setHours(0,0,0,0)},function(t,e){t.setDate(t.getDate()+e)},function(t,e){return(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/864e5}),L=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,Z=_({dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",periods:["AM","PM"],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"]});t.format=Z.format,t.utcFormat=Z.utcFormat;var W="%Y-%m-%dT%H:%M:%S.%LZ";C.parse=function(t){var e=new Date(t);return isNaN(e)?null:e},C.toString=function(){return W};var z=Date.prototype.toISOString&&+new Date("2000-01-01T00:00:00.000Z")?C:Z.utcFormat(W),J=z;t.isoFormat=J,t.localeFormat=_});
"undefined"==typeof Map?(Map=function(){this.clear()},Map.prototype={set:function(t,n){return this._[t]=n,this},get:function(t){return this._[t]},has:function(t){return t in this._},"delete":function(t){return t in this._&&delete this._[t]},clear:function(){this._=Object.create(null)},get size(){var t=0;for(var n in this._)++t;return t},forEach:function(t){for(var n in this._)t(this._[n],n,this)}}):function(){var t=new Map;t.set(0,0)!==t&&(t=t.set,Map.prototype.set=function(){return t.apply(this,arguments),this})}(),function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.timeFormat={})}(this,function(t){"use strict";function n(t){if(0<=t.y&&t.y<100){var n=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return n.setUTCFullYear(t.y),n}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function e(t){if(0<=t.y&&t.y<100){var n=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return n.setFullYear(t.y),n}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function r(t){return{y:t,m:0,d:1,H:0,M:0,S:0,L:0}}function u(t,n,e){var r=rt.exec(n.slice(e,e+1));return r?e+r[0].length:-1}function o(t,n,e){return/^[+-]\d{4}$/.test(n=n.slice(e,e+5))?(t.Z=-n,e+5):-1}function i(t,n,e){var r=ut.exec(n.slice(e,e+1));return r?(t.w=+r[0],e+r[0].length):-1}function c(t,n,e){var r=ut.exec(n.slice(e));return r?(t.U=+r[0],e+r[0].length):-1}function a(t,n,e){var r=ut.exec(n.slice(e));return r?(t.W=+r[0],e+r[0].length):-1}function f(t,n,e){var r=ut.exec(n.slice(e,e+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),e+r[0].length):-1}function s(t,n,e){var r=ut.exec(n.slice(e,e+2));return r?(t.m=r[0]-1,e+r[0].length):-1}function l(t,n,e){var r=ut.exec(n.slice(e,e+2));return r?(t.d=+r[0],e+r[0].length):-1}function g(t,n,e){var r=ut.exec(n.slice(e,e+3));return r?(t.m=0,t.d=+r[0],e+r[0].length):-1}function h(t,n,e){var r=ut.exec(n.slice(e,e+2));return r?(t.H=+r[0],e+r[0].length):-1}function d(t,n,e){var r=ut.exec(n.slice(e,e+2));return r?(t.M=+r[0],e+r[0].length):-1}function y(t,n,e){var r=ut.exec(n.slice(e,e+2));return r?(t.S=+r[0],e+r[0].length):-1}function T(t,n,e){var r=ut.exec(n.slice(e,e+3));return r?(t.L=+r[0],e+r[0].length):-1}function m(t,n,e){var r=ut.exec(n.slice(e,e+4));return r?(t.y=+r[0],e+r[0].length):-1}function D(){return"%"}function p(){return"+0000"}function U(t,n,e){var r=0>t?"-":"",u=(r?-t:t)+"",o=u.length;return r+(e>o?new Array(e-o+1).join(n)+u:u)}function v(t,n){return U(t.getUTCFullYear()%1e4,n,4)}function C(t,n){return U(t.getUTCFullYear()%100,n,2)}function M(t,n,e){function r(n){return t(n=new Date(+n)),n}return r.floor=r,r.round=function(e){var r=new Date(+e),u=new Date(e-1);return t(r),t(u),n(u,1),u-e>e-r?r:u},r.ceil=function(e){return t(e=new Date(e-1)),n(e,1),e},r.offset=function(t,e){return n(t=new Date(+t),null==e?1:Math.floor(e)),t},r.range=function(e,r,u){var o=[];if(e=new Date(e-1),r=new Date(+r),u=null==u?1:Math.floor(u),!(r>e&&u>0))return o;for(n(e,1),t(e),r>e&&o.push(new Date(+e));n(e,u),t(e),r>e;)o.push(new Date(+e));return o},r.filter=function(e){return M(function(n){for(;t(n),!e(n);)n.setTime(n-1)},function(t,r){for(;--r>=0;)for(;n(t,1),!e(t););})},e&&(r.count=function(n,r){return it.setTime(+n),ot.setTime(+r),t(it),t(ot),Math.floor(e(it,ot))}),r}function w(t){return M(function(n){n.setUTCHours(0,0,0,0),n.setUTCDate(n.getUTCDate()-(n.getUTCDay()+7-t)%7)},function(t,n){t.setUTCDate(t.getUTCDate()+7*n)},function(t,n){return(n-t)/6048e5})}function x(t,n){return U(at.count(ct(t),t),n,2)}function H(t){return t.getUTCDay()}function S(t,n){return U(ft.count(ct(t),t),n,2)}function F(t,n){return U(t.getUTCSeconds(),n,2)}function Y(t,n){return U(t.getUTCMinutes(),n,2)}function A(t,n){return U(t.getUTCMonth()+1,n,2)}function L(t,n){return U(t.getUTCMilliseconds(),n,3)}function b(t,n){return U(1+st.count(ct(t),t),n,3)}function W(t,n){return U(t.getUTCHours()%12||12,n,2)}function O(t,n){return U(t.getUTCHours(),n,2)}function j(t,n){return U(t.getUTCDate(),n,2)}function _(t){var n=t.getTimezoneOffset();return(n>0?"-":(n*=-1,"+"))+U(n/60|0,"0",2)+U(n%60,"0",2)}function Z(t,n){return U(t.getFullYear()%1e4,n,4)}function J(t,n){return U(t.getFullYear()%100,n,2)}function X(t){return M(function(n){n.setHours(0,0,0,0),n.setDate(n.getDate()-(n.getDay()+7-t)%7)},function(t,n){t.setDate(t.getDate()+7*n)},function(t,n){return(n-t-6e4*(n.getTimezoneOffset()-t.getTimezoneOffset()))/6048e5})}function z(t,n){return U(gt.count(lt(t),t),n,2)}function I(t){return t.getDay()}function N(t,n){return U(ht.count(lt(t),t),n,2)}function B(t,n){return U(t.getSeconds(),n,2)}function $(t,n){return U(t.getMinutes(),n,2)}function E(t,n){return U(t.getMonth()+1,n,2)}function P(t,n){return U(t.getMilliseconds(),n,3)}function R(t,n){return U(1+dt.count(lt(t),t),n,3)}function k(t,n){return U(t.getHours()%12||12,n,2)}function q(t,n){return U(t.getHours(),n,2)}function G(t,n){return U(t.getDate(),n,2)}function K(t){for(var n=new Map,e=-1,r=t.length;++e<r;)n.set(t[e].toLowerCase(),e);return n}function Q(t){return t.replace(yt,"\\$&")}function V(t){return new RegExp("^(?:"+t.map(Q).join("|")+")","i")}function tt(t){function U(t,n){return function(e){for(var r,u,o,i=[],c=-1,a=0,f=t.length;++c<f;)37===t.charCodeAt(c)&&(i.push(t.slice(a,c)),null!=(u=et[r=t.charAt(++c)])&&(r=t.charAt(++c)),(o=n[r])&&(r=o(e,null==u?"e"===r?" ":"0":u)),i.push(r),a=c+1);return i.push(t.slice(a,c)),i.join("")}}function M(t,e){return function(u){var o=r(1900),i=w(o,t,u,0);if(i!=u.length)return null;if("p"in o&&(o.H=o.H%12+12*o.p),"Z"in o){if("w"in o&&("W"in o||"U"in o)){var c=n(r(o.y)).getUTCDay();"W"in o&&(o.U=o.W,o.w=(o.w+6)%7,--c),o.m=0,o.d=o.w+7*o.U-(c+6)%7}return o.H+=o.Z/100|0,o.M+=o.Z%100,n(o)}if("w"in o&&("W"in o||"U"in o)){var c=e(r(o.y)).getDay();"W"in o&&(o.U=o.W,o.w=(o.w+6)%7,--c),o.m=0,o.d=o.w+7*o.U-(c+6)%7}return e(o)}}function w(t,n,e,r){for(var u,o,i=0,c=n.length,a=e.length;c>i;){if(r>=a)return-1;if(u=n.charCodeAt(i++),37===u){if(u=n.charAt(i++),o=_t[u in et?n.charAt(i++):u],!o||(r=o(t,e,r))<0)return-1}else if(u!=e.charCodeAt(r++))return-1}return r}function X(t,n,e){var r=Ft.exec(n.slice(e));return r?(t.w=Yt.get(r[0].toLowerCase()),e+r[0].length):-1}function Q(t,n,e){var r=Ht.exec(n.slice(e));return r?(t.w=St.get(r[0].toLowerCase()),e+r[0].length):-1}function tt(t,n,e){var r=bt.exec(n.slice(e));return r?(t.m=Wt.get(r[0].toLowerCase()),e+r[0].length):-1}function nt(t,n,e){var r=At.exec(n.slice(e));return r?(t.m=Lt.get(r[0].toLowerCase()),e+r[0].length):-1}function rt(t,n,e){return w(t,mt,n,e)}function ut(t,n,e){return w(t,Dt,n,e)}function ot(t,n,e){return w(t,pt,n,e)}function it(t,n,e){var r=xt.get(n.slice(e,e+=2).toLowerCase());return null==r?-1:(t.p=r,e)}function ct(t){return Ct[t.getDay()]}function at(t){return vt[t.getDay()]}function ft(t){return wt[t.getMonth()]}function st(t){return Mt[t.getMonth()]}function lt(t){return Ut[+(t.getHours()>=12)]}function gt(t){return Ct[t.getUTCDay()]}function ht(t){return vt[t.getUTCDay()]}function dt(t){return wt[t.getUTCMonth()]}function yt(t){return Mt[t.getUTCMonth()]}function Tt(t){return Ut[+(t.getUTCHours()>=12)]}var mt=t.dateTime,Dt=t.date,pt=t.time,Ut=t.periods,vt=t.days,Ct=t.shortDays,Mt=t.months,wt=t.shortMonths,xt=K(Ut),Ht=V(vt),St=K(vt),Ft=V(Ct),Yt=K(Ct),At=V(Mt),Lt=K(Mt),bt=V(wt),Wt=K(wt),Ot={a:ct,A:at,b:ft,B:st,c:null,d:G,e:G,H:q,I:k,j:R,L:P,m:E,M:$,p:lt,S:B,U:N,w:I,W:z,x:null,X:null,y:J,Y:Z,Z:_,"%":D},jt={a:gt,A:ht,b:dt,B:yt,c:null,d:j,e:j,H:O,I:W,j:b,L:L,m:A,M:Y,p:Tt,S:F,U:S,w:H,W:x,x:null,X:null,y:C,Y:v,Z:p,"%":D},_t={a:X,A:Q,b:tt,B:nt,c:rt,d:l,e:l,H:h,I:h,j:g,L:T,m:s,M:d,p:it,S:y,U:c,w:i,W:a,x:ut,X:ot,y:f,Y:m,Z:o,"%":u};return Ot.x=U(Dt,Ot),Ot.X=U(pt,Ot),Ot.c=U(mt,Ot),jt.x=U(Dt,jt),jt.X=U(pt,jt),jt.c=U(mt,jt),{format:function(t){var n=U(t+="",Ot);return n.parse=M(t,e),n.toString=function(){return t},n},utcFormat:function(t){var e=U(t+="",jt);return e.parse=M(t,n),e.toString=function(){return t},e}}}function nt(t){return t.toISOString()}var et={"-":"",_:" ",0:"0"},rt=/^%/,ut=/^\s*\d+/,ot=new Date,it=new Date,ct=M(function(t){t.setUTCHours(0,0,0,0),t.setUTCMonth(0,1)},function(t,n){t.setUTCFullYear(t.getUTCFullYear()+n)},function(t,n){return n.getUTCFullYear()-t.getUTCFullYear()}),at=w(1),ft=w(0),st=M(function(t){t.setUTCHours(0,0,0,0)},function(t,n){t.setUTCDate(t.getUTCDate()+n)},function(t,n){return(n-t)/864e5}),lt=M(function(t){t.setHours(0,0,0,0),t.setMonth(0,1)},function(t,n){t.setFullYear(t.getFullYear()+n)},function(t,n){return n.getFullYear()-t.getFullYear()}),gt=X(1),ht=X(0),dt=M(function(t){t.setHours(0,0,0,0)},function(t,n){t.setDate(t.getDate()+n)},function(t,n){return(n-t-6e4*(n.getTimezoneOffset()-t.getTimezoneOffset()))/864e5}),yt=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,Tt=tt({dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",periods:["AM","PM"],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"]});t.format=Tt.format,t.utcFormat=Tt.utcFormat;var mt="%Y-%m-%dT%H:%M:%S.%LZ";nt.parse=function(t){var n=new Date(t);return isNaN(n)?null:n},nt.toString=function(){return mt};var Dt=Date.prototype.toISOString&&+new Date("2000-01-01T00:00:00.000Z")?nt:Tt.utcFormat(mt),pt=Dt;t.isoFormat=pt,t.localeFormat=tt});
{
"name": "d3-time-format",
"version": "0.0.1",
"description": "A JavaScript time formatter and parser inspired by C’s strftime and strptime.",
"version": "0.0.2",
"description": "A JavaScript time formatter and parser inspired by strftime and strptime.",
"keywords": [

@@ -6,0 +6,0 @@ "d3",

@@ -1,6 +0,25 @@

import {day, sunday, monday, year} from "d3-time";
import UtcDate from "./UtcDate";
import {day, sunday, monday, year, utcDay, utcSunday, utcMonday, utcYear} from "d3-time";
var LocalDate = Date;
function localDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
date.setFullYear(d.y);
return date;
}
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
}
function utcDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
date.setUTCFullYear(d.y);
return date;
}
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
}
function newYear(y) {
return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
}
export default function(locale) {

@@ -11,4 +30,4 @@ var locale_dateTime = locale.dateTime,

locale_periods = locale.periods,
locale_days = locale.days,
locale_shortDays = locale.shortDays,
locale_weekdays = locale.days,
locale_shortWeekdays = locale.shortDays,
locale_months = locale.months,

@@ -18,46 +37,73 @@ locale_shortMonths = locale.shortMonths;

var periodLookup = formatLookup(locale_periods),
dayRe = formatRe(locale_days),
dayLookup = formatLookup(locale_days),
dayAbbrevRe = formatRe(locale_shortDays),
dayAbbrevLookup = formatLookup(locale_shortDays),
weekdayRe = formatRe(locale_weekdays),
weekdayLookup = formatLookup(locale_weekdays),
shortWeekdayRe = formatRe(locale_shortWeekdays),
shortWeekdayLookup = formatLookup(locale_shortWeekdays),
monthRe = formatRe(locale_months),
monthLookup = formatLookup(locale_months),
monthAbbrevRe = formatRe(locale_shortMonths),
monthAbbrevLookup = formatLookup(locale_shortMonths);
shortMonthRe = formatRe(locale_shortMonths),
shortMonthLookup = formatLookup(locale_shortMonths);
var formats = {
"a": function(d) { return locale_shortDays[d.getDay()]; },
"A": function(d) { return locale_days[d.getDay()]; },
"b": function(d) { return locale_shortMonths[d.getMonth()]; },
"B": function(d) { return locale_months[d.getMonth()]; },
"c": newFormat(locale_dateTime),
"d": function(d, p) { return pad(d.getDate(), p, 2); },
"e": function(d, p) { return pad(d.getDate(), p, 2); },
"H": function(d, p) { return pad(d.getHours(), p, 2); },
"I": function(d, p) { return pad(d.getHours() % 12 || 12, p, 2); },
"j": function(d, p) { return pad(1 + day.count(year(d), d), p, 3); },
"L": function(d, p) { return pad(d.getMilliseconds(), p, 3); },
"m": function(d, p) { return pad(d.getMonth() + 1, p, 2); },
"M": function(d, p) { return pad(d.getMinutes(), p, 2); },
"p": function(d) { return locale_periods[+(d.getHours() >= 12)]; },
"S": function(d, p) { return pad(d.getSeconds(), p, 2); },
"U": function(d, p) { return pad(sunday.count(year(d), d), p, 2); },
"w": function(d) { return d.getDay(); },
"W": function(d, p) { return pad(monday.count(year(d), d), p, 2); },
"x": newFormat(locale_date),
"X": newFormat(locale_time),
"y": function(d, p) { return pad(d.getFullYear() % 100, p, 2); },
"Y": function(d, p) { return pad(d.getFullYear() % 10000, p, 4); },
"a": formatShortWeekday,
"A": formatWeekday,
"b": formatShortMonth,
"B": formatMonth,
"c": null,
"d": formatDayOfMonth,
"e": formatDayOfMonth,
"H": formatHour24,
"I": formatHour12,
"j": formatDayOfYear,
"L": formatMilliseconds,
"m": formatMonthNumber,
"M": formatMinutes,
"p": formatPeriod,
"S": formatSeconds,
"U": formatWeekNumberSunday,
"w": formatWeekdayNumber,
"W": formatWeekNumberMonday,
"x": null,
"X": null,
"y": formatYear,
"Y": formatFullYear,
"Z": formatZone,
"%": function() { return "%"; }
"%": formatLiteralPercent
};
var utcFormats = {
"a": formatUTCShortWeekday,
"A": formatUTCWeekday,
"b": formatUTCShortMonth,
"B": formatUTCMonth,
"c": null,
"d": formatUTCDayOfMonth,
"e": formatUTCDayOfMonth,
"H": formatUTCHour24,
"I": formatUTCHour12,
"j": formatUTCDayOfYear,
"L": formatUTCMilliseconds,
"m": formatUTCMonthNumber,
"M": formatUTCMinutes,
"p": formatUTCPeriod,
"S": formatUTCSeconds,
"U": formatUTCWeekNumberSunday,
"w": formatUTCWeekdayNumber,
"W": formatUTCWeekNumberMonday,
"x": null,
"X": null,
"y": formatUTCYear,
"Y": formatUTCFullYear,
"Z": formatUTCZone,
"%": formatLiteralPercent
};
var parses = {
"a": parseWeekdayAbbrev,
"a": parseShortWeekday,
"A": parseWeekday,
"b": parseMonthAbbrev,
"b": parseShortMonth,
"B": parseMonth,
"c": parseLocaleDateTime,
"d": parseDay,
"e": parseDay,
"d": parseDayOfMonth,
"e": parseDayOfMonth,
"H": parseHour24,

@@ -69,3 +115,3 @@ "I": parseHour24,

"M": parseMinutes,
"p": parseAmPm,
"p": parsePeriod,
"S": parseSeconds,

@@ -83,6 +129,12 @@ "U": parseWeekNumberSunday,

function newFormat(specifier) {
specifier += "";
// These recursive directive definitions must be deferred.
formats.x = newFormat(locale_date, formats);
formats.X = newFormat(locale_time, formats);
formats.c = newFormat(locale_dateTime, formats);
utcFormats.x = newFormat(locale_date, utcFormats);
utcFormats.X = newFormat(locale_time, utcFormats);
utcFormats.c = newFormat(locale_dateTime, utcFormats);
function format(date) {
function newFormat(specifier, formats) {
return function(date) {
var string = [],

@@ -108,6 +160,8 @@ i = -1,

return string.join("");
}
};
}
format.parse = function(string) {
var d = {y: 1900, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0, Z: null},
function newParse(specifier, newDate) {
return function(string) {
var d = newYear(1900),
i = parseSpecifier(d, specifier, string, 0);

@@ -119,59 +173,25 @@ if (i != string.length) return null;

// If a time zone is specified, it is always relative to UTC;
// we need to use UtcDate if we aren’t already.
var localZ = d.Z != null && Date !== UtcDate,
date = new (localZ ? UtcDate : Date);
// Set year, month, date.
if ("j" in d) {
date.setFullYear(d.y, 0, d.j);
} else if ("w" in d && ("W" in d || "U" in d)) {
date.setFullYear(d.y, 0, 1);
date.setFullYear(d.y, 0, "W" in d
? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7
: d.w + d.U * 7 - (date.getDay() + 6) % 7);
} else {
date.setFullYear(d.y, d.m, d.d);
// If a time zone is specified, all fields are interpreted as UTC and then
// offset according to the specified time zone.
if ("Z" in d) {
if ("w" in d && ("W" in d || "U" in d)) {
var day = utcDate(newYear(d.y)).getUTCDay();
if ("W" in d) d.U = d.W, d.w = (d.w + 6) % 7, --day;
d.m = 0;
d.d = d.w + d.U * 7 - (day + 6) % 7;
}
d.H += d.Z / 100 | 0;
d.M += d.Z % 100;
return utcDate(d);
}
// Set hours, minutes, seconds and milliseconds.
date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
return localZ ? date._ : date;
};
format.toString = function() {
return specifier;
};
return format;
}
function newUtcFormat(specifier) {
var local = newFormat(specifier);
function format(date) {
try {
Date = UtcDate;
var utc = new Date;
utc._ = date;
return local(utc);
} finally {
Date = LocalDate;
// Otherwise, all fields are in local time.
if ("w" in d && ("W" in d || "U" in d)) {
var day = newDate(newYear(d.y)).getDay();
if ("W" in d) d.U = d.W, d.w = (d.w + 6) % 7, --day;
d.m = 0;
d.d = d.w + d.U * 7 - (day + 6) % 7;
}
}
format.parse = function(string) {
try {
Date = UtcDate;
var date = local.parse(string);
return date && date._;
} finally {
Date = LocalDate;
}
return newDate(d);
};
format.toString = local.toString;
return format;
}

@@ -201,15 +221,15 @@

function parseWeekdayAbbrev(d, string, i) {
var n = dayAbbrevRe.exec(string.slice(i));
return n ? (d.w = dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
function parseShortWeekday(d, string, i) {
var n = shortWeekdayRe.exec(string.slice(i));
return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
}
function parseWeekday(d, string, i) {
var n = dayRe.exec(string.slice(i));
return n ? (d.w = dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
var n = weekdayRe.exec(string.slice(i));
return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
}
function parseMonthAbbrev(d, string, i) {
var n = monthAbbrevRe.exec(string.slice(i));
return n ? (d.m = monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
function parseShortMonth(d, string, i) {
var n = shortMonthRe.exec(string.slice(i));
return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
}

@@ -234,3 +254,3 @@

function parseAmPm(d, string, i) {
function parsePeriod(d, string, i) {
var n = periodLookup.get(string.slice(i, i += 2).toLowerCase());

@@ -240,5 +260,55 @@ return n == null ? -1 : (d.p = n, i);

function formatShortWeekday(d) {
return locale_shortWeekdays[d.getDay()];
}
function formatWeekday(d) {
return locale_weekdays[d.getDay()];
}
function formatShortMonth(d) {
return locale_shortMonths[d.getMonth()];
}
function formatMonth(d) {
return locale_months[d.getMonth()];
}
function formatPeriod(d) {
return locale_periods[+(d.getHours() >= 12)];
}
function formatUTCShortWeekday(d) {
return locale_shortWeekdays[d.getUTCDay()];
}
function formatUTCWeekday(d) {
return locale_weekdays[d.getUTCDay()];
}
function formatUTCShortMonth(d) {
return locale_shortMonths[d.getUTCMonth()];
}
function formatUTCMonth(d) {
return locale_months[d.getUTCMonth()];
}
function formatUTCPeriod(d) {
return locale_periods[+(d.getUTCHours() >= 12)];
}
return {
format: newFormat,
utcFormat: newUtcFormat
format: function(specifier) {
var f = newFormat(specifier += "", formats);
f.parse = newParse(specifier, localDate);
f.toString = function() { return specifier; };
return f;
},
utcFormat: function(specifier) {
var f = newFormat(specifier += "", utcFormats);
f.parse = newParse(specifier, utcDate);
f.toString = function() { return specifier; };
return f;
}
};

@@ -309,3 +379,3 @@ };

function parseDay(d, string, i) {
function parseDayOfMonth(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));

@@ -317,6 +387,5 @@ return n ? (d.d = +n[0], i + n[0].length) : -1;

var n = numberRe.exec(string.slice(i, i + 3));
return n ? (d.j = +n[0], i + n[0].length) : -1;
return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
}
// Note: we don't validate that the hour is in the range [0,23] or [1,12].
function parseHour24(d, string, i) {

@@ -347,2 +416,54 @@ var n = numberRe.exec(string.slice(i, i + 2));

function formatDayOfMonth(d, p) {
return pad(d.getDate(), p, 2);
}
function formatHour24(d, p) {
return pad(d.getHours(), p, 2);
}
function formatHour12(d, p) {
return pad(d.getHours() % 12 || 12, p, 2);
}
function formatDayOfYear(d, p) {
return pad(1 + day.count(year(d), d), p, 3);
}
function formatMilliseconds(d, p) {
return pad(d.getMilliseconds(), p, 3);
}
function formatMonthNumber(d, p) {
return pad(d.getMonth() + 1, p, 2);
}
function formatMinutes(d, p) {
return pad(d.getMinutes(), p, 2);
}
function formatSeconds(d, p) {
return pad(d.getSeconds(), p, 2);
}
function formatWeekNumberSunday(d, p) {
return pad(sunday.count(year(d), d), p, 2);
}
function formatWeekdayNumber(d) {
return d.getDay();
}
function formatWeekNumberMonday(d, p) {
return pad(monday.count(year(d), d), p, 2);
}
function formatYear(d, p) {
return pad(d.getFullYear() % 100, p, 2);
}
function formatFullYear(d, p) {
return pad(d.getFullYear() % 10000, p, 4);
}
function formatZone(d) {

@@ -354,1 +475,61 @@ var z = d.getTimezoneOffset();

}
function formatUTCDayOfMonth(d, p) {
return pad(d.getUTCDate(), p, 2);
}
function formatUTCHour24(d, p) {
return pad(d.getUTCHours(), p, 2);
}
function formatUTCHour12(d, p) {
return pad(d.getUTCHours() % 12 || 12, p, 2);
}
function formatUTCDayOfYear(d, p) {
return pad(1 + utcDay.count(utcYear(d), d), p, 3);
}
function formatUTCMilliseconds(d, p) {
return pad(d.getUTCMilliseconds(), p, 3);
}
function formatUTCMonthNumber(d, p) {
return pad(d.getUTCMonth() + 1, p, 2);
}
function formatUTCMinutes(d, p) {
return pad(d.getUTCMinutes(), p, 2);
}
function formatUTCSeconds(d, p) {
return pad(d.getUTCSeconds(), p, 2);
}
function formatUTCWeekNumberSunday(d, p) {
return pad(utcSunday.count(utcYear(d), d), p, 2);
}
function formatUTCWeekdayNumber(d) {
return d.getUTCDay();
}
function formatUTCWeekNumberMonday(d, p) {
return pad(utcMonday.count(utcYear(d), d), p, 2);
}
function formatUTCYear(d, p) {
return pad(d.getUTCFullYear() % 100, p, 2);
}
function formatUTCFullYear(d, p) {
return pad(d.getUTCFullYear() % 10000, p, 4);
}
function formatUTCZone() {
return "+0000";
}
function formatLiteralPercent() {
return "%";
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc