Skip to content

Commit

Permalink
feat(time zones): better city grouping and renaming
Browse files Browse the repository at this point in the history
This commit adds a better city information in simplified-time-zones.json file.
Previously we were only taking cities from America/Los_Angeles (= Los Angeles)
and then trying to find them back in geonames dataset. Then we would only merge
cities if they both belonged to the exact same offsets + dst.

Now we still only group cities from same country, same offset + dst, but we do
so by first selecting all cities from geonames for this country + offset and
then merging them. This means we now display things like `Pacific Time, Los
Angeles, San Diego`.

+ added `mainCities` field as an array
+ added `alternativeName` (Pacific Time instead of America/Los_Angeles)

BREAKING CHANGES:
+ renamed `timeZoneName` to `name` in simplified-time-zones.json
+ removed cities-with-time-zones.json from package and repository, it changes
too often and would trigger many releases. This computation is better stored in
Algolia or any other search engine if you need to search in it
  • Loading branch information
vvo committed Jun 26, 2020
1 parent 9eda92c commit 6014bd2
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 24,964 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
dist/
cities-with-time-zones.json
simplified-time-zones.json
time-zones-names.json
2 changes: 1 addition & 1 deletion .github/workflows/maybe-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
commit_message: "feat(data): Automatic data update"

# Optional glob pattern of files which should be added to the commit
file_pattern: cities-with-time-zones.json simplified-time-zones.json time-zones-names.json
file_pattern: simplified-time-zones.json time-zones-names.json
- name: Release if necessary
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/next'
run: yarn semantic-release
Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
!*.yml
/coverage/
/dist/
cities-with-time-zones.json
time-zones-names.json
simplified-time-zones.json
131 changes: 49 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

This is a list and npm package of:

- "simplified" [IANA time zones](https://www.iana.org/time-zones) and their offset names
- all existing IANA time zones names
- and major cities (population > 5,000) with their associated time zones and offset names
- "simplified" [IANA time zones](https://www.iana.org/time-zones) with their alternative names like `Pacific Time` instead of `America/Los_Angeles`, along with major cities for each time zone.
- all existing raw IANA time zones names

The data and npm packages are **automatically updated** whenever there are changes to https://www.geonames.org/ which is generated from IANA databases.

Expand All @@ -19,28 +18,38 @@ This is most probably what you're looking for if you're trying to build a good c
Example data:

```js
{
"timeZoneName":"America/Anchorage",
"formatted":"-09:00 Alaska Time - Anchorage, Juneau",
"group":[
"America/Anchorage",
"America/Juneau",
"America/Metlakatla",
"America/Nome",
"America/Sitka",
"America/Yakutat"
]
},
{
"timeZoneName":"Pacific/Gambier",
"formatted":"-09:00 Gambier Time - Gambier",
"group":["Pacific/Gambier"]
},
{
"timeZoneName":"America/Los_Angeles",
"formatted":"-08:00 Pacific Time - Los Angeles",
"group":["America/Los_Angeles"]
},
[
// ...
{
name: "America/Anchorage",
alternativeName: "Alaska Time",
mainCities: ["Anchorage", "Juneau"],
formatted: "-09:00 Alaska Time - Anchorage, Juneau",
group: [
"America/Anchorage",
"America/Juneau",
"America/Metlakatla",
"America/Nome",
"America/Sitka",
"America/Yakutat",
],
},
{
name: "Pacific/Gambier",
alternativeName: "Gambier Time",
mainCities: ["Gambier"],
formatted: "-09:00 Gambier Time - Gambier",
group: ["Pacific/Gambier"],
},
{
name: "America/Los_Angeles",
alternativeName: "Pacific Time",
mainCities: ["Los Angeles", "San Diego"],
formatted: "-08:00 Pacific Time - Los Angeles, San Diego",
group: ["America/Los_Angeles"],
},
// ...
];
```

As you can see, we provide the time zone name and a pre-formatted version using more common offset names.
Expand All @@ -52,67 +61,26 @@ Notes:
- We provide offset names ("Pacific Time") without dst and remove "Standard" and "Daylight"
- This can be used to build a good enough (Google calendar like) select box of time zones, but it's your responsibility to handle dst and real offsets

### [cities-with-time-zones.json](./cities-with-time-zones.json)

This is a list of major cities (population > 5,000) and their associated time zone information, ranked by population. This is useful if you want to build an application where the user will type a city and you want the time zone information out of it.

Example data:

```js
{
"geonameId":"5368361",
"name":"Los Angeles",
"countryName":"United States",
"timeZoneName":"America/Los_Angeles",
"timeZoneOffsetNameWithoutDst":"Pacific Time",
"population":3971883,
"modificationDate":"2019-12-12"
},
{
"geonameId":"1205733",
"name":"Chittagong",
"countryName":"Bangladesh",
"timeZoneName":"Asia/Dhaka",
"timeZoneOffsetNameWithoutDst":"Bangladesh Time",
"population":3920222,
"modificationDate":"2016-11-09"
},
{
"geonameId":"1804651",
"name":"Kunming",
"countryName":"China",
"timeZoneName":"Asia/Shanghai",
"timeZoneOffsetNameWithoutDst":"China Time",
"population":3855346,
"modificationDate":"2014-08-14"
},
{
"geonameId":"361058",
"name":"Alexandria",
"countryName":"Egypt",
"timeZoneName":"Africa/Cairo",
"timeZoneOffsetNameWithoutDst":"Eastern European Time",
"population":3811516,
"modificationDate":"2019-09-05"
},
```

### [time-zones-names.json](./time-zones-names.json)

This is the raw list of all IANA time zones ranked by alphabetical order.

Example data:

```js
"America/La_Paz",
"America/Lima",
"America/Los_Angeles",
"America/Lower_Princes",
"America/Maceio",
"America/Managua",
"America/Manaus",
"America/Marigot",
"America/Martinique",
[
// ...
"America/La_Paz",
"America/Lima",
"America/Los_Angeles",
"America/Lower_Princes",
"America/Maceio",
"America/Managua",
"America/Manaus",
"America/Marigot",
"America/Martinique",
// ...
];
```

## NPM package
Expand All @@ -126,12 +94,11 @@ npm add @vvo/tzdb
Usage:

```js
import cities from "@vvo/tzdb/cities-with-time-zones.json";
import simplifiedTimeZones from "@vvo/tzdb/simplified-time-zones.json";
import timeZones from "@vvo/tzdb/time-zones-names.json";
import simplifiedTimeZones from "@vvo/tzdb/simplified-time-zones.json";
```

## Algolia
## [BETA] Algolia

You can store cities information on a search engine like [Algolia](http://algolia.com/). There's a `yarn build` command you can use if you clone this repository to create your own Algolia index. The expected environment variables are:

Expand Down
Loading

0 comments on commit 6014bd2

Please sign in to comment.