timezone-js-ts
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -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; |
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11590664
11
10978
3