Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timezone-js-ts

Package Overview
Dependencies
Maintainers
0
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timezone-js-ts - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

dist/timezoneConverterOutputs.json

10

dist/index.d.ts

@@ -1,9 +0,3 @@

export declare function getCurrentGlobalTime(timezone: string, localeIdentifier?: string): string;
export declare function timezoneConverter(timezone: string): {
res: string;
diff: {
difference: any;
yourLocalTimezone: string;
};
};
export declare function getDestinationTime(timezone: string, localeIdentifier?: string): string;
export declare function timezoneConverter(IANA_timezone_destination: string, IANA_timezone_source?: string): any;
export declare function allTimezones(): {

@@ -10,0 +4,0 @@ id: number;

50

dist/index.js

@@ -36,3 +36,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurrentGlobalTime = getCurrentGlobalTime;
exports.getDestinationTime = getDestinationTime;
exports.timezoneConverter = timezoneConverter;

@@ -49,2 +49,4 @@ exports.allTimezones = allTimezones;

const zoneData = __importStar(require("./countries-with-timezone.json"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
// ---------------------------------------------------------

@@ -67,2 +69,3 @@ // ------------------------- Helpers ----------------------

];
const sourceTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
function timeNowIs(timezone) {

@@ -73,3 +76,3 @@ const date = new Date();

dateStyle: 'full',
timeStyle: 'long'
timeStyle: 'full'
};

@@ -84,7 +87,8 @@ return new Intl.DateTimeFormat('en-GB', configOptions).formatToParts(date);

}
function getTimeDiff(timezone) {
function getTimeDiff(IANA_timezone_destination, IANA_timezone_source) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
IANA_timezone_source = IANA_timezone_source ? IANA_timezone_source : sourceTimeZone;
let timeDiff;
const currTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const destTime = timeNowIs(timezone);
// const currTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const destTime = timeNowIs(IANA_timezone_destination);
let destHour = (_a = destTime.find(h => h.type == 'hour')) === null || _a === void 0 ? void 0 : _a.value;

@@ -96,3 +100,3 @@ let destMinute = (_b = destTime.find(h => h.type == 'minute')) === null || _b === void 0 ? void 0 : _b.value;

const destYear = (_f = destTime.find(h => h.type == 'year')) === null || _f === void 0 ? void 0 : _f.value;
const currTime = timeNowIs(currTimeZone);
const currTime = timeNowIs(IANA_timezone_source);
let currHour = (_g = currTime.find(h => h.type == 'hour')) === null || _g === void 0 ? void 0 : _g.value;

@@ -134,3 +138,3 @@ let currMinute = (_h = currTime.find(h => h.type == 'minute')) === null || _h === void 0 ? void 0 : _h.value;

}
return { difference: timeDiff, yourLocalTimezone: currTimeZone };
return { offset_from_utc: timeDiff, iana_timezone_of_source: IANA_timezone_source, iana_timezone_of_destination: IANA_timezone_destination };
}

@@ -140,3 +144,3 @@ // ---------------------------------------------------------

// ---------------------------------------------------------
function getCurrentGlobalTime(timezone, localeIdentifier) {
function getDestinationTime(timezone, localeIdentifier) {
const date = new Date();

@@ -159,6 +163,28 @@ const configOptions = {

}
function timezoneConverter(timezone) {
const res = getCurrentGlobalTime(timezone);
const diff = getTimeDiff(timezone);
return { res, diff };
function timezoneConverter(IANA_timezone_destination, IANA_timezone_source) {
IANA_timezone_source = IANA_timezone_source ? IANA_timezone_source : sourceTimeZone;
const currentTime_Dest = getDestinationTime(IANA_timezone_destination);
const diff = getTimeDiff(IANA_timezone_destination, IANA_timezone_source);
const actualPath = path.resolve(__dirname, './timezoneConverterOutputs.json');
let fileData = [];
// fetch old data if exists
if (fs.existsSync(actualPath)) {
const content = fs.readFileSync(actualPath, 'utf8');
fileData = JSON.parse(content)[0].data;
}
// append new data
fileData.push({ id: fileData.length + 1, currentTime_Dest, diff });
let obj = [
{
"data": fileData
}
];
// write data into json file
fs.writeFile(actualPath, JSON.stringify(obj, null, " "), 'utf-8', err => {
if (err)
throw err;
});
// return this json file as a output
return obj[0].data;
// return { currentTime_Dest, diff };
}

@@ -165,0 +191,0 @@ function allTimezones() {

{
"name": "timezone-js-ts",
"version": "3.1.0",
"version": "3.1.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

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