js-joda / js-joda-timezone

!This package is deprecated!
Other
27 stars 4 forks source link
date iana-tzdb joda js-joda time timezone

!This package is deprecated!

The current version has been moved to the js-joda mono repository, see https://github.com/js-joda/js-joda

js-joda-timezone

npm version Build Status Sauce Test Status Coverage Status [Tested node version]()

Sauce Test Status

Motivation

Implementation of the js-joda ZoneRulesProvider, providing the bindings to the iana tzdb, using latest zone file generated by moment-timezone

Usage

Node

Install joda using npm

npm install js-joda
npm install js-joda-timezone

es5

var jsJoda = require('js-joda')
require('js-joda-timezone')

var { LocalDateTime, ZoneId, ZonedDateTime } = jsJoda;

LocalDateTime
    .parse('2016-06-30T11:30')
    .atZone(ZoneId.of('Europe/Berlin'))
    .toString()  // 2016-06-30T11:30+02:00[Europe/Berlin]

ZonedDateTime
    .parse('2016-06-30T11:30+02:00[Europe/Berlin]') 
    .withZoneSameInstant(ZoneId.of('America/New_York'))
    .toString() // 2016-06-30T05:30-04:00[America/New_York]

ZonedDateTime
    .parse('2016-06-30T11:30+02:00[Europe/Berlin]')
    .withZoneSameLocal(ZoneId.of('America/New_York'))
    .toString() // 2016-06-30T11:30-04:00[America/New_York]

es6 / typescript

import { ZonedDateTime, ZoneId } from 'js-joda'
import 'js-joda-timezone'

const zdt = ZonedDateTime.now(ZoneId.of('America/New_York'))

Browser

<script src="https://github.com/js-joda/js-joda-timezone/raw/master/./dist/js-joda.js"></script>
<script src="https://github.com/js-joda/js-joda-timezone/raw/master/./dist/js-joda-timezone.js"></script>
<script>
    // copy all js-joda classes to the global scope
    for(let key in JSJoda) { this[key] = JSJoda[key]; }

    LocalDateTime
        .parse('2016-06-30T11:30')
        .atZone(ZoneId.of('Europe/Berlin'))
        .toString()  // 2016-06-30T11:30+02:00[Europe/Berlin]

    ZonedDateTime
        .parse('2016-06-30T11:30+02:00[Europe/Berlin]') 
        .withZoneSameInstant(ZoneId.of('America/New_York'))
        .toString() // 2016-06-30T05:30-04:00[America/New_York]

    ZonedDateTime
        .parse('2016-06-30T11:30+02:00[Europe/Berlin]')
        .withZoneSameLocal(ZoneId.of('America/New_York'))
        .toString() // 2016-06-30T11:30-04:00[America/New_York]
</script>

Reducing js-joda-timezone file size

If you don't need all the historical data that js-joda-timezone provides, you can instead use one of the reduced files ize builds:

To use one of these, just change your import path to the following format:

import 'js-joda-timezone/dist/js-joda-timezone-1970-2030'

Implementation details

License