An open API service indexing awesome lists of open source software.

https://github.com/quorumdms/canadian-city-timezones

Searchable timezones for Canadian Cities, Towns, Villages based on census data.
https://github.com/quorumdms/canadian-city-timezones

canada time timezone timezone-list timezones

Last synced: 8 months ago
JSON representation

Searchable timezones for Canadian Cities, Towns, Villages based on census data.

Awesome Lists containing this project

README

          

Canadian City Timezones



Searchable timezones for all Canadian cities, towns, townships, villages, hamlets, and municipalities.

## Usage

`npm install canadian-city-timezones`

```ts
import {find} from 'canadian-city-timezones';

const result = await find(({city, province}) => city === 'Lethbridge' && province === 'Alberta');
result.city // Lethbridge
result.province // Alberta
result.timezone // America/Edmonton
```

## API

### Methods

```ts
find(predicate: (value: TimezoneResult) => boolean): Promise
```

Returns the first matching result for the given predicate.

```ts
filter(predicate: (value: TimezoneResult) => boolean): AsyncGenerator
```

Yields all matching results for the given predicate.

```ts
values(): AsyncGenerator
```

Yields all values.

### Interfaces

`TimezoneResult`
```
{
city: string;
province: string;
timezone: string;
}
```

## How Does This Work?

Before this package is published, census data listing all dwellings in Canada is downloaded from `statcan.gc.ca`. This is filtered by applicable types (city, town, etc) and sent to `mapbox.com` to find the dwelling's geographic coordinates (latitude & longitude). From there, the coordinates are given to [`geo-tz`](https://github.com/evansiroky/node-geo-tz) which returns the timezone.

This data is then written to a CSV file and published along side the simple interface for interacting with the data. So look ups are quick since it is just checking a local CSV.

The interface works with an async generator, reading this CSV file line by line to avoid loading all data into memory.

## Development

We want to reduce the number of dependencies the end user encounters, keep that in mind when working within this repository.

Data can be generated by manually triggering [the `Generate` workflow](https://github.com/autovance/canadian-city-timezones/actions?query=workflow%3AGenerate).

Releases are done automatically when commits are merged into master using [semantic-release](https://github.com/semantic-release/semantic-release). Please use appropriate commit prefixes.
Changes that only affect the generation of data should be prefixed with `generate:` to avoid triggering a release.