Skip to content

Instantly share code, notes, and snippets.

@timrwood
Created May 22, 2014 15:41
Show Gist options
  • Save timrwood/bc395e93474c2c5c77c4 to your computer and use it in GitHub Desktop.
Save timrwood/bc395e93474c2c5c77c4 to your computer and use it in GitHub Desktop.
Moment Timezone API

Formats

// Packed
"America/Los_Angeles|PST PDT|70 60|010101010101|-h234i0 fgd0 wef0 fgd0 wef0 fgd0 wef0"

// Unpacked
{
	name    : "America/Los_Angeles",
	abbrs   : ["PST", "PDT", "PST", "PDT", "PST", "PDT", "PST", "PDT", "PST", "PDT"],
	offsets : [420, 480, 420, 480, 420, 480, 420, 480, 420, 480, 420, 480, 420, 480],
	untils  : [-134089073429, -134074893883, -13407683724, -134074372626, -134074937463, -134074937463]
}

Data utils

// in moment-timezone.js
moment.tz.unpack(packed string) > unpacked object
moment.tz.unpackBase60(string) > number

// in moment-timezone-utils.js
moment.tz.pack(unpacked object) > packed string
moment.tz.packBase60(number, precision) > string
moment.tz.filterYear(unpacked object, min, max) > new unpacked object

External API

moment.tz.add(packed string[])
moment.tz.add(packed string)
moment.tz.link(nameA, nameB)
moment.tz.link("nameA|nameB")
moment.tz.link("nameA|nameB"[])
moment.tz.zones() > Zone[]

Zone API

moment.tz.Zone(packed string)
moment.tz.Zone.prototype.offsetFor(moment)
moment.tz.Zone.prototype.abbrFor(moment)
moment.tz.Zone.prototype._indexFor(moment)

Interaction with moment

moment.tz(..., zone name)
moment.fn.tz(zone name)
@timrwood
Copy link
Author

TODO

  • Move zone tests to /tests/zones
  • Move moment-timezone.json to /data/packed/latest.json
  • Write moment.tz.unpackBase60 + tests
  • Write moment.tz.unpack + tests
  • Write moment.tz.packBase60 + tests
  • Write moment.tz.pack + tests
  • Write moment.tz.Zone + tests
  • Write moment.tz.Zone#_indexFor + tests
  • Write moment.tz.Zone#offsetFor + tests
  • Write moment.tz.Zone#abbrFor + tests
  • Write moment.tz.add + tests
  • Write moment.tz.link + tests
  • Write moment.tz.zones + tests
  • Write moment.tz.filterYear + tests
  • Write zic task helper (data/source/northamerica > .temp/zic/america/los_angeles)
  • Write zdump task helper (.temp/zic/america/los_angeles > data/zdump/*.json)
  • Write dedupe task helper (data/zdump/.json > data/unpacked/.json)
  • Write pack task helper (data/unpacked/.json > data/packed/.json)
  • Write zone test helpers (data/zdump/*.json > tests/zones/america/los_angeles.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment