date-and-time 0.14.2 → 2.0.1
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/EXTEND.md +29 -11
- package/LOCALE.md +19 -34
- package/PLUGINS.md +222 -113
- package/README.md +203 -171
- package/date-and-time.js +171 -147
- package/date-and-time.min.js +14 -14
- package/esm/date-and-time.es.js +466 -0
- package/esm/date-and-time.es.min.js +17 -0
- package/esm/date-and-time.mjs +466 -0
- package/esm/locale/ar.es.js +39 -0
- package/esm/locale/ar.mjs +39 -0
- package/esm/locale/az.es.js +44 -0
- package/esm/locale/az.mjs +44 -0
- package/esm/locale/bn.es.js +50 -0
- package/esm/locale/bn.mjs +50 -0
- package/esm/locale/cs.es.js +22 -0
- package/esm/locale/cs.mjs +22 -0
- package/esm/locale/de.es.js +23 -0
- package/esm/locale/de.mjs +23 -0
- package/esm/locale/dk.es.js +22 -0
- package/esm/locale/dk.mjs +22 -0
- package/esm/locale/el.es.js +44 -0
- package/esm/locale/el.mjs +44 -0
- package/esm/locale/en.es.js +13 -0
- package/esm/locale/en.mjs +13 -0
- package/esm/locale/es.es.js +42 -0
- package/esm/locale/es.mjs +42 -0
- package/esm/locale/fa.es.js +39 -0
- package/esm/locale/fa.mjs +39 -0
- package/esm/locale/fr.es.js +23 -0
- package/esm/locale/fr.mjs +23 -0
- package/esm/locale/hi.es.js +50 -0
- package/esm/locale/hi.mjs +50 -0
- package/esm/locale/hu.es.js +23 -0
- package/esm/locale/hu.mjs +23 -0
- package/esm/locale/id.es.js +46 -0
- package/esm/locale/id.mjs +46 -0
- package/esm/locale/it.es.js +23 -0
- package/esm/locale/it.mjs +23 -0
- package/esm/locale/ja.es.js +31 -0
- package/esm/locale/ja.mjs +31 -0
- package/esm/locale/jv.es.js +46 -0
- package/esm/locale/jv.mjs +46 -0
- package/esm/locale/ko.es.js +23 -0
- package/esm/locale/ko.mjs +23 -0
- package/esm/locale/my.es.js +38 -0
- package/esm/locale/my.mjs +38 -0
- package/esm/locale/nl.es.js +37 -0
- package/esm/locale/nl.mjs +37 -0
- package/esm/locale/pa-in.es.js +62 -0
- package/esm/locale/pa-in.mjs +62 -0
- package/esm/locale/pl.es.js +37 -0
- package/esm/locale/pl.mjs +37 -0
- package/esm/locale/pt.es.js +44 -0
- package/esm/locale/pt.mjs +44 -0
- package/esm/locale/ro.es.js +22 -0
- package/esm/locale/ro.mjs +22 -0
- package/esm/locale/ru.es.js +44 -0
- package/esm/locale/ru.mjs +44 -0
- package/esm/locale/rw.es.js +22 -0
- package/esm/locale/rw.mjs +22 -0
- package/esm/locale/sr.es.js +22 -0
- package/esm/locale/sr.mjs +22 -0
- package/esm/locale/th.es.js +23 -0
- package/esm/locale/th.mjs +23 -0
- package/esm/locale/tr.es.js +22 -0
- package/esm/locale/tr.mjs +22 -0
- package/esm/locale/uk.es.js +57 -0
- package/esm/locale/uk.mjs +57 -0
- package/esm/locale/uz.es.js +22 -0
- package/esm/locale/uz.mjs +22 -0
- package/esm/locale/vi.es.js +23 -0
- package/esm/locale/vi.mjs +23 -0
- package/esm/locale/zh-cn.es.js +48 -0
- package/esm/locale/zh-cn.mjs +48 -0
- package/esm/locale/zh-tw.es.js +46 -0
- package/esm/locale/zh-tw.mjs +46 -0
- package/esm/plugin/day-of-week.es.js +19 -0
- package/esm/plugin/day-of-week.mjs +19 -0
- package/esm/plugin/meridiem.es.js +47 -0
- package/esm/plugin/meridiem.mjs +47 -0
- package/esm/plugin/microsecond.es.js +31 -0
- package/esm/plugin/microsecond.mjs +31 -0
- package/esm/plugin/ordinal.es.js +34 -0
- package/esm/plugin/ordinal.mjs +34 -0
- package/esm/plugin/timespan.es.js +75 -0
- package/esm/plugin/timespan.mjs +75 -0
- package/esm/plugin/timezone.es.js +73 -0
- package/esm/plugin/timezone.mjs +73 -0
- package/esm/plugin/two-digit-year.es.js +21 -0
- package/esm/plugin/two-digit-year.mjs +21 -0
- package/locale/ar.js +14 -19
- package/locale/az.js +14 -19
- package/locale/bn.js +14 -19
- package/locale/cs.js +14 -19
- package/locale/de.js +15 -20
- package/locale/dk.js +15 -20
- package/locale/el.js +21 -24
- package/locale/en.js +17 -19
- package/locale/es.js +14 -19
- package/locale/fa.js +14 -19
- package/locale/fr.js +14 -19
- package/locale/hi.js +14 -19
- package/locale/hu.js +14 -19
- package/locale/id.js +14 -19
- package/locale/it.js +14 -19
- package/locale/ja.js +14 -19
- package/locale/jv.js +14 -19
- package/locale/ko.js +14 -19
- package/locale/my.js +14 -19
- package/locale/nl.js +20 -23
- package/locale/pa-in.js +14 -19
- package/locale/pl.js +20 -23
- package/locale/pt.js +14 -19
- package/locale/ro.js +15 -20
- package/locale/ru.js +14 -19
- package/locale/rw.js +30 -0
- package/locale/sr.js +14 -19
- package/locale/th.js +14 -19
- package/locale/tr.js +14 -19
- package/locale/uk.js +23 -26
- package/locale/uz.js +14 -19
- package/locale/vi.js +14 -19
- package/locale/zh-cn.js +14 -19
- package/locale/zh-tw.js +14 -19
- package/package.json +26 -11
- package/plugin/day-of-week.js +13 -14
- package/plugin/meridiem.js +32 -24
- package/plugin/microsecond.js +14 -15
- package/plugin/ordinal.js +13 -14
- package/plugin/timespan.js +13 -14
- package/plugin/timezone.js +81 -0
- package/plugin/two-digit-year.js +13 -19
package/EXTEND.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Extension
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The easiest way to extend the default formatter and parser is to use plugins, but if the existing plugins do not meet your requirements, you can extend them yourself.
|
|
4
4
|
|
|
5
5
|
## Token
|
|
6
6
|
|
|
@@ -23,12 +23,26 @@ Tokens in this library have the following rules:
|
|
|
23
23
|
'Eee' // Not good
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
-
|
|
26
|
+
- Only tokens consisting of the following alphabets can be added to the parser.
|
|
27
27
|
|
|
28
28
|
```javascript
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
29
|
+
'Y' // Year
|
|
30
|
+
'M' // Month
|
|
31
|
+
'D' // Day
|
|
32
|
+
'H' // 24-hour
|
|
33
|
+
'A' // AM PM
|
|
34
|
+
'h' // 12-hour
|
|
35
|
+
's' // Second
|
|
36
|
+
'S' // Millisecond
|
|
37
|
+
'Z' // Timezone offset
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- Existing tokens cannot be overwritten.
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
'YYY' // This is OK because the same token does not exists.
|
|
44
|
+
'SSS' // This cannot be added because the exact same token exists.
|
|
45
|
+
'EEE' // This is OK for the formatter, but cannot be added to the parser.
|
|
32
46
|
```
|
|
33
47
|
|
|
34
48
|
## Examples
|
|
@@ -61,12 +75,12 @@ date.extend({
|
|
|
61
75
|
|
|
62
76
|
### Example 2
|
|
63
77
|
|
|
64
|
-
|
|
78
|
+
Add `MMMMM` token to the parser. This token ignores case:
|
|
65
79
|
|
|
66
80
|
```javascript
|
|
67
|
-
date.parse('Dec 25 2019', '
|
|
68
|
-
date.parse('dec 25 2019', '
|
|
69
|
-
date.parse('DEC 25 2019', '
|
|
81
|
+
date.parse('Dec 25 2019', 'MMMMM DD YYYY'); // => December 25, 2019
|
|
82
|
+
date.parse('dec 25 2019', 'MMMMM DD YYYY'); // => December 25, 2019
|
|
83
|
+
date.parse('DEC 25 2019', 'MMMMM DD YYYY'); // => December 25, 2019
|
|
70
84
|
```
|
|
71
85
|
|
|
72
86
|
Source code example is here:
|
|
@@ -76,7 +90,7 @@ const date = require('date-and-time');
|
|
|
76
90
|
|
|
77
91
|
date.extend({
|
|
78
92
|
parser: {
|
|
79
|
-
|
|
93
|
+
MMMMM: function (str) {
|
|
80
94
|
const mmm = this.res.MMM.map(m => m.toLowerCase());
|
|
81
95
|
const result = this.find(mmm, str.toLowerCase());
|
|
82
96
|
result.value++;
|
|
@@ -86,4 +100,8 @@ date.extend({
|
|
|
86
100
|
});
|
|
87
101
|
```
|
|
88
102
|
|
|
89
|
-
|
|
103
|
+
Extending the parser may be a bit difficult. Refer to the library source code to grasp the default behavior.
|
|
104
|
+
|
|
105
|
+
## Caveats
|
|
106
|
+
|
|
107
|
+
Note that switching locales or applying plugins after extending the library will be cleared all extensions. In such cases, you need to extend the library again.
|
package/LOCALE.md
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
# Locale
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
By default, `format()` outputs month, day of week, and meridiem (AM / PM) in English, and functions such as `parse()` assume that a passed date time string is in English. Here it describes how to use other languages in these functions.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- ES Modules:
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
import date from 'date-and-time';
|
|
11
|
+
import es from 'date-and-time/locale/es';
|
|
12
|
+
|
|
13
|
+
date.locale(es); // Spanish
|
|
14
|
+
date.format(new Date(), 'dddd D MMMM'); // => 'lunes 11 enero
|
|
15
|
+
```
|
|
8
16
|
|
|
9
17
|
- CommonJS:
|
|
10
18
|
|
|
@@ -16,20 +24,20 @@ date.locale(fr); // French
|
|
|
16
24
|
date.format(new Date(), 'dddd D MMMM'); // => 'lundi 11 janvier'
|
|
17
25
|
```
|
|
18
26
|
|
|
19
|
-
- ES Modules
|
|
27
|
+
- ES Modules for the browser:
|
|
20
28
|
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
import
|
|
29
|
+
```html
|
|
30
|
+
<script type="module">
|
|
31
|
+
import date from '/path/to/date-and-time.es.min.js';
|
|
32
|
+
import it from '/path/to/date-and-time/locale/it.es.js';
|
|
24
33
|
|
|
25
34
|
date.locale(it); // Italian
|
|
26
35
|
date.format(new Date(), 'dddd D MMMM'); // => 'Lunedì 11 gennaio'
|
|
36
|
+
</script>
|
|
27
37
|
```
|
|
28
38
|
|
|
29
39
|
- Older browser:
|
|
30
40
|
|
|
31
|
-
When in older browser, pass the locale string as before. (no changes)
|
|
32
|
-
|
|
33
41
|
```html
|
|
34
42
|
<script src="/path/to/date-and-time.min.js"></script>
|
|
35
43
|
<script src="/path/to/locale/zh-cn.js"></script>
|
|
@@ -42,9 +50,9 @@ date.format(new Date(), 'MMMD日dddd'); // => '1月11日星期一'
|
|
|
42
50
|
|
|
43
51
|
### NOTE
|
|
44
52
|
|
|
45
|
-
-
|
|
53
|
+
- If you want to use ES Modules in Node.js without a transpiler, you need to add `"type": "module"` in your `package.json` or change your file extension from `.js` to `.mjs`.
|
|
46
54
|
- The locale will be actually switched after executing the `locale()`.
|
|
47
|
-
- You can also change the locale back to English by
|
|
55
|
+
- You can also change the locale back to English by importing `en` locale:
|
|
48
56
|
|
|
49
57
|
```javascript
|
|
50
58
|
import en from 'date-and-time/locale/en';
|
|
@@ -52,30 +60,6 @@ import en from 'date-and-time/locale/en';
|
|
|
52
60
|
date.locale(en);
|
|
53
61
|
```
|
|
54
62
|
|
|
55
|
-
### FYI
|
|
56
|
-
|
|
57
|
-
The following (old) methods are deprecated. In the next version it won't be able to use them.
|
|
58
|
-
|
|
59
|
-
- CommonJS:
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
const date = require('date-and-time');
|
|
63
|
-
require('date-and-time/locale/fr');
|
|
64
|
-
|
|
65
|
-
date.locale('fr'); // French
|
|
66
|
-
date.format(new Date(), 'dddd D MMMM'); // => 'lundi 11 janvier'
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
- ES Modules (with transpile):
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
import date from 'date-and-time';
|
|
73
|
-
import 'date-and-time/locale/it';
|
|
74
|
-
|
|
75
|
-
date.locale('it'); // Italian
|
|
76
|
-
date.format(new Date(), 'dddd D MMMM'); // => 'Lunedì 11 gennaio'
|
|
77
|
-
```
|
|
78
|
-
|
|
79
63
|
## Supported locale List
|
|
80
64
|
|
|
81
65
|
At this time, it supports the following locales:
|
|
@@ -100,6 +84,7 @@ Indonesian (id)
|
|
|
100
84
|
Italian (it)
|
|
101
85
|
Japanese (ja)
|
|
102
86
|
Javanese (jv)
|
|
87
|
+
Kinyarwanda (rw)
|
|
103
88
|
Korean (ko)
|
|
104
89
|
Persian (fa)
|
|
105
90
|
Polish (pl)
|