Giter Site home page Giter Site logo

js-joda-timezone's Introduction

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

const jsJoda = require('js-joda')
    .use(require('js-joda-timezone'))

const { 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

import { use as jsJodaUse, ZonedDateTime, ZoneId } from 'js-joda'
import jsJodaTimeZone from 'js-joda-timezone'

jsJodaUse(jsJodaTimeZone)

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

Browser

<script src="../dist/js-joda.js"></script>
<script src="../dist/js-joda-timezone.js"></script>
<script>
    // use js-joda-timezone
    JSJoda.use(JSJodaTimezone)

    // 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>

Implementation details

  • This ZoneRulesProvider implemantion supplies all functionality that is required by the js-joda package.
  • Additional ZoneRules functionality like transitions(), etc. is not implemented.

License

  • js-joda-timezone is released under the BSD 3-clause license:

  • The author of joda time and the lead architect of the JSR-310 is Stephen Colebourne.

  • The packed json version of the iana tzdb is imported from moment-timezone package.

js-joda-timezone's People

Contributors

pithu avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.