timezoned-date
Advanced tools
Comparing version 2.0.19 to 2.1.0
551
lib/index.js
@@ -1,290 +0,299 @@ | ||
/*jshint esversion: 6, evil: true, -W103*/ | ||
'use strict'; | ||
(function (root, factory) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = factory(); | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(factory); | ||
} else { | ||
root.TimezonedDate = factory(); | ||
} | ||
})(this, function () { | ||
'use strict'; | ||
var MILLISECONDS_PER_MINUTE = 60 * 1000, | ||
var MILLISECONDS_PER_MINUTE = 60 * 1000, | ||
// Such strings are parsed as UTC. See http://dygraphs.com/date-formats.html | ||
UTC_YYYY_MM_DD = /^\d\d\d\d(-\d\d){0,2}($|T)/, | ||
OFFSET_SUFFIX = /(((GMT)?[\+\-]\d\d:?\d\d)|Z)(\s*\(.+\))?$/, | ||
daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | ||
NativeDate = global.Date, | ||
nativeProto = NativeDate.prototype; | ||
function makeConstructor(boundOffset) { | ||
if (boundOffset === undefined) { | ||
boundOffset = -new NativeDate().getTimezoneOffset(); | ||
} | ||
var // If the resulting constructor is "bound", | ||
// - its signature is compatible with built-in Date, | ||
// - objects it creates always have the same offset (boundOffset). | ||
// If it's not, | ||
// - it takes the offset as the last argument, | ||
// - so it can create objects with different offsets. | ||
bound = isOffset(boundOffset); | ||
var proto = Object.create(nativeProto); | ||
var constructor = function Date(a0, a1, a2, a3, a4, a5, a6) { | ||
if (!(this instanceof constructor)) { | ||
if ( // When Date() is called without new, it ignores its arguments and | ||
// returns same as new Date().toString() | ||
bound) { | ||
return new constructor().toString(); | ||
} | ||
return new constructor(a0).toString(); | ||
// Such strings are parsed as UTC. See http://dygraphs.com/date-formats.html | ||
UTC_YYYY_MM_DD = /^\d\d\d\d(-\d\d){0,2}($|T)/, | ||
OFFSET_SUFFIX = /(((GMT)?[\+\-]\d\d:?\d\d)|Z)(\s*\(.+\))?$/, | ||
daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | ||
NativeDate = Date, | ||
nativeProto = NativeDate.prototype; | ||
function makeConstructor(boundOffset) { | ||
if (boundOffset === undefined) { | ||
boundOffset = -new NativeDate().getTimezoneOffset(); | ||
} | ||
var args, offset, len; | ||
if (bound) { | ||
args = arguments; | ||
offset = boundOffset; | ||
} else { | ||
args = Array.prototype.slice.call(arguments); | ||
offset = args.pop(); | ||
if (!isOffset(offset)) { | ||
throw new TypeError('TimezonedDate requires an offset'); | ||
var // If the resulting constructor is "bound", | ||
// - its signature is compatible with built-in Date, | ||
// - objects it creates always have the same offset (boundOffset). | ||
// If it's not, | ||
// - it takes the offset as the last argument, | ||
// - so it can create objects with different offsets. | ||
bound = isOffset(boundOffset); | ||
var proto = Object.create(nativeProto); | ||
var constructor = function Date(a0, a1, a2, a3, a4, a5, a6) { | ||
if (!(this instanceof constructor)) { | ||
if ( // When Date() is called without new, it ignores its arguments and | ||
// returns same as new Date().toString() | ||
bound) { | ||
return new constructor().toString(); | ||
} | ||
return new constructor(a0).toString(); | ||
} | ||
} | ||
len = args.length; | ||
var instance = len === 0 ? new NativeDate() : len === 1 ? new NativeDate(a0) : len === 2 ? new NativeDate(a0, a1) : len === 3 ? new NativeDate(a0, a1, a2) : len === 4 ? new NativeDate(a0, a1, a2, a3) : len === 5 ? new NativeDate(a0, a1, a2, a3, a4) : len === 6 ? new NativeDate(a0, a1, a2, a3, a4, a5) : new NativeDate(a0, a1, a2, a3, a4, a5, a6); | ||
setPrototypeOf(instance, proto); | ||
if (!bound) { | ||
instance.offset = function () { | ||
return offset; | ||
}; | ||
} | ||
var done = len === 0 || len === 1 && (a0 == null || a0 instanceof NativeDate || typeof a0 === 'number' || typeof a0 === 'boolean') || isNaN(instance.getDate()); | ||
if (!done && len > 1) { | ||
instance.setTime(NativeDate.UTC.apply(NativeDate, args) - MILLISECONDS_PER_MINUTE * offset); | ||
done = true; | ||
} | ||
if (!done && typeof a0 !== 'string') { | ||
// According to the ES specification, a0 should be converted to a string or a number | ||
// using quite a complicated algorithm. | ||
// ES5: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.3.2 | ||
// ES6: http://www.ecma-international.org/ecma-262/6.0/#sec-date-value | ||
// Let's try to avoid reimplementing this algorithm in JS. We'll call the native constructor | ||
// with the argument explicitly converted to a string and compare the results. | ||
done = new NativeDate('' + a0).getTime() !== instance.getTime(); | ||
} | ||
if (!done) { | ||
var string = '' + a0, | ||
isLocal = !UTC_YYYY_MM_DD.test(string) && !OFFSET_SUFFIX.test(string); | ||
if (isLocal) { | ||
var date = new NativeDate(string + ' ' + formatOffset(offset)); | ||
if (!isNaN(date.getTime())) { | ||
instance.setTime(date); | ||
} else { | ||
applyOffset(instance, -nativeProto.getTimezoneOffset.apply(instance) - offset); | ||
var args, offset, len; | ||
if (bound) { | ||
args = arguments; | ||
offset = boundOffset; | ||
} else { | ||
args = Array.prototype.slice.call(arguments); | ||
offset = args.pop(); | ||
if (!isOffset(offset)) { | ||
throw new TypeError('TimezonedDate requires an offset'); | ||
} | ||
} | ||
} | ||
return instance; | ||
}; | ||
setPrototypeOf(constructor, Date); | ||
var constructorPropertyDescriptors = makeMethodDescriptors({ | ||
UTC: NativeDate.UTC, | ||
parse: bound ? function parse(string) { | ||
return new constructor(String(string)).getTime(); | ||
} : NativeDate.parse | ||
}); | ||
constructorPropertyDescriptors.prototype = { | ||
value: proto, | ||
writable: false, | ||
configurable: false | ||
}; | ||
// The next line is needed for Node 0.10.x only | ||
constructor.prototype = proto; | ||
Object.defineProperties(constructor, constructorPropertyDescriptors); | ||
var protoMethods = { | ||
constructor: constructor, | ||
offset: function offset() { | ||
return boundOffset; | ||
}, | ||
withOffset: function withOffset(offset) { | ||
return new TimezonedDate(this.getTime(), offset); | ||
}, | ||
getTimezoneOffset: function getTimezoneOffset() { | ||
return -this.offset(); | ||
}, | ||
toDateString: function toDateString() { | ||
if (isNaN(this.getDate())) { | ||
return 'Invalid Date'; | ||
len = args.length; | ||
var instance = len === 0 ? new NativeDate() : len === 1 ? new NativeDate(a0) : len === 2 ? new NativeDate(a0, a1) : len === 3 ? new NativeDate(a0, a1, a2) : len === 4 ? new NativeDate(a0, a1, a2, a3) : len === 5 ? new NativeDate(a0, a1, a2, a3, a4) : len === 6 ? new NativeDate(a0, a1, a2, a3, a4, a5) : new NativeDate(a0, a1, a2, a3, a4, a5, a6); | ||
setPrototypeOf(instance, proto); | ||
if (!bound) { | ||
instance.offset = function () { | ||
return offset; | ||
}; | ||
} | ||
return [daysOfWeek[this.getDay()], months[this.getMonth()], addZero(this.getDate()), padYear(this.getFullYear())].join(' '); | ||
}, | ||
toTimeString: function toTimeString() { | ||
if (isNaN(this.getDate())) { | ||
return 'Invalid Date'; | ||
var done = len === 0 || len === 1 && (a0 == null || a0 instanceof NativeDate || typeof a0 === 'number' || typeof a0 === 'boolean') || isNaN(instance.getDate()); | ||
if (!done && len > 1) { | ||
instance.setTime(NativeDate.UTC.apply(NativeDate, args) - MILLISECONDS_PER_MINUTE * offset); | ||
done = true; | ||
} | ||
return [addZero(this.getHours()), ':', addZero(this.getMinutes()), ':', addZero(this.getSeconds()), ' ', formatOffset(this.offset())].join(''); | ||
}, | ||
toString: function toString() { | ||
if (isNaN(this.getDate())) { | ||
return 'Invalid Date'; | ||
if (!done && typeof a0 !== 'string') { | ||
// According to the ES specification, a0 should be converted to a string or a number | ||
// using quite a complicated algorithm. | ||
// ES5: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.3.2 | ||
// ES6: http://www.ecma-international.org/ecma-262/6.0/#sec-date-value | ||
// Let's try to avoid reimplementing this algorithm in JS. We'll call the native constructor | ||
// with the argument explicitly converted to a string and compare the results. | ||
done = new NativeDate('' + a0).getTime() !== instance.getTime(); | ||
} | ||
return this.toDateString() + ' ' + this.toTimeString(); | ||
}, | ||
getYear: function getYear() { | ||
return getLocalDate(this).getUTCFullYear() - 1900; | ||
}, | ||
setYear: function setYear(year) { | ||
return this.setFullYear(1900 + year); | ||
}, | ||
if (!done) { | ||
var string = '' + a0, | ||
isLocal = !UTC_YYYY_MM_DD.test(string) && !OFFSET_SUFFIX.test(string); | ||
if (isLocal) { | ||
var date = new NativeDate(string + ' ' + formatOffset(offset)); | ||
if (!isNaN(date.getTime())) { | ||
instance.setTime(date); | ||
} else { | ||
applyOffset(instance, -nativeProto.getTimezoneOffset.apply(instance) - offset); | ||
} | ||
} | ||
} | ||
return instance; | ||
}; | ||
setPrototypeOf(constructor, Date); | ||
var constructorPropertyDescriptors = makeMethodDescriptors({ | ||
UTC: NativeDate.UTC, | ||
parse: bound ? function parse(string) { | ||
return new constructor(String(string)).getTime(); | ||
} : NativeDate.parse | ||
}); | ||
constructorPropertyDescriptors.prototype = { | ||
value: proto, | ||
writable: false, | ||
configurable: false | ||
}; | ||
// The next line is needed for Node 0.10.x only | ||
constructor.prototype = proto; | ||
Object.defineProperties(constructor, constructorPropertyDescriptors); | ||
var protoMethods = { | ||
constructor: constructor, | ||
offset: function offset() { | ||
return boundOffset; | ||
}, | ||
withOffset: function withOffset(offset) { | ||
return new TimezonedDate(this.getTime(), offset); | ||
}, | ||
getTimezoneOffset: function getTimezoneOffset() { | ||
return isNaN(this.getDate()) ? NaN : -this.offset(); | ||
}, | ||
toDateString: function toDateString() { | ||
if (isNaN(this.getDate())) { | ||
return 'Invalid Date'; | ||
} | ||
return [daysOfWeek[this.getDay()], months[this.getMonth()], addZero(this.getDate()), padYear(this.getFullYear())].join(' '); | ||
}, | ||
toTimeString: function toTimeString() { | ||
if (isNaN(this.getDate())) { | ||
return 'Invalid Date'; | ||
} | ||
return [addZero(this.getHours()), ':', addZero(this.getMinutes()), ':', addZero(this.getSeconds()), ' ', formatOffset(this.offset())].join(''); | ||
}, | ||
toString: function toString() { | ||
if (isNaN(this.getDate())) { | ||
return 'Invalid Date'; | ||
} | ||
return this.toDateString() + ' ' + this.toTimeString(); | ||
}, | ||
getYear: function getYear() { | ||
return getLocalDate(this).getUTCFullYear() - 1900; | ||
}, | ||
setYear: function setYear(year) { | ||
return this.setFullYear(1900 + year); | ||
}, | ||
getTime: nativeProto.getTime, | ||
setTime: nativeProto.setTime, | ||
valueOf: nativeProto.valueOf, | ||
toUTCString: nativeProto.toUTCString, | ||
toGMTString: nativeProto.toGMTString || nativeProto.toUTCString, | ||
toLocaleString: nativeProto.toLocaleString, | ||
toLocaleDateString: nativeProto.toLocaleDateString, | ||
toLocaleTimeString: nativeProto.toLocaleTimeString | ||
}; | ||
protoMethods.getDate = function getDate() { | ||
return getLocalDate(this).getUTCDate(); | ||
}; | ||
protoMethods.getUTCDate = nativeProto.getUTCDate; | ||
protoMethods.setDate = function setDate(a0) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCDate.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCDate = nativeProto.setUTCDate; | ||
protoMethods.getDay = function getDay() { | ||
return getLocalDate(this).getUTCDay(); | ||
}; | ||
protoMethods.getUTCDay = nativeProto.getUTCDay; | ||
protoMethods.getFullYear = function getFullYear() { | ||
return getLocalDate(this).getUTCFullYear(); | ||
}; | ||
protoMethods.getUTCFullYear = nativeProto.getUTCFullYear; | ||
protoMethods.setFullYear = function setFullYear(a0, a1, a2) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCFullYear.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCFullYear = nativeProto.setUTCFullYear; | ||
protoMethods.getHours = function getHours() { | ||
return getLocalDate(this).getUTCHours(); | ||
}; | ||
protoMethods.getUTCHours = nativeProto.getUTCHours; | ||
protoMethods.setHours = function setHours(a0, a1, a2, a3) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCHours.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCHours = nativeProto.setUTCHours; | ||
protoMethods.getMilliseconds = function getMilliseconds() { | ||
return getLocalDate(this).getUTCMilliseconds(); | ||
}; | ||
protoMethods.getUTCMilliseconds = nativeProto.getUTCMilliseconds; | ||
protoMethods.setMilliseconds = function setMilliseconds(a0) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCMilliseconds.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCMilliseconds = nativeProto.setUTCMilliseconds; | ||
protoMethods.getMinutes = function getMinutes() { | ||
return getLocalDate(this).getUTCMinutes(); | ||
}; | ||
protoMethods.getUTCMinutes = nativeProto.getUTCMinutes; | ||
protoMethods.setMinutes = function setMinutes(a0, a1, a2) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCMinutes.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCMinutes = nativeProto.setUTCMinutes; | ||
protoMethods.getMonth = function getMonth() { | ||
return getLocalDate(this).getUTCMonth(); | ||
}; | ||
protoMethods.getUTCMonth = nativeProto.getUTCMonth; | ||
protoMethods.setMonth = function setMonth(a0, a1) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCMonth.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCMonth = nativeProto.setUTCMonth; | ||
protoMethods.getSeconds = function getSeconds() { | ||
return getLocalDate(this).getUTCSeconds(); | ||
}; | ||
protoMethods.getUTCSeconds = nativeProto.getUTCSeconds; | ||
protoMethods.setSeconds = function setSeconds(a0, a1) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCSeconds.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCSeconds = nativeProto.setUTCSeconds; | ||
var prototypePropertyDescriptors = makeMethodDescriptors(protoMethods); | ||
if (typeof Symbol !== 'undefined') { | ||
if (Symbol.toStringTag) { | ||
// Node v6+ or a polyfill | ||
prototypePropertyDescriptors[Symbol.toStringTag] = { value: 'Date' }; | ||
getTime: nativeProto.getTime, | ||
setTime: nativeProto.setTime, | ||
valueOf: nativeProto.valueOf, | ||
toUTCString: nativeProto.toUTCString, | ||
toGMTString: nativeProto.toGMTString || nativeProto.toUTCString, | ||
toLocaleString: nativeProto.toLocaleString, | ||
toLocaleDateString: nativeProto.toLocaleDateString, | ||
toLocaleTimeString: nativeProto.toLocaleTimeString | ||
}; | ||
protoMethods.getDate = function getDate() { | ||
return getLocalDate(this).getUTCDate(); | ||
}; | ||
protoMethods.getUTCDate = nativeProto.getUTCDate; | ||
protoMethods.setDate = function setDate(a0) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCDate.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCDate = nativeProto.setUTCDate; | ||
protoMethods.getDay = function getDay() { | ||
return getLocalDate(this).getUTCDay(); | ||
}; | ||
protoMethods.getUTCDay = nativeProto.getUTCDay; | ||
protoMethods.getFullYear = function getFullYear() { | ||
return getLocalDate(this).getUTCFullYear(); | ||
}; | ||
protoMethods.getUTCFullYear = nativeProto.getUTCFullYear; | ||
protoMethods.setFullYear = function setFullYear(a0, a1, a2) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCFullYear.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCFullYear = nativeProto.setUTCFullYear; | ||
protoMethods.getHours = function getHours() { | ||
return getLocalDate(this).getUTCHours(); | ||
}; | ||
protoMethods.getUTCHours = nativeProto.getUTCHours; | ||
protoMethods.setHours = function setHours(a0, a1, a2, a3) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCHours.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCHours = nativeProto.setUTCHours; | ||
protoMethods.getMilliseconds = function getMilliseconds() { | ||
return getLocalDate(this).getUTCMilliseconds(); | ||
}; | ||
protoMethods.getUTCMilliseconds = nativeProto.getUTCMilliseconds; | ||
protoMethods.setMilliseconds = function setMilliseconds(a0) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCMilliseconds.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCMilliseconds = nativeProto.setUTCMilliseconds; | ||
protoMethods.getMinutes = function getMinutes() { | ||
return getLocalDate(this).getUTCMinutes(); | ||
}; | ||
protoMethods.getUTCMinutes = nativeProto.getUTCMinutes; | ||
protoMethods.setMinutes = function setMinutes(a0, a1, a2) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCMinutes.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCMinutes = nativeProto.setUTCMinutes; | ||
protoMethods.getMonth = function getMonth() { | ||
return getLocalDate(this).getUTCMonth(); | ||
}; | ||
protoMethods.getUTCMonth = nativeProto.getUTCMonth; | ||
protoMethods.setMonth = function setMonth(a0, a1) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCMonth.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCMonth = nativeProto.setUTCMonth; | ||
protoMethods.getSeconds = function getSeconds() { | ||
return getLocalDate(this).getUTCSeconds(); | ||
}; | ||
protoMethods.getUTCSeconds = nativeProto.getUTCSeconds; | ||
protoMethods.setSeconds = function setSeconds(a0, a1) { | ||
var localDate = getLocalDate(this); | ||
nativeProto.setUTCSeconds.apply(localDate, arguments); | ||
return this.setTime(applyOffset(localDate, -this.offset())); | ||
}; | ||
protoMethods.setUTCSeconds = nativeProto.setUTCSeconds; | ||
var prototypePropertyDescriptors = makeMethodDescriptors(protoMethods); | ||
if (typeof Symbol !== 'undefined') { | ||
if (Symbol.toStringTag) { | ||
// Node v6+ or a polyfill | ||
prototypePropertyDescriptors[Symbol.toStringTag] = { value: 'Date' }; | ||
} | ||
if (Symbol.toPrimitive) { | ||
prototypePropertyDescriptors[Symbol.toPrimitive] = { | ||
value: nativeProto[Symbol.toPrimitive], | ||
configurable: true | ||
}; | ||
} | ||
} | ||
if (Symbol.toPrimitive) { | ||
prototypePropertyDescriptors[Symbol.toPrimitive] = { | ||
value: nativeProto[Symbol.toPrimitive], | ||
configurable: true | ||
}; | ||
Object.defineProperties(proto, prototypePropertyDescriptors); | ||
return constructor; | ||
} | ||
function isOffset(x) { | ||
if (x == null) { | ||
return false; | ||
} | ||
if (typeof x.valueOf === 'function') { | ||
x = x.valueOf(); | ||
} | ||
return typeof x === 'number'; | ||
} | ||
Object.defineProperties(proto, prototypePropertyDescriptors); | ||
return constructor; | ||
} | ||
function isOffset(x) { | ||
if (x == null) { | ||
return false; | ||
function applyOffset(date, offset) { | ||
date.setTime(date.getTime() + MILLISECONDS_PER_MINUTE * offset); | ||
return date; | ||
} | ||
if (typeof x.valueOf === 'function') { | ||
x = x.valueOf(); | ||
function getLocalDate(date) { | ||
return new NativeDate(date.getTime() + MILLISECONDS_PER_MINUTE * date.offset()); | ||
} | ||
return typeof x === 'number'; | ||
} | ||
function applyOffset(date, offset) { | ||
date.setTime(date.getTime() + MILLISECONDS_PER_MINUTE * offset); | ||
return date; | ||
} | ||
function getLocalDate(date) { | ||
return new NativeDate(date.getTime() + MILLISECONDS_PER_MINUTE * date.offset()); | ||
} | ||
function formatOffset(offset) { | ||
var sign = offset >= 0 ? '+' : '-', | ||
absOffsetInMinutes = Math.abs(offset), | ||
hours = Math.floor(absOffsetInMinutes / 60), | ||
minutes = absOffsetInMinutes - 60 * hours, | ||
tzName = ''; | ||
if (Object.prototype.hasOwnProperty.call(offset, 'toString')) { | ||
tzName = ' (' + offset.toString() + ')'; | ||
} else if (+offset === 0) { | ||
tzName = ' (UTC)'; | ||
function formatOffset(offset) { | ||
var sign = offset >= 0 ? '+' : '-', | ||
absOffsetInMinutes = Math.abs(offset), | ||
hours = Math.floor(absOffsetInMinutes / 60), | ||
minutes = absOffsetInMinutes - 60 * hours, | ||
tzName = ''; | ||
if (Object.prototype.hasOwnProperty.call(offset, 'toString')) { | ||
tzName = ' (' + offset.toString() + ')'; | ||
} else if (+offset === 0) { | ||
tzName = ' (UTC)'; | ||
} | ||
return 'GMT' + sign + addZero(hours) + addZero(minutes) + tzName; | ||
} | ||
return 'GMT' + sign + addZero(hours) + addZero(minutes) + tzName; | ||
} | ||
function setPrototypeOf(object, proto) { | ||
if (typeof Object.setPrototypeOf === 'function') { | ||
Object.setPrototypeOf(object, proto); | ||
} else { | ||
// Node 0.10.x | ||
object.__proto__ = proto; | ||
function setPrototypeOf(object, proto) { | ||
if (typeof Object.setPrototypeOf === 'function') { | ||
Object.setPrototypeOf(object, proto); | ||
} else { | ||
// Node 0.10.x | ||
object.__proto__ = proto; | ||
} | ||
} | ||
} | ||
function makeMethodDescriptors(methods) { | ||
var result = {}; | ||
for (var key in methods) { | ||
if (methods.hasOwnProperty(key)) { | ||
result[key] = { | ||
value: methods[key], | ||
writable: true, | ||
configurable: true | ||
}; | ||
function makeMethodDescriptors(methods) { | ||
var result = {}; | ||
for (var key in methods) { | ||
if (methods.hasOwnProperty(key)) { | ||
result[key] = { | ||
value: methods[key], | ||
writable: true, | ||
configurable: true | ||
}; | ||
} | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
function addZero(value) { | ||
return (value < 10 ? '0' : '') + value; | ||
} | ||
function padYear(year) { | ||
var length = ('' + year).length; | ||
return (length < 4 ? ' '.slice(0, 4 - length) : '') + year; | ||
} | ||
var TimezonedDate = makeConstructor(false); | ||
TimezonedDate.makeConstructor = makeConstructor; | ||
module.exports = TimezonedDate; | ||
function addZero(value) { | ||
return (value < 10 ? '0' : '') + value; | ||
} | ||
function padYear(year) { | ||
var length = ('' + year).length; | ||
return (length < 4 ? ' '.slice(0, 4 - length) : '') + year; | ||
} | ||
var TimezonedDate = makeConstructor(false); | ||
TimezonedDate.makeConstructor = makeConstructor; | ||
return TimezonedDate; | ||
}); |
{ | ||
"name": "timezoned-date", | ||
"version": "2.0.19", | ||
"version": "2.1.0", | ||
"license": "Apache-2.0", | ||
@@ -27,7 +27,7 @@ "description": "Work with timezone-aware dates", | ||
"devDependencies": { | ||
"babel-cli": "^6.5.2", | ||
"babel-eslint": "^6.0.4", | ||
"babel-preset-es2015": "^6.9.0", | ||
"eslint": "^2.10.2", | ||
"mocha": "~2.5.1", | ||
"babel-cli": "^6.16.0", | ||
"babel-eslint": "^7.0.0", | ||
"babel-preset-es2015": "^6.16.0", | ||
"eslint": "^3.8.0", | ||
"mocha": "~3.1.2", | ||
"sweet.js": "0.7.8", | ||
@@ -45,3 +45,3 @@ "test262-harness": "^1.5.6" | ||
"test262native": "test262-harness \"test262/test262/test/built-ins/Date/**/*.js\"", | ||
"prepublish": "npm run build && npm test", | ||
"prepublish": "npm run lint && npm run build && npm test", | ||
"build": "mkdir lib 2>nul & sjs -r -m ./src/macros.js src/index.js > ./lib/index.js && babel lib/index.js --out-file lib/index.js", | ||
@@ -48,0 +48,0 @@ "watch": "babel src/index.js --out-dir lib --watch" |
20705
297