timezone-js-ts
Advanced tools
Comparing version 3.2.1 to 3.2.2
@@ -6,5 +6,8 @@ export declare function getDestinationTime(timezone: string, localeIdentifier?: string): string; | ||
diff: { | ||
abbreviation_of_zone: any; | ||
standardized_timezone_name: string; | ||
offset_from_utc: any; | ||
iana_timezone_of_source: string; | ||
"iana_timezone_of_source(local)": string; | ||
iana_timezone_of_destination: string; | ||
"daylight name": string; | ||
}; | ||
@@ -11,0 +14,0 @@ }[]; |
@@ -68,3 +68,4 @@ "use strict"; | ||
const sourceTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
function timeNowIs(timezone) { | ||
function timeNowIs(timezone, timestyle) { | ||
timestyle = timestyle ? timestyle : 'full'; | ||
const date = new Date(); | ||
@@ -74,8 +75,9 @@ const configOptions = { | ||
dateStyle: 'full', | ||
timeStyle: 'full' | ||
timeStyle: timestyle | ||
}; | ||
return new Intl.DateTimeFormat('en-GB', configOptions).formatToParts(date); | ||
} | ||
function getTimezoneName(data) { | ||
const dateObj = timeNowIs(data); | ||
function getTimezoneName(data, timestyle) { | ||
timestyle = timestyle ? timestyle : 'full'; | ||
const dateObj = timeNowIs(data, timestyle); | ||
const findTz = dateObj.find(z => z.type === 'timeZoneName'); | ||
@@ -136,3 +138,14 @@ var tzStr = findTz.value; | ||
} | ||
return { offset_from_utc: timeDiff, iana_timezone_of_source: IANA_timezone_source, iana_timezone_of_destination: IANA_timezone_destination }; | ||
// return { offset_from_utc: timeDiff, iana_timezone_of_source: IANA_timezone_source, iana_timezone_of_destination: IANA_timezone_destination }; | ||
const searchOffsets = ['UTC', 'GMT']; | ||
let standardizedTZ = getTimezoneName(IANA_timezone_destination, 'long'); | ||
standardizedTZ = searchOffsets.some(val => standardizedTZ.includes(val)) ? standardizedTZ : 'No UTC/GMT offset'; | ||
return { | ||
"abbreviation_of_zone": getTimezoneName(IANA_timezone_destination), | ||
"standardized_timezone_name": standardizedTZ, // e.g., GMT+5:30 or UTC-10:30 | ||
"offset_from_utc": timeDiff, // how many hours behind (or) ahead | ||
"iana_timezone_of_source(local)": IANA_timezone_source, //e.g., America/Los_Angeles | ||
"iana_timezone_of_destination": IANA_timezone_destination, | ||
"daylight name": "" | ||
}; | ||
} | ||
@@ -139,0 +152,0 @@ // --------------------------------------------------------- |
{ | ||
"name": "timezone-js-ts", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
11590011
10950