timezoned-date
Advanced tools
Comparing version 2.0.12 to 2.0.13
@@ -1,6 +0,8 @@ | ||
/*jshint esversion: 6*/ | ||
/*jshint esversion: 6, evil: true*/ | ||
'use strict'; | ||
var MILLISECONDS_PER_MINUTE = 60 * 1000, | ||
YYYY_MM_DD = /^\d\d\d\d(-\d\d){0,2}/, | ||
// Such strings are parsed as UTC. See http://dygraphs.com/date-formats.html | ||
YYYY_MM_DD = /^\d\d\d\d(-\d\d){0,2}$/, | ||
OFFSET_SUFFIX = /(((GMT)?[\+\-]\d\d:?\d\d)|Z)(\s*\(.+\))?$/, | ||
@@ -26,10 +28,10 @@ daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
function TimezonedDate(_a1, _a2, _a3, _a4, _a5, _a6, _a7) { | ||
if (!(this instanceof TimezonedDate)) { | ||
var constructor = function Date(_a1, _a2, _a3, _a4, _a5, _a6, _a7) { | ||
if (!(this instanceof constructor)) { | ||
// When Date() is called without new, it ignores its arguments and | ||
// returns same as new Date().toString() | ||
if (bound) { | ||
return new TimezonedDate().toString(); | ||
return new constructor().toString(); | ||
} | ||
return new TimezonedDate(_a1).toString(); | ||
return new constructor(_a1).toString(); | ||
} | ||
@@ -41,3 +43,4 @@ var args = Array.prototype.slice.call(arguments); | ||
} | ||
var instance = new (Function.prototype.bind.apply(NativeDate, [null].concat(args)))(); | ||
var boundNativeConstructor = Function.prototype.bind.apply(NativeDate, [null].concat(args)); | ||
var instance = new boundNativeConstructor(); | ||
Object.setPrototypeOf(instance, proto); | ||
@@ -48,3 +51,3 @@ instance.offset = function () { | ||
var inited = args.length === 0 || args.length === 1 && args[0] instanceof NativeDate || args.length === 1 && (typeof args[0] === 'number' || typeof args[0] === 'boolean') || args.length > 1 && isNaN(instance.getDate()); | ||
var inited = args[0] === undefined || args[0] === null && args.length === 1 || args.length === 1 && args[0] instanceof NativeDate || args.length === 1 && (typeof args[0] === 'number' || typeof args[0] === 'boolean') || args.length > 1 && isNaN(instance.getDate()); | ||
@@ -75,5 +78,5 @@ if (!inited && args.length > 1) { | ||
return instance; | ||
} | ||
}; | ||
Object.setPrototypeOf(TimezonedDate, Date); | ||
Object.setPrototypeOf(constructor, Date); | ||
@@ -91,9 +94,9 @@ var constructorPropertyDescriptors = makeMethodDescriptors({ | ||
Object.defineProperties(TimezonedDate, constructorPropertyDescriptors); | ||
Object.defineProperties(constructor, constructorPropertyDescriptors); | ||
var protoMethods = { | ||
constructor: TimezonedDate, | ||
constructor: constructor, | ||
withOffset: function withOffset(offset) { | ||
return new ExportedTimezonedDate(this.getTime(), offset); | ||
return new TimezonedDate(this.getTime(), offset); | ||
}, | ||
@@ -163,3 +166,3 @@ getTimezoneOffset: function getTimezoneOffset() { | ||
protoMethods[setterName] = createFunction(function () { | ||
if (!(this instanceof TimezonedDate)) { | ||
if (!(this instanceof constructor)) { | ||
throw new TypeError(); | ||
@@ -207,3 +210,3 @@ } | ||
return TimezonedDate; | ||
return constructor; | ||
} | ||
@@ -232,8 +235,14 @@ | ||
function formatOffset(offsetInMinutes) { | ||
var sign = offsetInMinutes >= 0 ? '+' : '-'; | ||
offsetInMinutes = Math.abs(offsetInMinutes); | ||
var hours = Math.floor(offsetInMinutes / 60), | ||
minutes = offsetInMinutes - 60 * hours; | ||
return 'GMT' + sign + addZero(hours) + addZero(minutes); | ||
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; | ||
} | ||
@@ -272,4 +281,4 @@ | ||
var ExportedTimezonedDate = makeConstructor(false); | ||
ExportedTimezonedDate.makeConstructor = makeConstructor; | ||
module.exports = ExportedTimezonedDate; | ||
var TimezonedDate = makeConstructor(false); | ||
TimezonedDate.makeConstructor = makeConstructor; | ||
module.exports = TimezonedDate; |
{ | ||
"name": "timezoned-date", | ||
"version": "2.0.12", | ||
"version": "2.0.13", | ||
"license": "Apache-2.0", | ||
@@ -34,3 +34,3 @@ "description": "Work with timezone-aware dates", | ||
"lint": "eslint src --fix || true", | ||
"test": "mocha", | ||
"test": "mocha --timeout 5000", | ||
"pretest262": "find test262/test262 -maxdepth 0 || git clone https://github.com/tc39/test262.git test262/test262 --depth 1", | ||
@@ -37,0 +37,0 @@ "test262": "cat test262/prelude.prefix lib/index.js test262/prelude.suffix > test262/prelude.js && test262-harness --prelude test262/prelude.js \"test262/test262/test/built-ins/Date/**/*.js\"", |
@@ -25,2 +25,4 @@ # Timezoned Date | ||
[](https://travis-ci.org/thorn0/timezoned-date) | ||
Known issues: | ||
@@ -27,0 +29,0 @@ |
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
180
0
16963
5
236