tz2tz

Shorthand for common timezone operations

Usage no npm install needed!

<script type="module">
  import tz2tz from 'https://cdn.skypack.dev/tz2tz';
</script>

README

Build Status

Disclaimer

Honestly I'm just writing this so that I can require it without relative file paths in my projects.

If you find it useful, great. Otherwise, like all open-source software, expect zero support.

I will happily merge PRs though :)

API

// I recommend 'z' because 't' is a common temp var name
var z = require('tz2tz')
  , timestamp = Date.now()

// Parse the timestamp in the timezone then output it in the moment-style format specified
z(timestamp, 'America/Los_Angeles', 'ddd MMM D')

// Shorthandy goodness

// Thu Jan 15
// Uses 'ddd MMM D' as format
z.getDate(timestamp, 'America/Los_Angeles')

// 6:05AM
// Uses 'h:mmA' as format
z.getTime(timestamp, 'America/Los_Angeles')

// 6:05AM 1/15/15
z.getShort(timestamp, 'America/Los_Angeles')

// Thu, Jan 15, 2015 6:05 AM
// Uses preferred locale format
z.getFull(timestamp, 'America/Los_Angeles')

// Thursday
z.getDay(timestamp, 'America/Los_Angeles')

// 6 (integer)
z.getHours(timestamp, 'America/Los_Angeles')

// 5 (integer)
z.getMinutes(timestamp, 'America/Los_Angeles')

// Change the shorthand constants
z.constants.timeFormat = 'h:mm a'

Is That All?

Yeah that's it. But seriously, if you had to do this hundreds of times, you would want something like this too.