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.
Files changed (133) hide show
  1. package/EXTEND.md +29 -11
  2. package/LOCALE.md +19 -34
  3. package/PLUGINS.md +222 -113
  4. package/README.md +203 -171
  5. package/date-and-time.js +171 -147
  6. package/date-and-time.min.js +14 -14
  7. package/esm/date-and-time.es.js +466 -0
  8. package/esm/date-and-time.es.min.js +17 -0
  9. package/esm/date-and-time.mjs +466 -0
  10. package/esm/locale/ar.es.js +39 -0
  11. package/esm/locale/ar.mjs +39 -0
  12. package/esm/locale/az.es.js +44 -0
  13. package/esm/locale/az.mjs +44 -0
  14. package/esm/locale/bn.es.js +50 -0
  15. package/esm/locale/bn.mjs +50 -0
  16. package/esm/locale/cs.es.js +22 -0
  17. package/esm/locale/cs.mjs +22 -0
  18. package/esm/locale/de.es.js +23 -0
  19. package/esm/locale/de.mjs +23 -0
  20. package/esm/locale/dk.es.js +22 -0
  21. package/esm/locale/dk.mjs +22 -0
  22. package/esm/locale/el.es.js +44 -0
  23. package/esm/locale/el.mjs +44 -0
  24. package/esm/locale/en.es.js +13 -0
  25. package/esm/locale/en.mjs +13 -0
  26. package/esm/locale/es.es.js +42 -0
  27. package/esm/locale/es.mjs +42 -0
  28. package/esm/locale/fa.es.js +39 -0
  29. package/esm/locale/fa.mjs +39 -0
  30. package/esm/locale/fr.es.js +23 -0
  31. package/esm/locale/fr.mjs +23 -0
  32. package/esm/locale/hi.es.js +50 -0
  33. package/esm/locale/hi.mjs +50 -0
  34. package/esm/locale/hu.es.js +23 -0
  35. package/esm/locale/hu.mjs +23 -0
  36. package/esm/locale/id.es.js +46 -0
  37. package/esm/locale/id.mjs +46 -0
  38. package/esm/locale/it.es.js +23 -0
  39. package/esm/locale/it.mjs +23 -0
  40. package/esm/locale/ja.es.js +31 -0
  41. package/esm/locale/ja.mjs +31 -0
  42. package/esm/locale/jv.es.js +46 -0
  43. package/esm/locale/jv.mjs +46 -0
  44. package/esm/locale/ko.es.js +23 -0
  45. package/esm/locale/ko.mjs +23 -0
  46. package/esm/locale/my.es.js +38 -0
  47. package/esm/locale/my.mjs +38 -0
  48. package/esm/locale/nl.es.js +37 -0
  49. package/esm/locale/nl.mjs +37 -0
  50. package/esm/locale/pa-in.es.js +62 -0
  51. package/esm/locale/pa-in.mjs +62 -0
  52. package/esm/locale/pl.es.js +37 -0
  53. package/esm/locale/pl.mjs +37 -0
  54. package/esm/locale/pt.es.js +44 -0
  55. package/esm/locale/pt.mjs +44 -0
  56. package/esm/locale/ro.es.js +22 -0
  57. package/esm/locale/ro.mjs +22 -0
  58. package/esm/locale/ru.es.js +44 -0
  59. package/esm/locale/ru.mjs +44 -0
  60. package/esm/locale/rw.es.js +22 -0
  61. package/esm/locale/rw.mjs +22 -0
  62. package/esm/locale/sr.es.js +22 -0
  63. package/esm/locale/sr.mjs +22 -0
  64. package/esm/locale/th.es.js +23 -0
  65. package/esm/locale/th.mjs +23 -0
  66. package/esm/locale/tr.es.js +22 -0
  67. package/esm/locale/tr.mjs +22 -0
  68. package/esm/locale/uk.es.js +57 -0
  69. package/esm/locale/uk.mjs +57 -0
  70. package/esm/locale/uz.es.js +22 -0
  71. package/esm/locale/uz.mjs +22 -0
  72. package/esm/locale/vi.es.js +23 -0
  73. package/esm/locale/vi.mjs +23 -0
  74. package/esm/locale/zh-cn.es.js +48 -0
  75. package/esm/locale/zh-cn.mjs +48 -0
  76. package/esm/locale/zh-tw.es.js +46 -0
  77. package/esm/locale/zh-tw.mjs +46 -0
  78. package/esm/plugin/day-of-week.es.js +19 -0
  79. package/esm/plugin/day-of-week.mjs +19 -0
  80. package/esm/plugin/meridiem.es.js +47 -0
  81. package/esm/plugin/meridiem.mjs +47 -0
  82. package/esm/plugin/microsecond.es.js +31 -0
  83. package/esm/plugin/microsecond.mjs +31 -0
  84. package/esm/plugin/ordinal.es.js +34 -0
  85. package/esm/plugin/ordinal.mjs +34 -0
  86. package/esm/plugin/timespan.es.js +75 -0
  87. package/esm/plugin/timespan.mjs +75 -0
  88. package/esm/plugin/timezone.es.js +73 -0
  89. package/esm/plugin/timezone.mjs +73 -0
  90. package/esm/plugin/two-digit-year.es.js +21 -0
  91. package/esm/plugin/two-digit-year.mjs +21 -0
  92. package/locale/ar.js +14 -19
  93. package/locale/az.js +14 -19
  94. package/locale/bn.js +14 -19
  95. package/locale/cs.js +14 -19
  96. package/locale/de.js +15 -20
  97. package/locale/dk.js +15 -20
  98. package/locale/el.js +21 -24
  99. package/locale/en.js +17 -19
  100. package/locale/es.js +14 -19
  101. package/locale/fa.js +14 -19
  102. package/locale/fr.js +14 -19
  103. package/locale/hi.js +14 -19
  104. package/locale/hu.js +14 -19
  105. package/locale/id.js +14 -19
  106. package/locale/it.js +14 -19
  107. package/locale/ja.js +14 -19
  108. package/locale/jv.js +14 -19
  109. package/locale/ko.js +14 -19
  110. package/locale/my.js +14 -19
  111. package/locale/nl.js +20 -23
  112. package/locale/pa-in.js +14 -19
  113. package/locale/pl.js +20 -23
  114. package/locale/pt.js +14 -19
  115. package/locale/ro.js +15 -20
  116. package/locale/ru.js +14 -19
  117. package/locale/rw.js +30 -0
  118. package/locale/sr.js +14 -19
  119. package/locale/th.js +14 -19
  120. package/locale/tr.js +14 -19
  121. package/locale/uk.js +23 -26
  122. package/locale/uz.js +14 -19
  123. package/locale/vi.js +14 -19
  124. package/locale/zh-cn.js +14 -19
  125. package/locale/zh-tw.js +14 -19
  126. package/package.json +26 -11
  127. package/plugin/day-of-week.js +13 -14
  128. package/plugin/meridiem.js +32 -24
  129. package/plugin/microsecond.js +14 -15
  130. package/plugin/ordinal.js +13 -14
  131. package/plugin/timespan.js +13 -14
  132. package/plugin/timezone.js +81 -0
  133. package/plugin/two-digit-year.js +13 -19
package/EXTEND.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Extension
2
2
 
3
- By using `extend()`, you could add your own tokens or modify behavior of existing tokens. This is equivalent to define a new plugin without name.
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
- - To the parser, it is not able to add token of new alphabet.
26
+ - Only tokens consisting of the following alphabets can be added to the parser.
27
27
 
28
28
  ```javascript
29
- 'EEE' // This is not able to add because `E` is not an existing token in the parser.
30
- 'YYY' // This is OK because `Y` token is existing in the parser.
31
- 'SSS' // This is modifying, not adding. Because exactly the same token is existing.
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
- In the parser, modify `MMM` token to ignore case:
78
+ Add `MMMMM` token to the parser. This token ignores case:
65
79
 
66
80
  ```javascript
67
- date.parse('Dec 25 2019', 'MMM DD YYYY'); // => December 25, 2019
68
- date.parse('dec 25 2019', 'MMM DD YYYY'); // => December 25, 2019
69
- date.parse('DEC 25 2019', 'MMM DD YYYY'); // => December 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
- MMM: function (str) {
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
- Modifying the parser may be a bit difficult. Refer to the library source code to grasp the default behavior.
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
- The `format()` outputs month, day of week, and meridiem (am / pm) in English, and the `parse()` assumes the passed date string is in English. Here it describes how to use other languages in these functions.
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
- To support `ES Modules` in the next version, the locale switching method has changed and then the old method has been deprecated.
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 (with transpile):
27
+ - ES Modules for the browser:
20
28
 
21
- ```javascript
22
- import date from 'date-and-time';
23
- import it from 'date-and-time/locale/it';
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
- - You have to import (or require) in advance the all locale modules that you are going to switch to.
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 loading the `en` module:
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)