Skip to content

Commit f730ea7

Browse files
improve usage example + docs
1 parent b96faca commit f730ea7

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"deno.enable": true,
3+
"deno.suggest.imports.hosts": {
4+
"https://deno.land": false
5+
}
6+
}

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@ fixed: https://github.com/denoland/deno/issues/1968
55

66
## Usage Example
77

8+
```sh
9+
10+
deno run --allow-read --allow-net https://deno.land/x/time/usage-example.ts
11+
12+
```
13+
814
```ts
9-
import * as log from "https://deno.land/std/log/mod.ts";
10-
import { TimeService } from "https://deno.land/x/time";
15+
import * as log from "https://deno.land/std/log/mod.ts"
16+
import { TimeService } from "https://deno.land/x/time/mod.ts"
1117

1218
const countryCode = "DE";
1319
const cityName = "Heidelberg";
1420

15-
const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName);
21+
const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName)
22+
log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`)
1623

17-
log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`);
18-
19-
20-
const timeZone = await TimeService.getTimeZone(countryCode, cityName);
21-
22-
log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`);
23-
24+
const timeZone = await TimeService.getTimeZone(countryCode, cityName)
25+
log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`)
2426

25-
const timeByTimeZone = await TimeService.getTimeByTimeZone(timeZone);
27+
const timeByTimeZone = await TimeService.getTimeByTimeZone(timeZone)
2628
log.info(`In ${timeZone} it is ${timeByTimeZone} o'Clock :)`)
2729

2830
```
@@ -31,7 +33,7 @@ log.info(`In ${timeZone} it is ${timeByTimeZone} o'Clock :)`)
3133

3234
```sh
3335

34-
deno test --allow-read https://deno.land/x/time/test.ts
36+
deno test --allow-read --allow-net https://deno.land/x/time/test.ts
3537

3638
```
3739

time-service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Persistence } from "https://deno.land/x/persistence@1.1.0/persistence.ts"
2-
import * as log from "https://deno.land/std/log/mod.ts";
32

43
export class TimeService {
54

65

76
public static async getAllTimeZoneEntries(): Promise<any[]> {
87
const pathToTimeZonesFile = 'https://raw.githubusercontent.com/michael-spengler/time/master/timezones.json'
9-
8+
109
const allTimeZoneEntries = JSON.parse(await Persistence.readFromRemoteFile(pathToTimeZonesFile))
11-
10+
1211
return allTimeZoneEntries
1312
}
1413

@@ -33,7 +32,7 @@ export class TimeService {
3332

3433
public static async getTimeByTimeZone(timeZone: string): Promise<string> {
3534

36-
const allTimeZones = await TimeService.getAllTimeZoneEntries()
35+
const allTimeZones = await TimeService.getAllTimeZoneEntries()
3736

3837
const entry = allTimeZones.filter((e: any) => e.timezone === timeZone)[0]
3938

@@ -87,7 +86,7 @@ export class TimeService {
8786

8887
private static async getTimeZoneEntry(countryCode: string, cityName: string): Promise<any> {
8988

90-
const allTimeZones = await TimeService.getAllTimeZoneEntries()
89+
const allTimeZones = await TimeService.getAllTimeZoneEntries()
9190

9291
const entry = allTimeZones.filter((e: any) => e.iso2 === countryCode && (e.city === cityName || e.city_ascii === cityName))[0]
9392
if (entry === undefined) {

usage-example.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import * as log from "https://deno.land/std/log/mod.ts";
2-
import { TimeService } from "https://deno.land/x/time";
1+
import * as log from "https://deno.land/std/log/mod.ts"
2+
import { TimeService } from "https://deno.land/x/time/mod.ts"
33

44
const countryCode = "DE";
55
const cityName = "Heidelberg";
66

7-
const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName);
7+
const time = await TimeService.getTimeByCountryAndCity(countryCode, cityName)
8+
log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`)
89

9-
log.info(`In ${cityName} (${countryCode}) it is ${time} o'Clock :)`);
10-
10+
const timeZone = await TimeService.getTimeZone(countryCode, cityName)
11+
log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`)
1112

12-
const timeZone = await TimeService.getTimeZone(countryCode, cityName);
13-
14-
log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`);
15-
16-
17-
const timeByTimeZone = await TimeService.getTimeByTimeZone(timeZone);
13+
const timeByTimeZone = await TimeService.getTimeByTimeZone(timeZone)
1814
log.info(`In ${timeZone} it is ${timeByTimeZone} o'Clock :)`)

0 commit comments

Comments
 (0)