1.2.1 • Published 8 months ago

chronoshift v1.2.1

Weekly downloads
1,913
License
Apache-2.0
Repository
github
Last release
8 months ago

Chronoshift

Chronoshift is a library to manipulate time with timezones

Installation

In node simply run: npm install chronoshift

In the browser you should use the browserified package/chronoshift.js

Usage

Chronoshift can be used in two ways:

1. By using the provided floor, ceil, and move methods

Use chronoshift[period][fn](date, timezone, moveAmount) where

  • period is one of ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond']
  • fn is one of ['floor, ceil, move']
var tz = Timezone.fromJS("America/Los_Angeles");

var hourStart = chronoshift.hour.floor(new Date("2012-11-04T00:30:00-07:00"), tz));

hourStart.getTime() === new Date("2012-11-04T00:00:00-07:00").getTime()

2. By using the Duration class

Construct a new duration with a ISO Duration string. Then you can call floor, ceil and move on it.

Note that floor and ceil only work for 'simple' durations like "P1x" and "PT1x".

var Duration = chronoshift.Duration;
var tz = Timezone.fromJS("America/Los_Angeles");

p1w = Duration.formJS('P1W');

var weekStart;

weekStart = p1w.floor(new Date("2013-09-29T01:02:03.456-07:00"), tz)
weekStart.getTime() === new Date("2013-09-29T00:00:00.000-07:00").getTime()

weekStart = p1w.floor(new Date("2013-10-03T01:02:03.456-07:00"), tz)
weekStart.getTime() === new Date("2013-09-29T00:00:00.000-07:00").getTime()

A duration can also be constructed from two dates and a timezone:

new Duration(
  new Date("2012-10-29T00:00:00-07:00")
  new Date("2012-11-05T00:00:00-08:00")
  tz
).toString() // => 'P7D'

new Duration(
  new Date("2012-01-01T00:00:00-08:00")
  new Date("2013-03-04T04:05:06-08:00")
  tz
).toString() // => 'P1Y2M3DT4H5M6S'

Useful!

Development

Clone the repository :

$ git clone https://github.com/implyio/chronoshift.git

Install the dependencies :

$ npm install

Watch :

$ npm run watch

Questions & Support

Please file bugs and feature requests by opening and issue on GitHub and direct all questions to our user groups.

1.2.1

8 months ago

1.2.0

8 months ago

1.1.0

9 months ago

1.0.1

10 months ago

1.0.0

10 months ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.0

4 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.1

7 years ago

0.7.3

7 years ago

0.8.0

7 years ago

0.7.2

7 years ago

0.6.10

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.9

8 years ago

0.6.8

8 years ago

0.6.7

8 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.5.8

9 years ago

0.5.7

9 years ago

0.5.6

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.3

9 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.3.7

10 years ago

0.3.6

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago