Huge News!Announcing our $40M Series B led by Abstract Ventures.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.6 to 0.4.7

2

package.json

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

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

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

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

describe('timezoneJS.Date', function () {
it('should correctly trim dates when date exceeds format length', function () {
var date = new timezoneJS.Date(2011, 10, 22);
expect(date.toString('yy-MM-dd')).toEqual('11-11-22')
});
it('should correctly pad dates when date is shorter than the format length', function () {
var date = new timezoneJS.Date(2011, 3, 2);
expect(date.toString('yyyy-MM-dd')).toEqual('2011-04-02')
});
it('should have correct format when initialized', function () {

@@ -48,2 +58,7 @@ var date = new timezoneJS.Date();

it('should format the Unix Epoch UTC to different formats and tz correctly', function () {
var date = new timezoneJS.Date(1970,0,1,0,0,0,0,'Etc/UTC');
expect(date.toString('MMM dd yyyy HH:mm:ss k Z', 'Europe/Kaliningrad')).toEqual('Jan 01 1970 03:00:00 AM MSK');
});
it('should use a default format with the given tz', function () {

@@ -518,2 +533,22 @@ var date = new timezoneJS.Date(2012, 7, 30, 10, 56, 0, 0, 'America/Los_Angeles');

});
it('should throw an exception when initialized without "new"', function () {
var init = function() {
var date = timezoneJS.Date();
};
expect(init).toThrow();
});
it('should throw an exception when initialized with another Date when missing "new"', function () {
var d = new timezoneJS.Date();
var init = function() {
var k = timezoneJS.Date(d);
};
expect(init).toThrow();
});
it('should take in year and month as constructor correctly', function () {
var d = new timezoneJS.Date( 2011, 8, "Etc/UTC");
expect( d.getMonth()).toEqual(8);
});
});

@@ -43,7 +43,11 @@ // -----

var timezoneJS;
// Export the timezoneJS object for Node.js, with backwards-compatibility for the old `require()` API
var timezoneJS = {};
if (typeof exports !== 'undefined') {
timezoneJS = exports;
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = timezoneJS;
}
exports.timezoneJS = timezoneJS;
} else {
timezoneJS = root.timezoneJS = {};
root.timezoneJS = timezoneJS;
}

@@ -64,4 +68,3 @@

, SHORT_DAYS = {}
, EXACT_DATE_TIME = {}
, TZ_REGEXP = new RegExp('^[a-zA-Z]+/');
, EXACT_DATE_TIME = {};

@@ -116,3 +119,5 @@ //`{ "Jan": 0, "Feb": 1, "Mar": 2, "Apr": 3, "May": 4, "Jun": 5, "Jul": 6, "Aug": 7, "Sep": 8, "Oct": 9, "Nov": 10, "Dec": 11 }`

//
// `_fixWidth(1998, 2) = '98'`
// `_fixWidth(1998, 2) = '98'` // year, shorten it to the 2 digit representation
//
// `_fixWidth(23, 1) = '23'` // hour, even with 1 digit specified, do not trim
//

@@ -122,10 +127,14 @@ // This is used to pad numbers in converting date to string in ISO standard.

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
var s = number.toString();
if (number.length > digits) {
return number.substr(number.length - digits, number.length);
var s_len = s.length;
if (trim && s_len > digits) {
return s.substr(s_len - digits, s_len);
}
while (s.length < digits) {
s = '0' + s;
s = [s];
while (s_len < digits) {
s.unshift('0');
s_len++;
}
return s;
return s.join('');
};

@@ -175,6 +184,11 @@

timezoneJS.Date = function () {
if(this === timezoneJS) {
throw "timezoneJS.Date object must be constructed with 'new'";
}
var args = Array.prototype.slice.apply(arguments)
, dt = null
, tz = null
, arr = [];
, arr = []
, valid = false
;

@@ -200,4 +214,8 @@

}
if (typeof args[args.length - 1] === 'string' && TZ_REGEXP.test(args[args.length - 1])) {
tz = args.pop();
// If the last string argument doesn't parse as a Date, treat it as tz
if (typeof args[args.length - 1] === 'string') {
valid = Date.parse(args[args.length - 1].replace(/GMT\+\d+/, ''));
if (isNaN(valid) || valid === null) { // Checking against null is required for compatability with Datejs
tz = args.pop();
}
}

@@ -218,2 +236,6 @@ var is_dt_local = false;

break;
case 2:
dt = new Date(args[0], args[1]);
is_dt_local = true;
break;
default:

@@ -252,3 +274,3 @@ for (var i = 0; i < 7; i++) {

// `dt_str_tz` is a date string containing timezone information, i.e. containing 'Z', 'T' or
// /[+-][0-9]{4}/ (e.g. '+0200'), while `dt_str` is a string which does not contain
// /[+-][0-9]{4}/ (e.g. '+0200'), while `dt_str` is a string which does not contain
// timezone information. See: http://dygraphs.com/date-formats.html

@@ -537,3 +559,3 @@ if (is_dt_local) {

, regionMap = {'Etc':'etcetera','EST':'northamerica','MST':'northamerica','HST':'northamerica','EST5EDT':'northamerica','CST6CDT':'northamerica','MST7MDT':'northamerica','PST8PDT':'northamerica','America':'northamerica','Pacific':'australasia','Atlantic':'europe','Africa':'africa','Indian':'africa','Antarctica':'antarctica','Asia':'asia','Australia':'australasia','Europe':'europe','WET':'europe','CET':'europe','MET':'europe','EET':'europe'}
, 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/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'};
, 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.'); }

@@ -848,3 +870,3 @@ function builtInLoadZoneFile(fileName, opts) {

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

@@ -851,0 +873,0 @@ return base;

@@ -5,3 +5,3 @@ (function () {

, timezoneJS = require('./date')
, EXCLUDED = new RegExp('Makefile|factory|(\\.+)', 'i');
, EXCLUDED = new RegExp('README|Makefile|factory|(\\.+)', 'i');

@@ -52,3 +52,8 @@ function parse(args) {

}
console.log(JSON.stringify(result));
console.log(JSON.stringify(result, function(key, value) {
if (typeof(value) == "number") {
return value.toString()
}
return value
}));
}

@@ -55,0 +60,0 @@

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