New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

timezone-js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timezone-js - npm Package Compare versions

Comparing version 0.4.9 to 0.4.10

2

package.json

@@ -13,3 +13,3 @@ {

"description": "JavaScript timezone library based on Olson timezone data",
"version": "0.4.9",
"version": "0.4.10",
"main": "src/date.js",

@@ -16,0 +16,0 @@ "homepage": "https://github.com/mde/timezone-js",

@@ -245,13 +245,2 @@ var TestUtils = require('./test-utils')

it('should convert timezone quickly', function () {
var start = Date.now()
, yearToMillis = 5 * 365 * 24 * 3600 * 1000
, date;
for (var i = 0; i < 5000; i++) {
date = new timezoneJS.Date(start - Math.random() * yearToMillis, 'America/New_York');
date.setTimezone('Europe/Minsk');
}
console.log('Took ' + (Date.now() - start) + 'ms to convert 5000 dates');
});
it('should output 1955-10-30 00:00:00 America/New_York as EDT', function () {

@@ -577,2 +566,6 @@ var dt = new timezoneJS.Date(1955, 9, 30, 0, 0, 0, 'America/New_York');

});
it('should return timezoneOffset as number', function () {
expect(new timezoneJS.Date(2014, 1, 1, 2, 0, 0, 0, 'Asia/Kolkata').getTimezoneOffset()).toEqual(-330);
});
});

@@ -21,14 +21,2 @@ var fs = require('fs');

timezoneJS.timezone.transport = function (opts) {
// No success handler, what's the point?
if (opts.async) {
if (typeof opts.success !== 'function') return;
opts.error = opts.error || console.error;
return fs.readFile(opts.url, 'utf8', function (err, data) {
return err ? opts.error(err) : opts.success(data);
});
}
return fs.readFileSync(opts.url, 'utf8');
};
timezoneJS.timezone.loadingScheme = opts.loadingScheme;

@@ -35,0 +23,0 @@ timezoneJS.timezone.defaultZoneFile = opts.defaultZoneFile;

@@ -166,10 +166,2 @@ var TestUtils = require('./test-utils')

it('should get tzInfo quickly', function () {
var time = Date.now();
for (var i = 0; i < 5000; i++) {
timezoneJS.timezone.getTzInfo(new Date(), 'America/Chicago');
}
console.log('Took ' + (Date.now() - time) + 'ms to get 5000 same tzInfo');
});
it('should throw error with invalid zone', function () {

@@ -179,5 +171,5 @@ var testFn = function () {

}
expect(testFn).toThrow(new Error('Timezone "asd" is either incorrect, or not loaded in the timezone registry.'));
expect(testFn).toThrow(new Error('Timezone \'asd\' is either incorrect, or not loaded in the timezone registry.'));
});
});

@@ -12,3 +12,3 @@ // -----

*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.

@@ -20,3 +20,3 @@ * You may obtain a copy of the License at

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

@@ -27,3 +27,3 @@ * See the License for the specific language governing permissions and

* Credits: Ideas included from incomplete JS implementation of Olson
* parser, "XMLDAte" by Philippe Goetz (philippe.goetz@wanadoo.fr)
* parser, 'XMLDAte' by Philippe Goetz (philippe.goetz@wanadoo.fr)
*

@@ -39,7 +39,7 @@ * Contributions:

/*jslint laxcomma:true, laxbreak:true, expr:true*/
/*jshint laxcomma:true, laxbreak:true, expr:true*/
(function () {
// Standard initialization stuff to make sure the library is
// usable on both client and server (node) side.
"use strict";
'use strict';
var root = this;

@@ -49,3 +49,7 @@

var timezoneJS = {};
if (typeof exports !== 'undefined') {
if (typeof define === 'function' && define.amd) { // AMD
define(function() {
return timezoneJS;
});
} else if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {

@@ -59,3 +63,3 @@ exports = module.exports = timezoneJS;

timezoneJS.VERSION = '0.4.4';
timezoneJS.VERSION = '0.4.10';

@@ -75,3 +79,3 @@ // Grab the ajax library from global context.

//`{ "Jan": 0, "Feb": 1, "Mar": 2, "Apr": 3, "May": 4, "Jun": 5, "Jul": 6, "Aug": 7, "Sep": 8, "Oct": 9, "Nov": 10, "Dec": 11 }`
//`{ 'Jan': 0, 'Feb': 1, 'Mar': 2, 'Apr': 3, 'May': 4, 'Jun': 5, 'Jul': 6, 'Aug': 7, 'Sep': 8, 'Oct': 9, 'Nov': 10, 'Dec': 11 }`
for (var i = 0; i < MONTHS.length; i++) {

@@ -81,3 +85,3 @@ SHORT_MONTHS[MONTHS[i].substr(0, 3)] = i;

//`{ "Sun": 0, "Mon": 1, "Tue": 2, "Wed": 3, "Thu": 4, "Fri": 5, "Sat": 6 }`
//`{ 'Sun': 0, 'Mon': 1, 'Tue': 2, 'Wed': 3, 'Thu': 4, 'Fri': 5, 'Sat': 6 }`
for (i = 0; i < DAYS.length; i++) {

@@ -131,3 +135,3 @@ SHORT_DAYS[DAYS[i].substr(0, 3)] = i;

var _fixWidth = function (number, digits) {
if (typeof number !== "number") { throw "not a number: " + number; }
if (typeof number !== 'number') { throw 'not a number: ' + number; }
var trim = (number > 1000); // only trim 'year', as the others don't make sense why anyone would want that

@@ -147,3 +151,3 @@ var s = number.toString();

// Abstraction layer for different transport layers, including fleegix/jQuery/Zepto
// Abstraction layer for different transport layers, including fleegix/jQuery/Zepto/Node.js
//

@@ -161,8 +165,25 @@ // Object `opts` include

var _transport = function (opts) {
if (!opts) return;
if (!opts.url) throw new Error ('URL must be specified');
if (!('async' in opts)) opts.async = true;
// Server-side (node)
// if node, require the file system module
if (typeof window === 'undefined' && typeof require === 'function') {
var nodefs = require('fs');
if (opts.async) {
// No point if there's no success handler
if (typeof opts.success !== 'function') return;
opts.error = opts.error || console.error;
return nodefs.readFile(opts.url, 'utf8', function(err, data) {
return err ? opts.error(err) : opts.success(data);
});
}
return nodefs.readFileSync(opts.url, 'utf8');
}
// Client-side
if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!ajax_lib || typeof ajax_lib.ajax === 'undefined')) {
throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.');
}
if (!opts) return;
if (!opts.url) throw new Error ('URL must be specified');
if (!('async' in opts)) opts.async = true;
if (!opts.async) {

@@ -192,3 +213,3 @@ return fleegix && fleegix.xhr

if(this === timezoneJS) {
throw "timezoneJS.Date object must be constructed with 'new'";
throw 'timezoneJS.Date object must be constructed with \'new\'';
}

@@ -223,3 +244,3 @@ var args = Array.prototype.slice.apply(arguments)

if (typeof args[args.length - 1] === 'string') {
valid = Date.parse(args[args.length - 1].replace(/GMT[\+\-]\d+/, ''));
valid = Date.parse(args[args.length - 1].replace(/GMT[\+\-]\d+/, ''));
if (isNaN(valid) || valid === null) { // Checking against null is required for compatability with Datejs

@@ -567,3 +588,3 @@ tz = args.pop();

, regionExceptions = {'Pacific/Honolulu':'northamerica','Atlantic/Bermuda':'northamerica','Atlantic/Cape_Verde':'africa','Atlantic/St_Helena':'africa','Indian/Kerguelen':'antarctica','Indian/Chagos':'asia','Indian/Maldives':'asia','Indian/Christmas':'australasia','Indian/Cocos':'australasia','America/Danmarkshavn':'europe','America/Scoresbysund':'europe','America/Godthab':'europe','America/Thule':'europe','Asia/Istanbul':'europe','Asia/Yekaterinburg':'europe','Asia/Omsk':'europe','Asia/Novosibirsk':'europe','Asia/Krasnoyarsk':'europe','Asia/Irkutsk':'europe','Asia/Yakutsk':'europe','Asia/Vladivostok':'europe','Asia/Sakhalin':'europe','Asia/Magadan':'europe','Asia/Kamchatka':'europe','Asia/Anadyr':'europe','Africa/Ceuta':'europe','America/Argentina/Buenos_Aires':'southamerica','America/Argentina/Salta':'southamerica','America/Argentina/San_Luis':'southamerica','America/Argentina/Cordoba':'southamerica','America/Argentina/Tucuman':'southamerica','America/Argentina/La_Rioja':'southamerica','America/Argentina/San_Juan':'southamerica','America/Argentina/Jujuy':'southamerica','America/Argentina/Catamarca':'southamerica','America/Argentina/Mendoza':'southamerica','America/Argentina/Rio_Gallegos':'southamerica','America/Argentina/Ushuaia':'southamerica','America/Aruba':'southamerica','America/La_Paz':'southamerica','America/Noronha':'southamerica','America/Belem':'southamerica','America/Fortaleza':'southamerica','America/Recife':'southamerica','America/Araguaina':'southamerica','America/Maceio':'southamerica','America/Bahia':'southamerica','America/Sao_Paulo':'southamerica','America/Campo_Grande':'southamerica','America/Cuiaba':'southamerica','America/Porto_Velho':'southamerica','America/Boa_Vista':'southamerica','America/Manaus':'southamerica','America/Eirunepe':'southamerica','America/Rio_Branco':'southamerica','America/Santiago':'southamerica','Pacific/Easter':'southamerica','America/Bogota':'southamerica','America/Curacao':'southamerica','America/Guayaquil':'southamerica','Pacific/Galapagos':'southamerica','Atlantic/Stanley':'southamerica','America/Cayenne':'southamerica','America/Guyana':'southamerica','America/Asuncion':'southamerica','America/Lima':'southamerica','Atlantic/South_Georgia':'southamerica','America/Paramaribo':'southamerica','America/Port_of_Spain':'southamerica','America/Montevideo':'southamerica','America/Caracas':'southamerica','GMT':'etcetera','Europe/Nicosia':'asia'};
function invalidTZError(t) { throw new Error('Timezone "' + t + '" is either incorrect, or not loaded in the timezone registry.'); }
function invalidTZError(t) { throw new Error('Timezone \'' + t + '\' is either incorrect, or not loaded in the timezone registry.'); }
function builtInLoadZoneFile(fileName, opts) {

@@ -580,3 +601,3 @@ var url = _this.zoneFileBasePath + '/' + fileName;

error : function () {
throw new Error('Error retrieving "' + url + '" zoneinfo files');
throw new Error('Error retrieving \'' + url + '\' zoneinfo files');
}

@@ -600,3 +621,3 @@ });

if (!_this.loadedZones.backward) {
// This is for obvious legacy zones (e.g., Iceland) that don't even have a prefix like "America/" that look like normal zones
// This is for obvious legacy zones (e.g., Iceland) that don't even have a prefix like 'America/' that look like normal zones
_this.loadZoneFile('backward');

@@ -635,3 +656,3 @@ return getRegionForTimezone(tz);

// Follow links to get to an actual zone
while (typeof zoneList === "string") {
while (typeof zoneList === 'string') {
t = zoneList;

@@ -643,3 +664,3 @@ zoneList = _this.zones[t];

if (!_this.loadedZones.backward) {
//This is for backward entries like "America/Fort_Wayne" that
//This is for backward entries like 'America/Fort_Wayne' that
// getRegionForTimezone *thinks* it has a region file and zone

@@ -654,3 +675,3 @@ // for (e.g., America => 'northamerica'), but in reality it's a

if (zoneList.length === 0) {
throw new Error('No Zone found for "' + tz + '" on ' + dt);
throw new Error('No Zone found for \'' + tz + '\' on ' + dt);
}

@@ -708,3 +729,3 @@ //Do backwards lookup since most use cases deal with newer dates.

} else {
throw new Error("unknown type " + type);
throw new Error('unknown type ' + type);
}

@@ -754,7 +775,7 @@ offset *= 60 * 1000; // to millis

//Example: `lastThu`
if (rule[4].substr(0, 4) === "last") {
if (rule[4].substr(0, 4) === 'last') {
// Start at the last day of the month and work backward.
effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]] + 1, 1, hms[0] - 24, hms[1], hms[2], 0));
targetDay = SHORT_DAYS[rule[4].substr(4, 3)];
operator = "<=";
operator = '<=';
}

@@ -770,6 +791,6 @@ //Example: `Sun>=15`

//Go forwards.
if (operator === ">=") {
if (operator === '>=') {
effectiveDate.setUTCDate(effectiveDate.getUTCDate() + (targetDay - ourDay + ((targetDay < ourDay) ? 7 : 0)));
}
//Go backwards. Looking for the last of a certain day, or operator is "<=" (less likely).
//Go backwards. Looking for the last of a certain day, or operator is '<=' (less likely).
else {

@@ -799,6 +820,6 @@ effectiveDate.setUTCDate(effectiveDate.getUTCDate() + (targetDay - ourDay - ((targetDay > ourDay) ? 7 : 0)));

ruleset[i][1] >= year ||
// Date is in an "only" year.
(ruleset[i][0] === year && ruleset[i][1] === "only") ||
// Date is in an 'only' year.
(ruleset[i][0] === year && ruleset[i][1] === 'only') ||
//We're in a range from the start year to infinity.
ruleset[i][1] === "max"
ruleset[i][1] === 'max'
)

@@ -886,3 +907,3 @@ ) {

//Chose one of two alternative strings.
return base.split("/", 2)[rule ? (rule[6] ? 1 : 0) : 0];
return base.split('/', 2)[rule ? (rule[6] ? 1 : 0) : 0];
}

@@ -983,5 +1004,5 @@ return base;

if (l.match(/^\s/)) {
l = "Zone " + zone + l;
l = 'Zone ' + zone + l;
}
l = l.split("#")[0];
l = l.split('#')[0];
if (l.length > 3) {

@@ -1024,3 +1045,3 @@ arr = l.split(/\s+/);

//Create the link.
_this.zones[arr[1]] = arr[0];
_this.zones[arr[1]] = +arr[0];
break;

@@ -1057,3 +1078,3 @@ }

};
};
}();
}).call(this);

Sorry, the diff of this file is not supported yet

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