qrono 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Qrono<small> - 🕥 Just right date time library</small>
1
+ # <img src="docs/public/logo.png" alt="Qrono Logo" width="100"> Qrono - 🕥 _Just right date time library_
2
2
 
3
3
  [![MIT License][image-license]][url-license]
4
4
  [![NPM version][image-npm-version]][url-npm]
@@ -11,7 +11,7 @@ qrono('2021-08-31 12:34') < qrono('2021-09-30 12:34')
11
11
  qrono({ localtime: true }, '2021-08-31 12:34').toString() === '2021-08-31T12:34.000-04:00'
12
12
  ```
13
13
 
14
- [🎨 Design philosophy](#design-philosophy-) \| [📥 Getting started](#getting-started-) \| [🚀 Quick tour](#quick-tour-) \| [🌏 License](#license-)
14
+ [🌐 Website](https://urin.github.io/qrono/) \| [🎨 Design philosophy](#design-philosophy-) \| [📥 Getting started](#getting-started-) \| [🚀 Quick tour](#quick-tour-) \| [🌏 License](#license-)
15
15
 
16
16
  ---
17
17
 
@@ -29,47 +29,52 @@ qrono({ localtime: true }, '2021-08-31 12:34').toString() === '2021-08-31T12:34.
29
29
  - Follows [ISO 8601](https://www.iso.org/obp/ui/#iso:std:iso:8601:-1:ed-1:v1:en).
30
30
  - Pure JavaScript without dependencies.
31
31
 
32
- <details>
33
- <summary id="alternatives">Alternatives</summary>
34
- <ul>
35
- <li>
36
- <a href="https://github.com/moment/moment">Moment.js</a>
37
- <br>
38
- A widely used library that was the de-facto standard. It went into maintenance mode in 2020.<br>
39
- It has a fundamental problem with mutable objects, making it prone to bugs. The later date-time libraries introduced below are all designed to be immutable.<br>
40
- </li>
41
- <li>
42
- <a href="https://github.com/moment/luxon">Luxon</a>
43
- <br>
44
- An immutable and rich library created by the maintainers of <a href="https://github.com/moment/moment">Moment.js</a>. Sophisticated and feature-rich. Good codebase to explore.<br>
45
- By default, it handles time in local time and <a href="https://moment.github.io/luxon/#/zones?id=ambiguous-times">cannot strictly handle ambiguous times</a>.<br>
46
- It differs from other libraries in that the documentation clearly shows how it behaves with ambiguous time.<br>
47
- </li>
48
- <li>
49
- <a href="https://github.com/iamkun/dayjs">Day.js</a>
50
- <br>
51
- A <a href="https://github.com/moment/moment">Moment.js</a> compatible library with a minimum size of 2KB, which has <a href="https://github.com/iamkun/dayjs/stargazers">many GitHub stars</a> and is becoming the de-facto standard. The code readability is not high.<br>
52
- The codebase is large due to time zone and locale support (178 source files as of 2021-11-02), but the effective size can be reduced if tree-shaking is available.<br>
53
- Requires importing plugins each time because most functions are provided as plugins.<br>
54
- Planning a major version upgrade while solving <a href="https://github.com/iamkun/dayjs/issues?q=is%3Aissue+is%3Aopen">many issues</a>.<br>
55
- </li>
56
- <li>
57
- <a href="https://github.com/date-fns/date-fns">date-fns</a>
58
- <br>
59
- Provides over 200 pure functions for manipulating JavaScript `Date` objects, implemented in TypeScript and tree-shaking enabled.<br>
60
- Since the JavaScript `Date` object takes the lead, problems such as mutability and month starting at 0 are inherited. <br>
61
- </li>
62
- <li>
63
- <a href="https://tc39.es/proposal-temporal/docs/index.html">
64
- The ECMA TC39 Temporal Proposal
65
- </a>
66
- <br>
67
- An ECMAScript® API proposal that may become a future standard. The specification is rigorous, spectacular, and inspired by <a href="https://jcp.org/aboutJava/communityprocess/pfd/jsr310/JSR-310-guide.html">java.time</a>.
68
- </li>
69
- </ul>
70
- </details>
71
-
72
- ### About daylight saving time transitions
32
+ ### Alternatives
33
+
34
+ - **[Moment.js](https://momentjs.com/)**
35
+ A widely used library that was the de-facto standard. It went into maintenance mode in 2020.
36
+ It has a fundamental problem with mutable objects, making it prone to bugs. The later date-time libraries introduced below are all designed to be immutable.
37
+
38
+ - **[Luxon](https://moment.github.io/luxon/)**
39
+ An immutable and rich library created by the maintainers of [Moment.js](https://github.com/moment/moment). Sophisticated and feature-rich. Good codebase to explore.
40
+ By default, it handles time in local time and [cannot strictly handle ambiguous times](https://moment.github.io/luxon/#/zones?id=ambiguous-times).
41
+ It differs from other libraries in that the documentation clearly shows how it behaves with ambiguous time.
42
+
43
+ - **[Day.js](https://day.js.org/)**
44
+ A [Moment.js](https://github.com/moment/moment) compatible library with small size, which has [many GitHub stars](https://github.com/iamkun/dayjs/stargazers) and is becoming the de-facto standard.
45
+ Requires importing plugins each time because most functions are provided as plugins.
46
+ 3.4kB with 30+ APIs, but requires plugin imports for timezone/locale support and other functions.
47
+ **Qrono** achieves **3.9kB with 100+ APIs** without plugins.
48
+ The codebase is large due to time zone and locale support (178 source files as of 2021-11-02), but the effective size can be reduced if tree-shaking is available. The code readability is not high.
49
+ Planning a major version upgrade while solving [many issues](https://github.com/iamkun/dayjs/issues?q=is%3Aissue+is%3Aopen).
50
+
51
+ - **[date-fns](https://date-fns.org/)**
52
+ Provides 200+ pure functions for manipulating JavaScript `Date` objects, implemented in TypeScript and tree-shaking enabled.
53
+ Since the JavaScript `Date` object takes the lead, problems such as mutability and month starting at 0 are inherited.
54
+
55
+ - **[The ECMA TC39 Temporal Proposal](https://tc39.es/proposal-temporal/docs/index.html)**
56
+ An ECMAScript® API proposal that may become a future standard. The specification is rigorous, spectacular, and inspired by [java.time](https://jcp.org/aboutJava/communityprocess/pfd/jsr310/JSR-310-guide.html).
57
+
58
+ ### Reason for Supporting Only the Local Time of the Execution Environment
59
+
60
+ When handling time in a globally accessible web application, careful consideration about local time required.
61
+
62
+ In general, the server does not know the user’s actual time zone or the time zone of the client environment (OS).
63
+ If the system needs to be aware of the user’s time zone, an application-level mechanism to manage time zones becomes necessary. In practice, however, the user’s time zone is usually assumed to be the same as the client environment’s (OS) time zone.
64
+
65
+ For example, a user who resides in Japan may start using the application in the United States. If the user changes the OS time zone to match the local time in the United States, this will be done automatically in most cases such as the environment is a smart device, the client environment’s time zone will differ from the one that is managed in the server. Considering the large number of such edge cases, it is impractical for a server-side application to manage each user’s intended time zone in a database-like manner.
66
+
67
+ For this reason, to keep the system design simple, the server should avoid managing user-specific time zones. Instead, the server should store and handle time exclusively in UTC. All time values should be transmitted to clients in UTC (typically as ISO 8601–formatted strings), and converting them into local time should be the responsibility of the client.
68
+
69
+ Even when support for multiple locales is required, storing time data in UTC is usually sufficient. In most cases, locale-specific formatting can be handled entirely on the client side by using the [ECMAScript® Internationalization API](https://402.ecma-international.org/#overview).
70
+
71
+ One important caveat of this design is that the time zone database of the client environment (OS) must be properly maintained. Daylight saving time rules — for example, in Brazil — may change from year to year, and time zone definitions themselves are determined by laws that are frequently revised. This means that the underlying time zone database must be kept up to date.
72
+
73
+ If the application is used in a closed or unmanaged environment where such updates cannot be applied due to special constraints, the approach described above may be insufficient.
74
+
75
+ Considering these factors, **Qrono** is deliberately designed to forgo support for multiple time zones in order to achieve greater overall benefits such as small code base and easy handling of daylight saving time transitions.
76
+
77
+ ### Handling DST transitions with JavaScript's `Date`
73
78
 
74
79
  JavaScript's `Date` object can behave in non-intuitive ways when handling daylight saving time transitions.
75
80
 
@@ -87,24 +92,25 @@ This behavior is not a bug but a result of strictly following the ECMAScript spe
87
92
 
88
93
  Additionally, a `Date` object created from a duplicated time during daylight saving time (DST) transition always refers to the time before DST ends. In other words, there is no simple way to obtain a `Date` object that refers to the UTC time **after** the end of DST from a duplicated time.
89
94
 
90
- This library addresses these issues by providing a more understandable approach to handling such transitions.
95
+ Qrono is the only JavaScript date-time library with dedicated APIs for DST handling (`hasDstInYear()`, `isInDst()`, `isDstTransitionDay()`, `minutesInDay()`).
91
96
 
92
97
  ## Getting started 📥
93
98
 
94
- ### Browser
99
+ ```sh
100
+ npm install qrono # for npm
101
+ deno add jsr:@urin/qrono # for Deno
102
+ bunx jsr add @urin/qrono # for Bun
103
+ pnpm add @urin/qrono # for pnpm
104
+ yarn add @urin/qrono # for Yarn
105
+ ```
95
106
 
96
107
  ```html
108
+ <!-- for Browser -->
97
109
  <script src="path/to/qrono.min.js"></script>
98
110
  <!-- from UNPKG -->
99
111
  <script src="https://unpkg.com/qrono/dist/qrono.min.js"></script>
100
112
  ```
101
113
 
102
- ### Node.js
103
-
104
- ```sh
105
- npm install qrono
106
- ```
107
-
108
114
  ```js
109
115
  // as module
110
116
  import { qrono } from 'qrono'