Skip to content

Commit d8625a7

Browse files
refer to ICU Support since Deno 1.8 is there
1 parent f730ea7 commit d8625a7

File tree

3 files changed

+11
-63
lines changed

3 files changed

+11
-63
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Time
22

3-
Some features of this module might be obsolete as soon as the following issue is
4-
fixed: https://github.com/denoland/deno/issues/1968
3+
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.
4+
So this module will evolve in providing different time related services in the future.
5+
6+
Contributions are welcome.
57

68
## Usage Example
79

@@ -18,15 +20,9 @@ import { TimeService } from "https://deno.land/x/time/mod.ts"
1820
const countryCode = "DE";
1921
const cityName = "Heidelberg";
2022

21-
const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName)
22-
log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`)
23-
2423
const timeZone = await TimeService.getTimeZone(countryCode, cityName)
2524
log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`)
2625

27-
const timeByTimeZone = await TimeService.getTimeByTimeZone(timeZone)
28-
log.info(`In ${timeZone} it is ${timeByTimeZone} o'Clock :)`)
29-
3026
```
3127

3228
## Test

test.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { TimeService } from './time-service.ts'
2-
import * as log from "https://deno.land/std/log/mod.ts";
3-
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
2+
import * as log from "https://deno.land/std/log/mod.ts"
3+
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"
44

55

66
Deno.test("get time by offset", async (): Promise<void> => {
7-
7+
88
const offset = '+02:00'
99

1010
const time = await TimeService.getTimeByOffset(offset)
@@ -14,7 +14,7 @@ Deno.test("get time by offset", async (): Promise<void> => {
1414
});
1515

1616
Deno.test("get timezone", async (): Promise<void> => {
17-
17+
1818
const countryCode = 'DE'
1919
const cityName = 'Heidelberg'
2020

@@ -26,32 +26,8 @@ Deno.test("get timezone", async (): Promise<void> => {
2626
});
2727

2828

29-
Deno.test("get time by country and city", async (): Promise<void> => {
30-
31-
const countryCode = 'DE'
32-
const cityName = 'Heidelberg'
33-
34-
const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName)
35-
36-
log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`)
37-
38-
assertEquals(time.length, 8)
39-
});
40-
41-
Deno.test("get time by timezone", async (): Promise<void> => {
42-
43-
const timeZone = 'Europe/Berlin'
44-
45-
const time = await TimeService.getTimeByTimeZone(timeZone)
46-
47-
log.info(`In ${timeZone} it is ${time} o'Clock :)`)
48-
49-
assertEquals(time.length, 8)
50-
});
51-
52-
5329
Deno.test("get offset", async (): Promise<void> => {
54-
30+
5531
const countryCode = 'DE'
5632
const cityName = 'Heidelberg'
5733

@@ -66,10 +42,10 @@ Deno.test("get offset", async (): Promise<void> => {
6642

6743

6844
Deno.test("get daylight saving time offset", async (): Promise<void> => {
69-
45+
7046
const countryCode = 'DE'
7147
const cityName = 'Heidelberg'
72-
48+
7349
const offsetDST = await TimeService.getTimeZoneOffsetDST(countryCode, cityName)
7450

7551
log.info(`offsetDST: ${offsetDST}`)

time-service.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Persistence } from "https://deno.land/x/persistence@1.1.0/persistence.t
22

33
export class TimeService {
44

5-
65
public static async getAllTimeZoneEntries(): Promise<any[]> {
76
const pathToTimeZonesFile = 'https://raw.githubusercontent.com/michael-spengler/time/master/timezones.json'
87

@@ -11,13 +10,6 @@ export class TimeService {
1110
return allTimeZoneEntries
1211
}
1312

14-
public static async getTimeByCountryAndCity(countryCode: string, cityName: string): Promise<string> {
15-
16-
const entry = await TimeService.getTimeZoneEntry(countryCode, cityName)
17-
18-
return TimeService.getTimeByTimeZone(entry.timezone)
19-
}
20-
2113
public static getTimeByOffset(offset: string) {
2214
const minutes = Number(TimeService.convertOffsetToMinutes(offset))
2315

@@ -30,22 +22,6 @@ export class TimeService {
3022
return result.substr(11, 8)
3123
}
3224

33-
public static async getTimeByTimeZone(timeZone: string): Promise<string> {
34-
35-
const allTimeZones = await TimeService.getAllTimeZoneEntries()
36-
37-
const entry = allTimeZones.filter((e: any) => e.timezone === timeZone)[0]
38-
39-
if (TimeService.isTimeZoneInDST(timeZone)) {
40-
return TimeService.getTimeByOffset(entry.dayLightSavingTimeOffset)
41-
} else {
42-
return TimeService.getTimeByOffset(entry.offset)
43-
}
44-
}
45-
46-
public static isTimeZoneInDST(timeZone: string): boolean {
47-
return true // still figuring out a more sophisticated solution ;)
48-
}
4925

5026
public static async getTimeZone(countryCode: string, cityName: string): Promise<string> {
5127

0 commit comments

Comments
 (0)