Skip to content

Commit

Permalink
improve usage example + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-spengler committed Nov 6, 2021
1 parent b96faca commit f730ea7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"deno.enable": true,
"deno.suggest.imports.hosts": {
"https://deno.land": false
}
}
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ fixed: https://github.com/denoland/deno/issues/1968

## Usage Example

```sh

deno run --allow-read --allow-net https://deno.land/x/time/usage-example.ts

```

```ts
import * as log from "https://deno.land/std/log/mod.ts";
import { TimeService } from "https://deno.land/x/time";
import * as log from "https://deno.land/std/log/mod.ts"
import { TimeService } from "https://deno.land/x/time/mod.ts"

const countryCode = "DE";
const cityName = "Heidelberg";

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

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 timeZone = await TimeService.getTimeZone(countryCode, cityName)
log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`)

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

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

```sh

deno test --allow-read https://deno.land/x/time/test.ts
deno test --allow-read --allow-net https://deno.land/x/time/test.ts

```

Expand Down
9 changes: 4 additions & 5 deletions time-service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Persistence } from "https://deno.land/x/persistence@1.1.0/persistence.ts"
import * as log from "https://deno.land/std/log/mod.ts";

export class TimeService {


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

const allTimeZoneEntries = JSON.parse(await Persistence.readFromRemoteFile(pathToTimeZonesFile))

return allTimeZoneEntries
}

Expand All @@ -33,7 +32,7 @@ export class TimeService {

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

const allTimeZones = await TimeService.getAllTimeZoneEntries()
const allTimeZones = await TimeService.getAllTimeZoneEntries()

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

Expand Down Expand Up @@ -87,7 +86,7 @@ export class TimeService {

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

const allTimeZones = await TimeService.getAllTimeZoneEntries()
const allTimeZones = await TimeService.getAllTimeZoneEntries()

const entry = allTimeZones.filter((e: any) => e.iso2 === countryCode && (e.city === cityName || e.city_ascii === cityName))[0]
if (entry === undefined) {
Expand Down
18 changes: 7 additions & 11 deletions usage-example.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import * as log from "https://deno.land/std/log/mod.ts";
import { TimeService } from "https://deno.land/x/time";
import * as log from "https://deno.land/std/log/mod.ts"
import { TimeService } from "https://deno.land/x/time/mod.ts"

const countryCode = "DE";
const cityName = "Heidelberg";

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

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 timeZone = await TimeService.getTimeZone(countryCode, cityName);

log.info(`The timezone of ${cityName} (${countryCode}) is ${timeZone}`);


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

0 comments on commit f730ea7

Please sign in to comment.