Socket
Socket
Sign inDemoInstall

spacetime-informal

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    spacetime-informal

interpret abbreviated and informal timezone names


Version published
Weekly downloads
2.7K
increased by24.11%
Maintainers
1
Install size
314 kB
Created
Weekly downloads
 

Changelog

Source

0.6.1 [March 2021]

  • better support for GMT-X offsets

Readme

Source
interpret abbreviated and informal timezone names
spacetime-informal
by Spencer Kelly

The IANA timezone database is the official nomenclature 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, we use: PST, MST, EST...
  • in Europe (lately) they use: WEST, CEST, EEST...
  • in Africa they use: EAT, CAT, WAST...
  • in Australia they use: AWST, AEDT, ACST...

these line-up with the IANA timezones sometimes. Other times they don't.

These names collide all the time, (like IST - irish/indian stardard time).

These names produce all-sorts of ambiguities, regarding DST-changes - Both Winnipeg and Mexico City are CST, but have a much different DST schedule: image

(thanks timeanddate.com!)

Of course, there's a bunch of political/historical/disputed stuff going on, too. Apologies if I step into this unknowingly.

This library is an attempt to 'soften' this exchange, between human-IANA, using some opinionated-but-common-sense rules and decision-making.

It was built for use in the spacetime timezone library, but may be used without it.

const informal = require('spacetime-informal')

informal.find('EST')
// 'America/New_York'

informal.find('central')
// 'America/Chicago'

informal.find('venezuela')
// 'America/Caracas'

informal.find('south east asia')
// 'Asia/Bangkok'

informal.display('Toronto')
/*{
  standard: { name: 'Eastern Standard Time', abbrev: 'EST' },
  daylight: { name: 'Eastern Daylight Time', abbrev: 'EDT' },
  iana: 'Canada/Toronto'
}*/

it was built to be as forgiving as possible, and return the most common-sense IANA timezone id from user-input.


along with spacetime, you can generate human-friendly time formats, like this:

const spacetime = require('spacetime')
const informal = require('spacetime-informal')

let display = informal.display('montreal')
let s = spacetime.now(display.iana)
let abbrev = s.isDST() ? display.daylight.abbrev : display.standard.abbrev // (add some null-checks)
let time = `${s.time()} ${abbrev}`
// '4:20pm EDT'

work-in-progress.

MIT

FAQs

Last updated on 05 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc