diff --git a/README.md b/README.md index 2eedc19..9154a6d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # Time -Some features of this module might be obsolete as soon as the following issue is -fixed: https://github.com/denoland/deno/issues/1968 +Fortunately there is [ICU support](https://github.com/denoland/deno/issues/1968) since [Deno v1.8](https://deno.com/blog/v1.8#icu-support) came out. +So this module will evolve in providing different time related services in the future. + +Contributions are welcome. ## Usage Example @@ -18,15 +20,9 @@ import { TimeService } from "https://deno.land/x/time/mod.ts" const countryCode = "DE"; const cityName = "Heidelberg"; -const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName) -log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`) - const timeZone = await TimeService.getTimeZone(countryCode, cityName) log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`) -const timeByTimeZone = await TimeService.getTimeByTimeZone(timeZone) -log.info(`In ${timeZone} it is ${timeByTimeZone} o'Clock :)`) - ``` ## Test diff --git a/test.ts b/test.ts index e147e5b..749ccbc 100644 --- a/test.ts +++ b/test.ts @@ -1,10 +1,10 @@ import { TimeService } from './time-service.ts' -import * as log from "https://deno.land/std/log/mod.ts"; -import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; +import * as log from "https://deno.land/std/log/mod.ts" +import { assertEquals } from "https://deno.land/std/testing/asserts.ts" Deno.test("get time by offset", async (): Promise => { - + const offset = '+02:00' const time = await TimeService.getTimeByOffset(offset) @@ -14,7 +14,7 @@ Deno.test("get time by offset", async (): Promise => { }); Deno.test("get timezone", async (): Promise => { - + const countryCode = 'DE' const cityName = 'Heidelberg' @@ -26,32 +26,8 @@ Deno.test("get timezone", async (): Promise => { }); -Deno.test("get time by country and city", async (): Promise => { - - const countryCode = 'DE' - const cityName = 'Heidelberg' - - const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName) - - log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`) - - assertEquals(time.length, 8) -}); - -Deno.test("get time by timezone", async (): Promise => { - - const timeZone = 'Europe/Berlin' - - const time = await TimeService.getTimeByTimeZone(timeZone) - - log.info(`In ${timeZone} it is ${time} o'Clock :)`) - - assertEquals(time.length, 8) -}); - - Deno.test("get offset", async (): Promise => { - + const countryCode = 'DE' const cityName = 'Heidelberg' @@ -66,10 +42,10 @@ Deno.test("get offset", async (): Promise => { Deno.test("get daylight saving time offset", async (): Promise => { - + const countryCode = 'DE' const cityName = 'Heidelberg' - + const offsetDST = await TimeService.getTimeZoneOffsetDST(countryCode, cityName) log.info(`offsetDST: ${offsetDST}`) diff --git a/time-service.ts b/time-service.ts index c2311c2..38c88b7 100644 --- a/time-service.ts +++ b/time-service.ts @@ -2,7 +2,6 @@ import { Persistence } from "https://deno.land/x/persistence@1.1.0/persistence.t export class TimeService { - public static async getAllTimeZoneEntries(): Promise { const pathToTimeZonesFile = 'https://raw.githubusercontent.com/michael-spengler/time/master/timezones.json' @@ -11,13 +10,6 @@ export class TimeService { return allTimeZoneEntries } - public static async getTimeByCountryAndCity(countryCode: string, cityName: string): Promise { - - const entry = await TimeService.getTimeZoneEntry(countryCode, cityName) - - return TimeService.getTimeByTimeZone(entry.timezone) - } - public static getTimeByOffset(offset: string) { const minutes = Number(TimeService.convertOffsetToMinutes(offset)) @@ -30,22 +22,6 @@ export class TimeService { return result.substr(11, 8) } - public static async getTimeByTimeZone(timeZone: string): Promise { - - const allTimeZones = await TimeService.getAllTimeZoneEntries() - - const entry = allTimeZones.filter((e: any) => e.timezone === timeZone)[0] - - if (TimeService.isTimeZoneInDST(timeZone)) { - return TimeService.getTimeByOffset(entry.dayLightSavingTimeOffset) - } else { - return TimeService.getTimeByOffset(entry.offset) - } - } - - public static isTimeZoneInDST(timeZone: string): boolean { - return true // still figuring out a more sophisticated solution ;) - } public static async getTimeZone(countryCode: string, cityName: string): Promise {