timezone
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -29,6 +29,14 @@ (function() { | ||
}, | ||
dateFormat: "%m/%d/%y", | ||
timeFormat: "%H:%M:%S", | ||
dateTimeFormat: "%a %b %_d %H:%M:%S %Y", | ||
meridiem: ["am", "pm"], | ||
dateFormat: "%m/%d/%Y", | ||
timeFormat: "%I:%M:%S %p", | ||
dateTimeFormat: "%a %d %b %Y %I:%M:%S %p %Z", | ||
meridiem: [ | ||
{ | ||
lower: "am", | ||
upper: "AM" | ||
}, { | ||
lower: "pm", | ||
upper: "PM" | ||
} | ||
], | ||
monthBeforeDate: true | ||
@@ -215,6 +223,6 @@ } | ||
P: function(date, locale) { | ||
return locale.meridiem[Math.floor(date.getUTCHours() / 12)]; | ||
return locale.meridiem[Math.floor(date.getUTCHours() / 12)].lower; | ||
}, | ||
p: function(date, locale) { | ||
return locale.meridiem[Math.floor(date.getUTCHours() / 12)].toUpperCase(); | ||
return locale.meridiem[Math.floor(date.getUTCHours() / 12)].upper; | ||
}, | ||
@@ -260,2 +268,5 @@ M: function(date) { | ||
} | ||
}, | ||
Z: function() { | ||
return "UTC"; | ||
} | ||
@@ -315,3 +326,3 @@ }; | ||
while (rest.length) { | ||
match = /^(.*?)%(?:%|([-0_^]?)([aAcdDeFHIjklMNpPsrRSTuwXUWVmhbByYcGgCx]))(.*)$/.exec(rest); | ||
match = /^(.*?)%(?:%|([-0_^]?)([aAcdDeFHIjklMNpPsrRSTuwXUWVmhbByYcGgCxzZ]))(.*)$/.exec(rest); | ||
if (match) { | ||
@@ -661,3 +672,3 @@ _ref2 = match.slice(1), prefix = _ref2[0], flags = _ref2[1], specifier = _ref2[2], rest = _ref2[3]; | ||
adjust = (function() { | ||
var FIELD, SIGN_OFFSET, explode; | ||
var ASSIGNMENT, DAYS, FIELD, SIGN_OFFSET, TIME, explode; | ||
FIELD = { | ||
@@ -672,2 +683,8 @@ year: 0, | ||
}; | ||
TIME = { | ||
milli: 1, | ||
second: SECOND, | ||
minute: MINUTE, | ||
hour: HOUR | ||
}; | ||
SIGN_OFFSET = { | ||
@@ -677,62 +694,99 @@ "-": -1, | ||
}; | ||
DAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]; | ||
ASSIGNMENT = { | ||
year: { | ||
min: 0, | ||
max: Number.MAX_VALUE | ||
}, | ||
month: { | ||
min: 1, | ||
max: 12 | ||
}, | ||
day: { | ||
min: 1, | ||
max: 12 | ||
} | ||
}; | ||
explode = function(wallclock) {}; | ||
return function(wallclock, adjustment, tzdata) { | ||
var count, date, fields, forward, increment, match, month, offset, offsets, rest, sign, terminal, unit, utc, _ref; | ||
var count, date, fields, forward, increment, index, match, millis, month, offset, position, sign, unit, utc, _ref, _ref2; | ||
fields = explode(wallclock); | ||
offsets = [0, 0, 0, 0, 0, 0, 0]; | ||
rest = adjustment.replace(/^\s+/, ""); | ||
while (true) { | ||
match = /^([+-])\s*(\d+)\s+(year|month|day|hour|minute|second|milli)s?(:?(?:\s+(.*))|(.*))$/.exec(rest); | ||
if (!match) { | ||
throw new Error("bad date math pattern " + adjustment + "."); | ||
} | ||
_ref = match.slice(1), sign = _ref[0], count = _ref[1], unit = _ref[2], rest = _ref[3], terminal = _ref[4]; | ||
if (terminal != null) { | ||
if (terminal !== "") { | ||
throw new Error("bad date math pattern " + adjustment + "."); | ||
match = /^\s*([+-]?)\s*(\d+)\s+(year|month|day|hour|minute|second|milli|sunday|monday|tuesday|wednesday|thursday|friday|saturday)s?\s*$/i.exec(adjustment); | ||
if (match) { | ||
_ref = match.slice(1), sign = _ref[0], count = _ref[1], unit = _ref[2]; | ||
sign || (sign = "+"); | ||
unit = unit.toLowerCase(); | ||
increment = SIGN_OFFSET[sign]; | ||
offset = parseInt(count, 10); | ||
if ((index = DAYS.indexOf(unit)) !== -1) { | ||
while (offset !== 0) { | ||
wallclock += increment * DAY; | ||
if (new Date(wallclock).getDay() === index) { | ||
offset--; | ||
} | ||
} | ||
break; | ||
} | ||
offsets[FIELD[unit]] += parseInt(count, 10) * SIGN_OFFSET[sign]; | ||
if (rest === "") { | ||
break; | ||
} | ||
} | ||
utc = convertToUTC(wallclock, tzdata); | ||
utc += offsets[FIELD.milli]; | ||
utc += offsets[FIELD.second] * SECOND; | ||
utc += offsets[FIELD.minute] * MINUTE; | ||
utc += offsets[FIELD.hour] * HOUR; | ||
wallclock = convertToWallclock(utc, tzdata); | ||
if (offset = offsets[FIELD.day]) { | ||
forward = offset / Math.abs(offset); | ||
wallclock += offset * DAY; | ||
} | ||
date = new Date(wallclock); | ||
fields = [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()]; | ||
if (offset = offsets[FIELD.month]) { | ||
forward = increment = offset / Math.abs(offset); | ||
while (offset !== 0) { | ||
month = offset[FIELD.month]; | ||
if (month === 0 && offset < 0) { | ||
fields[FIELD.month] = 11; | ||
fields[FIELD.year]--; | ||
} else if (month === 11 && offset > 0) { | ||
fields[FIELD.month] = 0; | ||
fields[FIELD.year]++; | ||
} else { | ||
if (millis = TIME[unit]) { | ||
utc = convertToUTC(wallclock, tzdata); | ||
utc += offset * increment * millis; | ||
wallclock = convertToWallclock(utc, tzdata); | ||
} else if (unit === "day") { | ||
wallclock += offset * increment * DAY; | ||
} else { | ||
fields[FIELD.month] += increment; | ||
date = new Date(wallclock); | ||
fields = [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()]; | ||
if (unit === "month") { | ||
while (offset !== 0) { | ||
month = fields[FIELD.month]; | ||
if (month === 0 && offset < 0) { | ||
fields[FIELD.month] = 11; | ||
fields[FIELD.year]--; | ||
} else if (month === 11 && offset > 0) { | ||
fields[FIELD.month] = 0; | ||
fields[FIELD.year]++; | ||
} else { | ||
fields[FIELD.month] += increment; | ||
} | ||
offset -= increment; | ||
} | ||
} | ||
if (unit === "year") { | ||
forward = offset / Math.abs(offset); | ||
fields[FIELD.year] += offset; | ||
} | ||
wallclock = Date.UTC.apply(null, fields); | ||
} | ||
offset += increment; | ||
} | ||
} else if (match = /^\s*(year|month|day|hour|minute|second|milli|time|sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s+(\d+)\s*$/.exec(adjustment)) { | ||
_ref2 = match.slice(1), unit = _ref2[0], position = _ref2[1]; | ||
unit = unit.toLowerCase(); | ||
date = new Date(wallclock); | ||
fields = [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()]; | ||
switch (unit) { | ||
case "year": | ||
fields[FIELD.year] = position; | ||
adjustment = "0 year"; | ||
break; | ||
case "month": | ||
if (position < 1) { | ||
throw new Error("invalid month"); | ||
} | ||
fields[FIELD.month] = 1; | ||
adjustment = "" + (position - 1) + " month"; | ||
break; | ||
case "day": | ||
fields[FIELD.day] = 1; | ||
adjustment = "" + (position - 1) + " day"; | ||
break; | ||
default: | ||
fields[FIELD[unit]] = 0; | ||
adjustment = "" + (position - 1) + " " + unit; | ||
} | ||
wallclock = Date.UTC.apply(null, fields); | ||
wallclock = adjust(wallclock, adjustment, tzdata); | ||
} | ||
if (offset = offsets[FIELD.year]) { | ||
forward = offset / Math.abs(offset); | ||
fields[FIELD.year] += offset; | ||
} | ||
wallclock = Date.UTC.apply(null, fields); | ||
if (!(convertToUTC(wallclock, tzdata) != null)) { | ||
wallclock += DAY * forward; | ||
wallclock += DAY * increment; | ||
utc = convertToUTC(wallclock, tzdata); | ||
utc -= DAY * forward; | ||
utc -= DAY * increment; | ||
wallclock = convertToWallclock(utc, tzdata); | ||
@@ -809,9 +863,8 @@ } | ||
}; | ||
tz.locales = function(override) { | ||
var k, v; | ||
if (override != null) { | ||
for (k in override) { | ||
v = override[k]; | ||
LOCALES[k] = v; | ||
} | ||
tz.locales = function() { | ||
var locale, locales, _i, _len; | ||
locales = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
for (_i = 0, _len = locales.length; _i < _len; _i++) { | ||
locale = locales[_i]; | ||
LOCALES[locale.name] = locale; | ||
} | ||
@@ -818,0 +871,0 @@ return LOCALES; |
{ "name": "timezone" | ||
, "version": "0.0.6" | ||
, "version": "0.0.7" | ||
, "author": "Alan Gutierrez" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2181265
100
44719
2