windows-iana
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -11,2 +11,3 @@ import { findAlias, findIana, findOneIana, findWindows, getAllIanaWindowsMap } from "../src"; | ||
expect(findOneIana(WindowsZoneName.ChinaStandardTime)).toBe("Asia/Shanghai"); | ||
expect(findOneIana("China Standard Time")).toBe("Asia/Shanghai"); | ||
}); | ||
@@ -20,2 +21,3 @@ | ||
expect(findOneIana(WindowsZoneName.ChinaStandardTime, Territory.Hk)).toBe("Asia/Hong_Kong"); | ||
expect(findOneIana("China Standard Time", "HK")).toBe("Asia/Hong_Kong"); | ||
}); | ||
@@ -29,2 +31,3 @@ | ||
expect(findOneIana(WindowsZoneName.UsMountainStandardTime, "fake" as any)).toBeUndefined(); | ||
expect(findOneIana("US Mountain Standard Time", "fake" as any)).toBeUndefined(); | ||
}); | ||
@@ -48,2 +51,3 @@ }); | ||
]); | ||
expect(findIana("Central Standard Time")).toEqual(["America/Chicago", "US/Central"]); | ||
}); | ||
@@ -72,2 +76,3 @@ | ||
expect(findIana(WindowsZoneName.ChinaStandardTime, Territory.Hk)).toEqual(["Asia/Hong_Kong", "Hongkong"]); | ||
expect(findIana("China Standard Time", "HK")).toEqual(["Asia/Hong_Kong", "Hongkong"]); | ||
}); | ||
@@ -81,2 +86,3 @@ | ||
expect(findIana(WindowsZoneName.UsMountainStandardTime, "fake" as any)).toBeUndefined(); | ||
expect(findIana("US Mountain Standard Time", "fake" as any)).toBeUndefined(); | ||
}); | ||
@@ -93,2 +99,3 @@ }); | ||
expect(findWindows(IanaName.AsiaKolkata)).toEqual("India Standard Time"); | ||
expect(findWindows("Asia/Kolkata")).toEqual("India Standard Time"); | ||
}); | ||
@@ -105,2 +112,3 @@ test("returns `undefined` if the Iana timezone cannot be converted", () => { | ||
expect(findAlias(IanaName.AsiaSaigon)).toEqual(["Asia/Saigon", "Asia/Ho_Chi_Minh"]); | ||
expect(findAlias("Asia/Saigon")).toEqual(["Asia/Saigon", "Asia/Ho_Chi_Minh"]); | ||
}); | ||
@@ -107,0 +115,0 @@ test("returns `undefined` if the Iana timezone cannot be converted", () => { |
@@ -1,6 +0,6 @@ | ||
import { IanaName, Territory, WindowsZoneName } from "./enums"; | ||
export declare const findIana: (windowsTimeZone: WindowsZoneName, territory?: Territory) => IanaName[] | undefined; | ||
export declare const findOneIana: (windowsTimeZone: WindowsZoneName, territory?: Territory) => IanaName | undefined; | ||
export declare const findWindows: (ianaTimeZone: IanaName) => WindowsZoneName | undefined; | ||
export declare const findAlias: (ianaTimeZone: IanaName) => IanaName[] | undefined; | ||
import { IanaName, WindowsZoneName } from "./enums"; | ||
export declare const findIana: (windowsTimeZone: string, territory?: string) => IanaName[] | undefined; | ||
export declare const findOneIana: (windowsTimeZone: string, territory?: string) => IanaName | undefined; | ||
export declare const findWindows: (ianaTimeZone: string) => WindowsZoneName | undefined; | ||
export declare const findAlias: (ianaTimeZone: string) => IanaName[] | undefined; | ||
export declare const getAllIanaWindowsMap: () => Map<IanaName, WindowsZoneName>; |
@@ -8,5 +8,7 @@ "use strict"; | ||
if (territory === void 0) { territory = enums_1.Territory["001"]; } | ||
var windowsZoneNameEnum = windowsTimeZone; | ||
var territoryEnum = territory; | ||
var entry = time_zone_map_1.map.find(function (_a) { | ||
var itemName = _a.windowsName, itemTerritory = _a.territory; | ||
return itemName === windowsTimeZone && itemTerritory === territory; | ||
return itemName === windowsZoneNameEnum && itemTerritory === territoryEnum; | ||
}); | ||
@@ -48,5 +50,6 @@ if (typeof entry === "undefined") | ||
exports.findAlias = function (ianaTimeZone) { | ||
var ianaNameEnum = ianaTimeZone; | ||
var entry = iana_aliases_1.map.find(function (_a) { | ||
var alias = _a.alias; | ||
return alias.includes(ianaTimeZone); | ||
return alias.includes(ianaNameEnum); | ||
}); | ||
@@ -53,0 +56,0 @@ if (typeof entry === "undefined") |
{ | ||
"name": "windows-iana", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A small tool to convert between Windows time zones and IANA", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -18,2 +18,3 @@ [![Build Status](https://travis-ci.org/rubenillodo/windows-iana.svg?branch=master)](https://travis-ci.org/rubenillodo/windows-iana) | ||
- `findAlias()`: will an array of all IANA aliases, including the one passed as a parameter. | ||
- `getAllIanaWindowsMap()`: will return an map of all IANA time zones as key, and a Windows time zone as value. | ||
@@ -75,1 +76,10 @@ ## `findOneIana()` | ||
``` | ||
## `getAllIanaWindowsMap()` | ||
``` | ||
import { getAllIanaWindowsMap } from "windows-iana"; | ||
const result = getAllIanaWindowsMap(); | ||
console.log(result.get('America/New_York')); // Eastern Standard Time | ||
``` |
@@ -6,8 +6,11 @@ import { IanaName, Territory, WindowsZoneName } from "./enums"; | ||
export const findIana = ( | ||
windowsTimeZone: WindowsZoneName, | ||
territory: Territory = Territory["001"], | ||
windowsTimeZone: WindowsZoneName | string, | ||
territory: Territory | string = Territory["001"], | ||
): IanaName[] | undefined => { | ||
const windowsZoneNameEnum = windowsTimeZone as WindowsZoneName; | ||
const territoryEnum = territory as Territory; | ||
const entry = timeZoneMap.find( | ||
({ windowsName: itemName, territory: itemTerritory }) => | ||
itemName === windowsTimeZone && itemTerritory === territory, | ||
itemName === windowsZoneNameEnum && itemTerritory === territoryEnum, | ||
); | ||
@@ -28,4 +31,4 @@ | ||
export const findOneIana = ( | ||
windowsTimeZone: WindowsZoneName, | ||
territory: Territory = Territory["001"], | ||
windowsTimeZone: WindowsZoneName | string, | ||
territory: Territory | string = Territory["001"], | ||
): IanaName | undefined => { | ||
@@ -37,3 +40,3 @@ const result = findIana(windowsTimeZone, territory); | ||
export const findWindows = (ianaTimeZone: IanaName): WindowsZoneName | undefined => { | ||
export const findWindows = (ianaTimeZone: IanaName | string): WindowsZoneName | undefined => { | ||
let result: WindowsZoneName | undefined; | ||
@@ -55,4 +58,5 @@ | ||
export const findAlias = (ianaTimeZone: IanaName): IanaName[] | undefined => { | ||
const entry = ianaAliasMap.find(({ alias }) => alias.includes(ianaTimeZone)); | ||
export const findAlias = (ianaTimeZone: IanaName | string): IanaName[] | undefined => { | ||
const ianaNameEnum = ianaTimeZone as IanaName; | ||
const entry = ianaAliasMap.find(({ alias }) => alias.includes(ianaNameEnum)); | ||
if (typeof entry === "undefined") return undefined; | ||
@@ -59,0 +63,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
689807
9074
84