Searchable timezones for all Canadian cities, towns, townships, villages, hamlets, and municipalities.
npm install canadian-city-timezones
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
find(predicate: (value: TimezoneResult) => boolean): Promise<TimezoneResult | null>
Returns the first matching result for the given predicate.
filter(predicate: (value: TimezoneResult) => boolean): AsyncGenerator<TimezoneResult>
Yields all matching results for the given predicate.
values(): AsyncGenerator<TimezoneResult>
Yields all values.
TimezoneResult
{
city: string;
province: string;
timezone: string;
}
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
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.
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.
Releases are done automatically when commits are merged into master using 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.