UNPKG

8.75 kBMarkdownView Raw
1# @js-joda/core
2
3# Immutable date and time library for JavaScript
4
5[![npm version](https://badge.fury.io/js/%40js-joda%2Fcore.svg)](https://badge.fury.io/js/%40js-joda%2Fcore)
6[![Travis Build Status](https://travis-ci.org/js-joda/js-joda.svg)](https://travis-ci.org/js-joda/js-joda)
7[![Sauce Test Status](https://saucelabs.com/buildstatus/js-joda)](https://saucelabs.com/u/js-joda)
8[![Coverage Status](https://coveralls.io/repos/js-joda/js-joda/badge.svg?branch=master&service=github)](https://coveralls.io/github/js-joda/js-joda?branch=master)
9[![Tested node version](https://img.shields.io/badge/tested_with-current_node_LTS-blue.svg?style=flat)]()
10[![Sauce Test Status](https://saucelabs.com/browser-matrix/js-joda.svg)](https://saucelabs.com/u/js-joda)
11
12## Introduction
13
14**js-joda** is an **immutable date and time library** for JavaScript. It provides a **simple, domain-driven and clean API** based on the ISO calendar system, which is the de facto world calendar following the proleptic Gregorian rules.
15
16- js-joda has a lightweight footprint, only **43 kB minified and compressed**, no third party dependencies.
17
18- js-joda is **fast**. It is about 2 to 10 times faster than other JavaScript date libraries.
19
20- js-joda comes with built-in parsers/ formatters for ISO 8601 as specified in RFC 3339, that can be easily customized.
21
22- js-joda supports **ECMAScript 5** browsers down to IE9.
23
24- js-joda is a **port of the threeten** backport, which is the base for JSR-310 implementation of the Java SE 8 java.time package. Threeten is inspired by **Joda-Time**, having similar concepts and the same author.
25
26- js-joda is **robust and stable**. We ported more then 1700 test-cases with a lots of test-permutations from the threetenbp project. We run the automated karma test-suite against Firefox, Chrome, Node and phantomjs.
27
28## Why yet another JavaScript date and time library?
29
30- Popular JavaScript date libraries like [moment](https://momentjs.com/) or [date-utils](https://github.com/continuouscalendar/dateutils) are **wrappers** around the native JavaScript `Date` object, providing syntactic sugar. The native `Date` object always consist of a date, time and a timezone part. In contrast, js-joda is a **standalone** date and time implementation.
31
32- The API has a **domain-driven design** with classes for each of the different use cases, like `LocalDate`, `ZonedDateTime` or `Period`. For example, `LocalDate` allows you to handle dates without times (like birthdays or holidays) in a clean and error-safe way, especially if these dates are persisted to an external server.
33
34- js-joda is **immutable**. Immutability aligns well with pure functions and with the architecture of frameworks like React and Flux.
35
36## The ThreeTen domain models
37
38### Dates and Times
39
40- **LocalDate** represents a date without a time and timezone in the ISO-8601 calendar system, such as 2007-12-24.
41
42- **LocalTime** represents a time without timezone in the ISO-8601 calendar system such as '11:55:00'.
43
44- **LocalDateTime** is a description of the date (LocalDate), as used for birthdays, combined with the local time (LocalTime) as seen on a wall clock.
45
46- **ZonedDateTime** is a date-time with a timezone in the ISO-8601 calendar system, such as 2007-12-24T16:15:30+01:00 UTC+01:00.
47
48- **Instant** is an instantaneous point on the time-line measured from the epoch of _1970-01-01T00:00:00Z_ in epoch-seconds and nanosecond-of-second.
49
50### Duration and Period
51
52- **Duration** is a time-based amount of time, such as '34.5 seconds'.
53
54- **Period** is a date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.
55
56### Additional value types
57
58- **Year** represents a year in the ISO-8601 calendar system, such as '2016'.
59
60- **YearMonth** represents a year and a month in the ISO-8601 calendar system, such as '2016-01'.
61
62- **Month** represents a month-of-year in the ISO-8601 calendar system, such as 'July'.
63
64- **MonthDay** represents a month-day in the ISO-8601 calendar system, such as '--12-03'. Could be used to represent e.g. Birthdays.
65
66- **DayOfWeek** represents a day-of-week in the ISO-8601 calendar system, such as 'Tuesday'.
67
68## Getting started
69
70### Node
71
72Install joda using npm
73
74```
75npm install @js-joda/core
76```
77
78Then require it to any module
79
80```js
81var LocalDate = require('@js-joda/core').LocalDate;
82
83var d = LocalDate.parse('2012-12-24').atStartOfDay().plusMonths(2); // 2013-02-24T00:00:00
84```
85
86### Browser
87
88To use js-joda from a browser, download either `dist/js-joda.min.js` or `dist/js-joda.js` (with sourcemaps for development). Then add it as a script tag to your page
89
90```html
91<script src="js-joda.min.js"></script>
92<script>
93 var LocalDate = JSJoda.LocalDate;
94 var d = LocalDate.parse('2012-12-24').atStartOfDay().plusMonths(2); // 2013-02-24T00:00:00
95</script>
96```
97
98## Documentation
99
100- [js-joda Quick start guide](//js-joda.github.io/js-joda/manual/getting-started.html) Quick start guide and examples
101- [API](//js-joda.github.io/js-joda/identifiers.html) ESDoc generated API documentation
102
103## Roadmap
104
105### Milestone 1: Core domains (reached with version v1.0.0)
106
107- Support for the domain models `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `Instant`, `Duration` and `Period` converting to and from ISO8601.
108- `ZonedDateTime` (without support for loading iana timezone databases) currently supports only fixed offsets like UTC or UTC+02:00 and the system default time zone.
109
110### Milestone 2: IANA timezone support (reached with version v1.2.0)
111
112- Add IANA timezone database support to js-joda. Implement handling of daylight saving transitions, mainly in `ZonedDateTime`.
113- For access to the IANA timezone database, the plugin [@js-joda/timezone](//github.com/js-joda/js-joda/tree/master/packages/timezone) is required. It provides an implementation of the [ZoneRulesProvider](//js-joda.github.io/js-joda/class/packages/core/src/zone/ZoneRulesProvider.js~ZoneRulesProvider.html) and contains the iana timezone database.
114
115### Milestone 3: Locale support (reached with v2.0.0 of js-joda-locale)
116
117- Add locale support.
118- Extend pattern parser/ formatter for text with locale support.
119
120see the plugin [@js-joda/locale](//github.com/js-joda/js-joda/tree/master/packages/locale)
121
122### Future Milestones
123
124- Reduce library size by removing redundant code, especially by refactoring code for formatting/ parsing dates.
125- Increase test coverage (ongoing task)
126- Cleanup documentation (ongoing task)
127- Improve static factory API design and make it more JavaScript style. One idea is to remove static factory methods like parse, from, of and unify it to one factory method per domain. E.g. localDate(isoDate: string), localDate(year: number, month: number, dayOfMonth: number)
128- Merge methods get and getLong (difference between `int` and `long` values makes no sense with JavaScript)
129- Simplify temporal adjusters (amount, etc) by using functions instead of classes or objects
130
131## Contributing
132
133Contributions are always welcome. Before contributing please read the [code of conduct](http://contributor-covenant.org/version/1/4/) &
134search the issue tracker. We use GitHub issues. Your issue may have already been discussed or fixed. To contribute, fork js-joda, commit your changes, & send a pull request.
135
136By contributing to js-joda, you agree that your contributions will be licensed under its BSD license.
137
138Note that only pull requests and issues that match the threeten backport API will be considered. Additional requested features will be rejected.
139
140## License
141
142- `Joda-Time` is the base for JSR-310 that became part of Java SE 8 in the java.time package. JSR-310 is a new implementation with an API 'inspired by Joda-Time' but improves on some design flaws (see http://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html) `Joda-Time` is under Apache 2.0 licence.
143
144`js-joda` uses the ThreeTen-Backport implementation (http://www.threeten.org/threetenbp/) as a reference base for implementation. This allows us to release js-joda under the BSD License while the OpenJDK java.time implementation is under GNU GPL+linking exception. The API of the ThreeTen-Backport is mostly identical to the official Java SE 8 API from the view of our JavaScript port.
145
146- `js-joda` is released under the [BSD 3-clause license](//github.com/js-joda/js-joda/blob/master/LICENSE).
147
148- Our implementation reference base ThreeTen-Backport (http://www.threeten.org/threetenbp/) is also released under the BSD 3-clause license
149
150- `OpenJDK` is under GNU GPL+linking exception.
151
152- The author of `Joda-Time` and the lead architect of the JSR-310 is Stephen Colebourne.
153
154The API of this project (as far as possible with JavaScript), a lot of implementation details and documentation
155are just copied but never equalled.