Skip to content

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

License

Notifications You must be signed in to change notification settings

QuorumDMS/canadian-city-timezones

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Canadian City Timezones

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

Usage

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

API

Methods

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.

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 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.

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.