Skip to content

Commit

Permalink
v3.0.0: Support for mulitple countries per timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmhtr committed Jul 29, 2021
1 parent 61cc83e commit 72beb76
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 128 deletions.
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.0.0] - 2021-07-28
### Added
- [#32](https://github.com/manuelmhtr/countries-and-timezones/pull/32) Added support for ESM named exports

### Changed
- Timezones might now be related with multiple countries.

### Removed
- Removed deprecated timezones: `America/Fort_Wayne`, `America/Godthab`, `America/Indianapolis`, `Asia/Rangoon`, `Singapore`, `US/East-Indiana`, `W-SU`.

### Breaking changes
- `getCountryForTimezone` method was renamed to `getCountriesForTimezone` since now timezones might be related with multiple countries. The first country in the list is more relevant due to its geographical location.
- The timezone property `country` was renamed to `countries` and is a list of strings rather than a single string.

## [2.5.0] - 2021-07-18
### Added
- [#27](https://github.com/manuelmhtr/countries-and-timezones/pull/27) Added ESM Build (by [Sachin Singh](https://github.com/scssyworks))

## [2.4.0] - 2021-04-24
### Changed
Expand Down Expand Up @@ -28,8 +45,8 @@ All notable changes to this project will be documented in this file.

## [2.1.0] - 2020-03-31
### Added
- [#15](https://github.com/manuelmhtr/countries-and-timezones/pull/15) Babel and ES5 support (Steven Vachon)
- [#16](https://github.com/manuelmhtr/countries-and-timezones/pull/16) CI Action (Steven Vachon)
- [#15](https://github.com/manuelmhtr/countries-and-timezones/pull/15) Babel and ES5 support (by [Steven Vachon](https://github.com/stevenvachon))
- [#16](https://github.com/manuelmhtr/countries-and-timezones/pull/16) CI Action (by [Steven Vachon](https://github.com/stevenvachon))


## [2.0.0] - 2019-10-10
Expand Down
57 changes: 39 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add the following script to your project (only ~9kb):
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-and-timezones@latest/dist/index.js" type="text/javascript"></script>

<!-- Or specify a version -->
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-and-timezones@v2.4.0/dist/index.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-and-timezones@v3.0.0/dist/index.js" type="text/javascript"></script>

<!-- This will export a variable named "ct": -->
<script type="text/javascript">
Expand Down Expand Up @@ -77,7 +77,7 @@ Prints:
{
name: 'America/Los_Angeles',
country: 'US',
countries: [ 'US' ],
utcOffset: -480,
utcOffsetStr: '-08:00',
dstOffset: -420,
Expand Down Expand Up @@ -148,7 +148,7 @@ Prints:
{
'Africa/Bamako': {
name: 'Africa/Bamako',
country: 'ML',
countries: [ 'ML' ],
utcOffset: 0,
utcOffsetStr: '+00:00',
dstOffset: 0,
Expand All @@ -157,7 +157,7 @@ Prints:
},
'Africa/Banjul': {
name: 'Africa/Banjul',
country: 'GM',
countries: [ 'GM' ],
utcOffset: 0,
utcOffsetStr: '+00:00',
dstOffset: 0,
Expand All @@ -166,7 +166,7 @@ Prints:
},
'Africa/Conakry': {
name: 'Africa/Conakry',
country: 'GN',
countries: [ 'GN' ],
utcOffset: 0,
utcOffsetStr: '+00:00',
dstOffset: 0,
Expand Down Expand Up @@ -197,7 +197,7 @@ Prints:
[
{
name: 'Mexico/BajaSur',
country: 'MX',
countries: [ 'MX' ],
utcOffset: -420,
utcOffsetStr: '-07:00',
dstOffset: -360,
Expand All @@ -206,7 +206,7 @@ Prints:
},
{
name: 'Mexico/General',
country: 'MX',
countries: [ 'MX' ],
utcOffset: -360,
utcOffsetStr: '-06:00',
dstOffset: -300,
Expand All @@ -215,7 +215,7 @@ Prints:
},
{
name: 'America/Ensenada',
country: 'MX',
countries: [ 'MX' ],
utcOffset: -480,
utcOffsetStr: '-08:00',
dstOffset: -420,
Expand All @@ -228,26 +228,47 @@ Prints:
*/
```

### `.getCountryForTimezone(name)`
### `.getCountriesForTimezone(name)`

Returns the country that uses a timezone given its `name`.
Returns a list of the countries that uses a timezone given its `name`. When a timezone has multiple countries **the first element is more relevant** due to its geographical location.

**Example**

```javascript
const ct = require('countries-and-timezones');

const timezone = ct.getCountryForTimezone('Asia/Tokyo');
const timezone = ct.getCountriesForTimezone('Asia/Tokyo');
console.log(timezone);

/*
Prints:
{
id: 'JP',
name: 'Japan',
timezones: [ 'Asia/Tokyo' ]
}
[
{
"id": "CH",
"name": "Switzerland",
"timezones": [
"Europe/Zurich"
]
},
{
"id": "DE",
"name": "Germany",
"timezones": [
"Europe/Busingen",
"Europe/Berlin",
"Europe/Zurich"
]
},
{
"id": "LI",
"name": "Liechtenstein",
"timezones": [
"Europe/Vaduz",
"Europe/Zurich"
]
}
]
*/

Expand Down Expand Up @@ -298,7 +319,7 @@ A timezone is defined by the following parameters:
| Parameter | Type | Description |
| --------- | ---- | ----------- |
|`name`|String|The name of the timezone, from [tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).|
|`country`|String|The [ISO 3166-1 code](https://es.wikipedia.org/wiki/ISO_3166-1) of the country where it's used. `Etc/*`, `GMT` and `UTC` timezones don't have and associated country.|
|`countries`|[String]|A list of [ISO 3166-1 codes](https://es.wikipedia.org/wiki/ISO_3166-1) of the countries where it's used. `Etc/*`, `GMT` and `UTC` timezones don't have associated countries.|
|`utcOffset`|Number|The difference in **minutes** between the timezone and [UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time).|
|`utcOffsetStr`|String|The difference in hours and minutes between the timezone and [UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time), expressed as string with format: `±[hh]:[mm]`.|
|`dstOffset`|Number|The difference in **minutes** between the timezone and [UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time) during daylight saving time ([DST](https://en.wikipedia.org/wiki/Daylight_saving_time)). When `utcOffset` and `dstOffset` are the same, means that the timezone does not observe a daylight saving time.|
Expand All @@ -308,7 +329,7 @@ A timezone is defined by the following parameters:
```javascript
{
name: 'Asia/Tel_Aviv',
country: 'IL',
countries: [ 'IL' ],
utcOffset: 120,
utcOffsetStr: '+02:00',
dstOffset: 180,
Expand Down
2 changes: 0 additions & 2 deletions dist/index.esm.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.esm.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 72beb76

Please sign in to comment.