All Projects → spencermountain → timezone-soft

spencermountain / timezone-soft

Licence: other
parse informal timezone names

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to timezone-soft

ziptz
Get the time zone and daylight saving time support for any US ZIP code
Stars: ✭ 64 (+300%)
Mutual labels:  timezones
tz.js
A library for working with timezones in JavaScript. Used as part of https://github.com/dbaron/timezone-map .
Stars: ✭ 25 (+56.25%)
Mutual labels:  timezones
graphcountries
An easy to use GraphQL API to query country-related data for free and without restrictions
Stars: ✭ 61 (+281.25%)
Mutual labels:  timezones
world
A Laravel package which provides a list of the countries, states, cities, currencies, timezones and languages.
Stars: ✭ 479 (+2893.75%)
Mutual labels:  timezones
scala-java-time
Implementation of the `java.time` API in scala. Especially useful for scala.js
Stars: ✭ 111 (+593.75%)
Mutual labels:  timezones
Friend-Time
Discord bot - Friend Time helps your server coordinate times and events by converting times mentioned in chat between time zones!
Stars: ✭ 62 (+287.5%)
Mutual labels:  timezones
hawking
A Natural Language Date Time Parser that Extract date and time from text with context and parse to the required format
Stars: ✭ 168 (+950%)
Mutual labels:  timezones
Luxon
⏱ A library for working with dates and times in JS
Stars: ✭ 11,926 (+74437.5%)
Mutual labels:  timezones
Dateutil
Useful extensions to the standard Python datetime features
Stars: ✭ 1,706 (+10562.5%)
Mutual labels:  timezones
Countries
Laravel countries and currencies
Stars: ✭ 1,564 (+9675%)
Mutual labels:  timezones
Pendulum
Python datetimes made easy
Stars: ✭ 4,639 (+28893.75%)
Mutual labels:  timezones
Spacetime
A lightweight javascript timezone library
Stars: ✭ 3,463 (+21543.75%)
Mutual labels:  timezones
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (+125%)
Mutual labels:  timezones
ng2-timezone-selector
A simple Angular module to create a timezone selector using moment-timezone.
Stars: ✭ 12 (-25%)
Mutual labels:  timezones
django-timezone-field
A Django app providing DB, form, and REST framework fields for zoneinfo and pytz timezone objects.
Stars: ✭ 322 (+1912.5%)
Mutual labels:  timezones
tz-trout
Helps you figure out the time zone based on an address or a phone number.
Stars: ✭ 14 (-12.5%)
Mutual labels:  timezones
parse abbreviated, sloppy, and informal timezone names
npm install timezone-soft
by Spencer Kelly
(formerly called 'spacetime-informal')

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 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: image

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

Usage

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:

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, like this:

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

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].