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.
- Host: GitHub
- URL: https://github.com/quorumdms/canadian-city-timezones
- Owner: QuorumDMS
- License: mit
- Created: 2020-07-30T19:53:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-02T21:50:19.000Z (almost 3 years ago)
- Last Synced: 2025-02-05T17:13:13.730Z (10 months ago)
- Topics: canada, time, timezone, timezone-list, timezones
- Language: JavaScript
- Homepage:
- Size: 850 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.md
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.