https://github.com/spencermountain/timezone-soft
parse informal timezone names
https://github.com/spencermountain/timezone-soft
iana-timezones timezones
Last synced: 16 days ago
JSON representation
parse informal timezone names
- Host: GitHub
- URL: https://github.com/spencermountain/timezone-soft
- Owner: spencermountain
- Created: 2019-02-08T15:14:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-26T17:50:06.000Z (about 2 months ago)
- Last Synced: 2025-03-31T04:04:45.885Z (23 days ago)
- Topics: iana-timezones, timezones
- Language: JavaScript
- Homepage: https://observablehq.com/@spencermountain/current-time-in
- Size: 1.31 MB
- Stars: 28
- Watchers: 2
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
Awesome Lists containing this project
README
parse abbreviated, sloppy, and informal timezone names
npm install timezone-soft
by
Spencer Kelly
(formerly called 'spacetime-informal')
```js
import soft from 'timezone-soft'// get an IANA tz from user input
let timezones = soft('milwaukee')[0]
/*[{
iana: 'America/Chicago',
standard: { name: 'Central Standard Time', abbrev: 'CST' },
daylight: { name: 'Central Daylight Time', abbrev: 'CDT' }
}
]*/
```
**[IANA timezone codes](https://www.iana.org/time-zones)** are the official reference for timezone information, and is what you should use, whenever possible.
Humans though, _are goofballs_, and use a whole different informal scheme:
---
- In (North) America: **PST, MST, EST**...
- in Europe (lately): **WEST, CEST, EEST**...
- in Africa: **EAT, CAT, WAST**...
- in Australia: **AWST, AEDT, ACST**...---
#### these line-up with the IANA codes sometimes.
#### ...other times they don't.
These names also collide -
'**_IST_**' is used to mean:
- '_Indian Stardard Time_'
- '_Irish Stardard Time_'
- '_Israeli Stardard Time_'These names also produce all-sorts of ambiguities, regarding DST-changes-
Both Winnipeg and Mexico City are **CST**, but have a much different DST schedule:
_(thanks [timeanddate.com](https://www.timeanddate.com)!)_
-of course, there's a bunch of political/historical/disputed stuff going on, too. Apologies if this library steps into that unknowingly.
...so that's what we're trying to fix - to _'soften'_ this exchange, between human and IANA timezone nomenclature, using some _opinionated-but-common-sense_ rules and decision-making.
It was originally built for use in the _[spacetime timezone library](https://github.com/spencermountain/spacetime)_.
### Usage
```js
const soft = require('timezone-soft')soft('EST')
// 'America/New_York'soft('central')
// 'America/Chicago'soft('venezuela')
// 'America/Caracas'soft('south east asia')
// 'Asia/Bangkok'
```Typescript/Deno/Webpack:
```js
import soft from 'timezone-soft'
```it was built to be as forgiving as possible, and return the most common-sense IANA timezone id from user-input.
![]()
---
### DST
Often, the proper timezone name will depend on which date you are referencing.
You can reckon this pretty-easily with [spacetime](https://github.com/spencermountain/spacetime), like this:```js
const spacetime = require('spacetime')
const soft = require('timezone-soft')let display = soft('montreal')[0]
let show = display.standard.abbrev// are we in standard time, or daylight time?
let s = spacetime.now(display.iana)
if (display.daylight && s.isDST()) {
show = display.daylight.abbrev
}
console.log(s.time() + ' ' + show)
// '4:20pm EDT'
```
work-in-progress!
### See also
- [TimeZoneNames](https://github.com/mattjohnsonpint/TimeZoneNames) .NET Standard Library by Matt Johnson-Pint
MIT