@internationalized/date 3.12.0 → 3.12.2

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 (204) hide show
  1. package/dist/index.cjs +113 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.js +45 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +45 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/private/CalendarDate.cjs +272 -0
  8. package/dist/private/CalendarDate.cjs.map +1 -0
  9. package/dist/private/CalendarDate.js +282 -0
  10. package/dist/private/CalendarDate.js.map +1 -0
  11. package/dist/private/CalendarDate.mjs +264 -0
  12. package/dist/private/CalendarDate.mjs.map +1 -0
  13. package/dist/{DateFormatter.main.js → private/DateFormatter.cjs} +31 -28
  14. package/dist/private/DateFormatter.cjs.map +1 -0
  15. package/dist/{DateFormatter.module.js → private/DateFormatter.js} +27 -24
  16. package/dist/private/DateFormatter.js.map +1 -0
  17. package/dist/{DateFormatter.mjs → private/DateFormatter.mjs} +31 -28
  18. package/dist/private/DateFormatter.mjs.map +1 -0
  19. package/dist/{BuddhistCalendar.main.js → private/calendars/BuddhistCalendar.cjs} +13 -13
  20. package/dist/{BuddhistCalendar.main.js.map → private/calendars/BuddhistCalendar.cjs.map} +1 -1
  21. package/dist/{BuddhistCalendar.module.js → private/calendars/BuddhistCalendar.js} +13 -13
  22. package/dist/{BuddhistCalendar.module.js.map → private/calendars/BuddhistCalendar.js.map} +1 -1
  23. package/dist/{BuddhistCalendar.mjs → private/calendars/BuddhistCalendar.mjs} +13 -13
  24. package/dist/private/calendars/BuddhistCalendar.mjs.map +1 -0
  25. package/dist/{EthiopicCalendar.main.js → private/calendars/EthiopicCalendar.cjs} +37 -37
  26. package/dist/private/calendars/EthiopicCalendar.cjs.map +1 -0
  27. package/dist/{EthiopicCalendar.module.js → private/calendars/EthiopicCalendar.js} +35 -35
  28. package/dist/private/calendars/EthiopicCalendar.js.map +1 -0
  29. package/dist/{EthiopicCalendar.mjs → private/calendars/EthiopicCalendar.mjs} +35 -35
  30. package/dist/private/calendars/EthiopicCalendar.mjs.map +1 -0
  31. package/dist/{GregorianCalendar.main.js → private/calendars/GregorianCalendar.cjs} +31 -31
  32. package/dist/private/calendars/GregorianCalendar.cjs.map +1 -0
  33. package/dist/{GregorianCalendar.module.js → private/calendars/GregorianCalendar.js} +27 -27
  34. package/dist/private/calendars/GregorianCalendar.js.map +1 -0
  35. package/dist/{GregorianCalendar.mjs → private/calendars/GregorianCalendar.mjs} +27 -27
  36. package/dist/private/calendars/GregorianCalendar.mjs.map +1 -0
  37. package/dist/{HebrewCalendar.main.js → private/calendars/HebrewCalendar.cjs} +44 -44
  38. package/dist/private/calendars/HebrewCalendar.cjs.map +1 -0
  39. package/dist/{HebrewCalendar.module.js → private/calendars/HebrewCalendar.js} +44 -44
  40. package/dist/private/calendars/HebrewCalendar.js.map +1 -0
  41. package/dist/{HebrewCalendar.mjs → private/calendars/HebrewCalendar.mjs} +44 -44
  42. package/dist/private/calendars/HebrewCalendar.mjs.map +1 -0
  43. package/dist/{IndianCalendar.main.js → private/calendars/IndianCalendar.cjs} +20 -20
  44. package/dist/private/calendars/IndianCalendar.cjs.map +1 -0
  45. package/dist/{IndianCalendar.module.js → private/calendars/IndianCalendar.js} +20 -20
  46. package/dist/private/calendars/IndianCalendar.js.map +1 -0
  47. package/dist/{IndianCalendar.mjs → private/calendars/IndianCalendar.mjs} +20 -20
  48. package/dist/private/calendars/IndianCalendar.mjs.map +1 -0
  49. package/dist/private/calendars/IslamicCalendar.cjs +168 -0
  50. package/dist/private/calendars/IslamicCalendar.cjs.map +1 -0
  51. package/dist/private/calendars/IslamicCalendar.js +161 -0
  52. package/dist/private/calendars/IslamicCalendar.js.map +1 -0
  53. package/dist/private/calendars/IslamicCalendar.mjs +161 -0
  54. package/dist/private/calendars/IslamicCalendar.mjs.map +1 -0
  55. package/dist/{JapaneseCalendar.main.js → private/calendars/JapaneseCalendar.cjs} +37 -37
  56. package/dist/private/calendars/JapaneseCalendar.cjs.map +1 -0
  57. package/dist/{JapaneseCalendar.module.js → private/calendars/JapaneseCalendar.js} +37 -37
  58. package/dist/private/calendars/JapaneseCalendar.js.map +1 -0
  59. package/dist/{JapaneseCalendar.mjs → private/calendars/JapaneseCalendar.mjs} +37 -37
  60. package/dist/private/calendars/JapaneseCalendar.mjs.map +1 -0
  61. package/dist/{PersianCalendar.main.js → private/calendars/PersianCalendar.cjs} +13 -13
  62. package/dist/private/calendars/PersianCalendar.cjs.map +1 -0
  63. package/dist/{PersianCalendar.module.js → private/calendars/PersianCalendar.js} +13 -13
  64. package/dist/private/calendars/PersianCalendar.js.map +1 -0
  65. package/dist/{PersianCalendar.mjs → private/calendars/PersianCalendar.mjs} +13 -13
  66. package/dist/private/calendars/PersianCalendar.mjs.map +1 -0
  67. package/dist/{TaiwanCalendar.main.js → private/calendars/TaiwanCalendar.cjs} +20 -20
  68. package/dist/{TaiwanCalendar.main.js.map → private/calendars/TaiwanCalendar.cjs.map} +1 -1
  69. package/dist/private/calendars/TaiwanCalendar.js +75 -0
  70. package/dist/{TaiwanCalendar.module.js.map → private/calendars/TaiwanCalendar.js.map} +1 -1
  71. package/dist/{TaiwanCalendar.mjs → private/calendars/TaiwanCalendar.mjs} +20 -20
  72. package/dist/private/calendars/TaiwanCalendar.mjs.map +1 -0
  73. package/dist/{conversion.main.js → private/conversion.cjs} +85 -85
  74. package/dist/private/conversion.cjs.map +1 -0
  75. package/dist/{conversion.module.js → private/conversion.js} +71 -71
  76. package/dist/private/conversion.js.map +1 -0
  77. package/dist/{conversion.mjs → private/conversion.mjs} +71 -71
  78. package/dist/private/conversion.mjs.map +1 -0
  79. package/dist/private/createCalendar.cjs +69 -0
  80. package/dist/private/createCalendar.cjs.map +1 -0
  81. package/dist/private/createCalendar.js +64 -0
  82. package/dist/private/createCalendar.js.map +1 -0
  83. package/dist/private/createCalendar.mjs +64 -0
  84. package/dist/private/createCalendar.mjs.map +1 -0
  85. package/dist/{manipulation.main.js → private/manipulation.cjs} +106 -109
  86. package/dist/private/manipulation.cjs.map +1 -0
  87. package/dist/{manipulation.mjs → private/manipulation.js} +88 -88
  88. package/dist/private/manipulation.js.map +1 -0
  89. package/dist/{manipulation.module.js → private/manipulation.mjs} +93 -96
  90. package/dist/private/manipulation.mjs.map +1 -0
  91. package/dist/private/queries.cjs +359 -0
  92. package/dist/private/queries.cjs.map +1 -0
  93. package/dist/private/queries.js +326 -0
  94. package/dist/private/queries.js.map +1 -0
  95. package/dist/private/queries.mjs +324 -0
  96. package/dist/private/queries.mjs.map +1 -0
  97. package/dist/private/string.cjs +181 -0
  98. package/dist/private/string.cjs.map +1 -0
  99. package/dist/{string.mjs → private/string.js} +64 -64
  100. package/dist/private/string.js.map +1 -0
  101. package/dist/private/string.mjs +166 -0
  102. package/dist/private/string.mjs.map +1 -0
  103. package/dist/{utils.main.js → private/utils.cjs} +3 -3
  104. package/dist/{utils.main.js.map → private/utils.cjs.map} +1 -1
  105. package/dist/{utils.module.js → private/utils.js} +3 -3
  106. package/dist/{utils.module.js.map → private/utils.js.map} +1 -1
  107. package/dist/{utils.mjs → private/utils.mjs} +3 -3
  108. package/dist/private/utils.mjs.map +1 -0
  109. package/dist/{weekStartData.main.js → private/weekStartData.cjs} +3 -3
  110. package/dist/{weekStartData.main.js.map → private/weekStartData.cjs.map} +1 -1
  111. package/dist/{weekStartData.module.js → private/weekStartData.js} +3 -3
  112. package/dist/{weekStartData.module.js.map → private/weekStartData.js.map} +1 -1
  113. package/dist/{weekStartData.mjs → private/weekStartData.mjs} +3 -3
  114. package/dist/private/weekStartData.mjs.map +1 -0
  115. package/dist/types/src/CalendarDate.d.ts +207 -0
  116. package/dist/types/src/DateFormatter.d.ts +24 -0
  117. package/dist/types/src/calendars/BuddhistCalendar.d.ts +16 -0
  118. package/dist/types/src/calendars/EthiopicCalendar.d.ts +45 -0
  119. package/dist/types/src/calendars/GregorianCalendar.d.ts +26 -0
  120. package/dist/types/src/calendars/HebrewCalendar.d.ts +21 -0
  121. package/dist/types/src/calendars/IndianCalendar.d.ts +17 -0
  122. package/dist/types/src/calendars/IslamicCalendar.d.ts +51 -0
  123. package/dist/types/src/calendars/JapaneseCalendar.d.ts +22 -0
  124. package/dist/types/src/calendars/PersianCalendar.d.ts +19 -0
  125. package/dist/types/src/calendars/TaiwanCalendar.d.ts +19 -0
  126. package/dist/types/src/conversion.d.ts +45 -0
  127. package/dist/types/src/createCalendar.d.ts +3 -0
  128. package/dist/types/src/index.d.ts +17 -0
  129. package/dist/types/src/manipulation.d.ts +25 -0
  130. package/dist/types/src/queries.d.ts +93 -0
  131. package/dist/types/src/string.d.ts +36 -0
  132. package/dist/types/src/types.d.ts +136 -0
  133. package/dist/types/src/utils.d.ts +4 -0
  134. package/dist/types/src/weekStartData.d.ts +97 -0
  135. package/package.json +33 -18
  136. package/src/CalendarDate.ts +215 -35
  137. package/src/DateFormatter.ts +36 -16
  138. package/src/calendars/BuddhistCalendar.ts +1 -6
  139. package/src/calendars/EthiopicCalendar.ts +6 -5
  140. package/src/calendars/GregorianCalendar.ts +11 -4
  141. package/src/calendars/HebrewCalendar.ts +8 -4
  142. package/src/calendars/IndianCalendar.ts +8 -3
  143. package/src/calendars/IslamicCalendar.ts +40 -25
  144. package/src/calendars/JapaneseCalendar.ts +18 -10
  145. package/src/calendars/PersianCalendar.ts +2 -4
  146. package/src/calendars/TaiwanCalendar.ts +2 -9
  147. package/src/conversion.ts +98 -25
  148. package/src/createCalendar.ts +10 -2
  149. package/src/index.ts +11 -2
  150. package/src/manipulation.ts +133 -30
  151. package/src/queries.ts +57 -15
  152. package/src/string.ts +52 -25
  153. package/src/types.ts +73 -51
  154. package/src/utils.ts +1 -1
  155. package/dist/CalendarDate.main.js +0 -260
  156. package/dist/CalendarDate.main.js.map +0 -1
  157. package/dist/CalendarDate.mjs +0 -252
  158. package/dist/CalendarDate.module.js +0 -252
  159. package/dist/CalendarDate.module.js.map +0 -1
  160. package/dist/DateFormatter.main.js.map +0 -1
  161. package/dist/DateFormatter.module.js.map +0 -1
  162. package/dist/EthiopicCalendar.main.js.map +0 -1
  163. package/dist/EthiopicCalendar.module.js.map +0 -1
  164. package/dist/GregorianCalendar.main.js.map +0 -1
  165. package/dist/GregorianCalendar.module.js.map +0 -1
  166. package/dist/HebrewCalendar.main.js.map +0 -1
  167. package/dist/HebrewCalendar.module.js.map +0 -1
  168. package/dist/IndianCalendar.main.js.map +0 -1
  169. package/dist/IndianCalendar.module.js.map +0 -1
  170. package/dist/IslamicCalendar.main.js +0 -168
  171. package/dist/IslamicCalendar.main.js.map +0 -1
  172. package/dist/IslamicCalendar.mjs +0 -161
  173. package/dist/IslamicCalendar.module.js +0 -161
  174. package/dist/IslamicCalendar.module.js.map +0 -1
  175. package/dist/JapaneseCalendar.main.js.map +0 -1
  176. package/dist/JapaneseCalendar.module.js.map +0 -1
  177. package/dist/PersianCalendar.main.js.map +0 -1
  178. package/dist/PersianCalendar.module.js.map +0 -1
  179. package/dist/TaiwanCalendar.module.js +0 -75
  180. package/dist/conversion.main.js.map +0 -1
  181. package/dist/conversion.module.js.map +0 -1
  182. package/dist/createCalendar.main.js +0 -69
  183. package/dist/createCalendar.main.js.map +0 -1
  184. package/dist/createCalendar.mjs +0 -64
  185. package/dist/createCalendar.module.js +0 -64
  186. package/dist/createCalendar.module.js.map +0 -1
  187. package/dist/import.mjs +0 -45
  188. package/dist/main.js +0 -113
  189. package/dist/main.js.map +0 -1
  190. package/dist/manipulation.main.js.map +0 -1
  191. package/dist/manipulation.module.js.map +0 -1
  192. package/dist/module.js +0 -45
  193. package/dist/module.js.map +0 -1
  194. package/dist/queries.main.js +0 -361
  195. package/dist/queries.main.js.map +0 -1
  196. package/dist/queries.mjs +0 -326
  197. package/dist/queries.module.js +0 -326
  198. package/dist/queries.module.js.map +0 -1
  199. package/dist/string.main.js +0 -190
  200. package/dist/string.main.js.map +0 -1
  201. package/dist/string.module.js +0 -175
  202. package/dist/string.module.js.map +0 -1
  203. package/dist/types.d.ts +0 -672
  204. package/dist/types.d.ts.map +0 -1
@@ -10,17 +10,46 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {add, addTime, addZoned, constrain, constrainTime, cycleDate, cycleTime, cycleZoned, set, setTime, setZoned, subtract, subtractTime, subtractZoned} from './manipulation';
14
- import {AnyCalendarDate, AnyTime, Calendar, CycleOptions, CycleTimeOptions, DateDuration, DateField, DateFields, DateTimeDuration, Disambiguation, TimeDuration, TimeField, TimeFields} from './types';
13
+ import {
14
+ add,
15
+ addTime,
16
+ addZoned,
17
+ constrain,
18
+ constrainTime,
19
+ cycleDate,
20
+ cycleTime,
21
+ cycleZoned,
22
+ set,
23
+ setTime,
24
+ setZoned,
25
+ subtract,
26
+ subtractTime,
27
+ subtractZoned
28
+ } from './manipulation';
29
+ import {
30
+ AnyCalendarDate,
31
+ AnyTime,
32
+ Calendar,
33
+ CycleOptions,
34
+ CycleTimeOptions,
35
+ DateDuration,
36
+ DateField,
37
+ DateFields,
38
+ DateTimeDuration,
39
+ Disambiguation,
40
+ TimeDuration,
41
+ TimeField,
42
+ TimeFields
43
+ } from './types';
15
44
  import {compareDate, compareTime} from './queries';
16
45
  import {dateTimeToString, dateToString, timeToString, zonedDateTimeToString} from './string';
17
46
  import {GregorianCalendar} from './calendars/GregorianCalendar';
18
47
  import {toCalendarDateTime, toDate, toZoned, zonedToDate} from './conversion';
19
48
 
49
+ export type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
50
+
20
51
  function shiftArgs(args: any[]) {
21
- let calendar: Calendar = typeof args[0] === 'object'
22
- ? args.shift()
23
- : new GregorianCalendar();
52
+ let calendar: Calendar = typeof args[0] === 'object' ? args.shift() : new GregorianCalendar();
24
53
 
25
54
  let era: string;
26
55
  if (typeof args[0] === 'string') {
@@ -93,7 +122,10 @@ export class CalendarDate {
93
122
  return subtract(this, duration);
94
123
  }
95
124
 
96
- /** Returns a new `CalendarDate` with the given fields set to the provided values. Other fields will be constrained accordingly. */
125
+ /**
126
+ * Returns a new `CalendarDate` with the given fields set to the provided values. Other fields
127
+ * will be constrained accordingly.
128
+ */
97
129
  set(fields: DateFields): CalendarDate {
98
130
  return set(this, fields);
99
131
  }
@@ -106,7 +138,10 @@ export class CalendarDate {
106
138
  return cycleDate(this, field, amount, options);
107
139
  }
108
140
 
109
- /** Converts the date to a native JavaScript Date object, with the time set to midnight in the given time zone. */
141
+ /**
142
+ * Converts the date to a native JavaScript Date object, with the time set to midnight in the
143
+ * given time zone.
144
+ */
110
145
  toDate(timeZone: string): Date {
111
146
  return toDate(this, timeZone);
112
147
  }
@@ -116,7 +151,10 @@ export class CalendarDate {
116
151
  return dateToString(this);
117
152
  }
118
153
 
119
- /** Compares this date with another. A negative result indicates that this date is before the given one, and a positive date indicates that it is after. */
154
+ /**
155
+ * Compares this date with another. A negative result indicates that this date is before the given
156
+ * one, and a positive date indicates that it is after.
157
+ */
120
158
  compare(b: AnyCalendarDate): number {
121
159
  return compareDate(this, b);
122
160
  }
@@ -136,12 +174,7 @@ export class Time {
136
174
  /** The millisecond in the second. */
137
175
  public readonly millisecond: number;
138
176
 
139
- constructor(
140
- hour: number = 0,
141
- minute: number = 0,
142
- second: number = 0,
143
- millisecond: number = 0
144
- ) {
177
+ constructor(hour: number = 0, minute: number = 0, second: number = 0, millisecond: number = 0) {
145
178
  this.hour = hour;
146
179
  this.minute = minute;
147
180
  this.second = second;
@@ -164,7 +197,10 @@ export class Time {
164
197
  return subtractTime(this, duration);
165
198
  }
166
199
 
167
- /** Returns a new `Time` with the given fields set to the provided values. Other fields will be constrained accordingly. */
200
+ /**
201
+ * Returns a new `Time` with the given fields set to the provided values. Other fields will be
202
+ * constrained accordingly.
203
+ */
168
204
  set(fields: TimeFields): Time {
169
205
  return setTime(this, fields);
170
206
  }
@@ -182,7 +218,10 @@ export class Time {
182
218
  return timeToString(this);
183
219
  }
184
220
 
185
- /** Compares this time with another. A negative result indicates that this time is before the given one, and a positive time indicates that it is after. */
221
+ /**
222
+ * Compares this time with another. A negative result indicates that this time is before the given
223
+ * one, and a positive time indicates that it is after.
224
+ */
186
225
  compare(b: AnyTime): number {
187
226
  return compareTime(this, b);
188
227
  }
@@ -216,10 +255,46 @@ export class CalendarDateTime {
216
255
  /** The millisecond in the second. */
217
256
  public readonly millisecond: number;
218
257
 
219
- constructor(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number);
220
- constructor(era: string, year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number);
221
- constructor(calendar: Calendar, year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number);
222
- constructor(calendar: Calendar, era: string, year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number);
258
+ constructor(
259
+ year: number,
260
+ month: number,
261
+ day: number,
262
+ hour?: number,
263
+ minute?: number,
264
+ second?: number,
265
+ millisecond?: number
266
+ );
267
+ constructor(
268
+ era: string,
269
+ year: number,
270
+ month: number,
271
+ day: number,
272
+ hour?: number,
273
+ minute?: number,
274
+ second?: number,
275
+ millisecond?: number
276
+ );
277
+ constructor(
278
+ calendar: Calendar,
279
+ year: number,
280
+ month: number,
281
+ day: number,
282
+ hour?: number,
283
+ minute?: number,
284
+ second?: number,
285
+ millisecond?: number
286
+ );
287
+ constructor(
288
+ calendar: Calendar,
289
+ era: string,
290
+ year: number,
291
+ month: number,
292
+ day: number,
293
+ hour?: number,
294
+ minute?: number,
295
+ second?: number,
296
+ millisecond?: number
297
+ );
223
298
  constructor(...args: any[]) {
224
299
  let [calendar, era, year, month, day] = shiftArgs(args);
225
300
  this.calendar = calendar;
@@ -238,9 +313,28 @@ export class CalendarDateTime {
238
313
  /** Returns a copy of this date. */
239
314
  copy(): CalendarDateTime {
240
315
  if (this.era) {
241
- return new CalendarDateTime(this.calendar, this.era, this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
316
+ return new CalendarDateTime(
317
+ this.calendar,
318
+ this.era,
319
+ this.year,
320
+ this.month,
321
+ this.day,
322
+ this.hour,
323
+ this.minute,
324
+ this.second,
325
+ this.millisecond
326
+ );
242
327
  } else {
243
- return new CalendarDateTime(this.calendar, this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
328
+ return new CalendarDateTime(
329
+ this.calendar,
330
+ this.year,
331
+ this.month,
332
+ this.day,
333
+ this.hour,
334
+ this.minute,
335
+ this.second,
336
+ this.millisecond
337
+ );
244
338
  }
245
339
  }
246
340
 
@@ -254,7 +348,10 @@ export class CalendarDateTime {
254
348
  return subtract(this, duration);
255
349
  }
256
350
 
257
- /** Returns a new `CalendarDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */
351
+ /**
352
+ * Returns a new `CalendarDateTime` with the given fields set to the provided values. Other fields
353
+ * will be constrained accordingly.
354
+ */
258
355
  set(fields: DateFields & TimeFields): CalendarDateTime {
259
356
  return set(setTime(this, fields), fields);
260
357
  }
@@ -263,7 +360,11 @@ export class CalendarDateTime {
263
360
  * Returns a new `CalendarDateTime` with the given field adjusted by a specified amount.
264
361
  * When the resulting value reaches the limits of the field, it wraps around.
265
362
  */
266
- cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions): CalendarDateTime {
363
+ cycle(
364
+ field: DateField | TimeField,
365
+ amount: number,
366
+ options?: CycleTimeOptions
367
+ ): CalendarDateTime {
267
368
  switch (field) {
268
369
  case 'era':
269
370
  case 'year':
@@ -285,7 +386,10 @@ export class CalendarDateTime {
285
386
  return dateTimeToString(this);
286
387
  }
287
388
 
288
- /** Compares this date with another. A negative result indicates that this date is before the given one, and a positive date indicates that it is after. */
389
+ /**
390
+ * Compares this date with another. A negative result indicates that this date is before the given
391
+ * one, and a positive date indicates that it is after.
392
+ */
289
393
  compare(b: CalendarDate | CalendarDateTime | ZonedDateTime): number {
290
394
  let res = compareDate(this, b);
291
395
  if (res === 0) {
@@ -328,10 +432,54 @@ export class ZonedDateTime {
328
432
  /** The UTC offset for this time, in milliseconds. */
329
433
  public readonly offset: number;
330
434
 
331
- constructor(year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
332
- constructor(era: string, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
333
- constructor(calendar: Calendar, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
334
- constructor(calendar: Calendar, era: string, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
435
+ constructor(
436
+ year: number,
437
+ month: number,
438
+ day: number,
439
+ timeZone: string,
440
+ offset: number,
441
+ hour?: number,
442
+ minute?: number,
443
+ second?: number,
444
+ millisecond?: number
445
+ );
446
+ constructor(
447
+ era: string,
448
+ year: number,
449
+ month: number,
450
+ day: number,
451
+ timeZone: string,
452
+ offset: number,
453
+ hour?: number,
454
+ minute?: number,
455
+ second?: number,
456
+ millisecond?: number
457
+ );
458
+ constructor(
459
+ calendar: Calendar,
460
+ year: number,
461
+ month: number,
462
+ day: number,
463
+ timeZone: string,
464
+ offset: number,
465
+ hour?: number,
466
+ minute?: number,
467
+ second?: number,
468
+ millisecond?: number
469
+ );
470
+ constructor(
471
+ calendar: Calendar,
472
+ era: string,
473
+ year: number,
474
+ month: number,
475
+ day: number,
476
+ timeZone: string,
477
+ offset: number,
478
+ hour?: number,
479
+ minute?: number,
480
+ second?: number,
481
+ millisecond?: number
482
+ );
335
483
  constructor(...args: any[]) {
336
484
  let [calendar, era, year, month, day] = shiftArgs(args);
337
485
  let timeZone = args.shift();
@@ -354,9 +502,32 @@ export class ZonedDateTime {
354
502
  /** Returns a copy of this date. */
355
503
  copy(): ZonedDateTime {
356
504
  if (this.era) {
357
- return new ZonedDateTime(this.calendar, this.era, this.year, this.month, this.day, this.timeZone, this.offset, this.hour, this.minute, this.second, this.millisecond);
505
+ return new ZonedDateTime(
506
+ this.calendar,
507
+ this.era,
508
+ this.year,
509
+ this.month,
510
+ this.day,
511
+ this.timeZone,
512
+ this.offset,
513
+ this.hour,
514
+ this.minute,
515
+ this.second,
516
+ this.millisecond
517
+ );
358
518
  } else {
359
- return new ZonedDateTime(this.calendar, this.year, this.month, this.day, this.timeZone, this.offset, this.hour, this.minute, this.second, this.millisecond);
519
+ return new ZonedDateTime(
520
+ this.calendar,
521
+ this.year,
522
+ this.month,
523
+ this.day,
524
+ this.timeZone,
525
+ this.offset,
526
+ this.hour,
527
+ this.minute,
528
+ this.second,
529
+ this.millisecond
530
+ );
360
531
  }
361
532
  }
362
533
 
@@ -370,7 +541,10 @@ export class ZonedDateTime {
370
541
  return subtractZoned(this, duration);
371
542
  }
372
543
 
373
- /** Returns a new `ZonedDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */
544
+ /**
545
+ * Returns a new `ZonedDateTime` with the given fields set to the provided values. Other fields
546
+ * will be constrained accordingly.
547
+ */
374
548
  set(fields: DateFields & TimeFields, disambiguation?: Disambiguation): ZonedDateTime {
375
549
  return setZoned(this, fields, disambiguation);
376
550
  }
@@ -388,17 +562,23 @@ export class ZonedDateTime {
388
562
  return zonedToDate(this);
389
563
  }
390
564
 
391
- /** Converts the date to an ISO 8601 formatted string, including the UTC offset and time zone identifier. */
565
+ /**
566
+ * Converts the date to an ISO 8601 formatted string, including the UTC offset and time zone
567
+ * identifier.
568
+ */
392
569
  toString(): string {
393
570
  return zonedDateTimeToString(this);
394
571
  }
395
572
 
396
- /** Converts the date to an ISO 8601 formatted string in UTC. */
573
+ /** Converts the date to an ISO 8601 formatted string in UTC. */
397
574
  toAbsoluteString(): string {
398
575
  return this.toDate().toISOString();
399
576
  }
400
577
 
401
- /** Compares this date with another. A negative result indicates that this date is before the given one, and a positive date indicates that it is after. */
578
+ /**
579
+ * Compares this date with another. A negative result indicates that this date is before the given
580
+ * one, and a positive date indicates that it is after.
581
+ */
402
582
  compare(b: CalendarDate | CalendarDateTime | ZonedDateTime): number {
403
583
  // TODO: Is this a bad idea??
404
584
  return this.toDate().getTime() - toZoned(b, this.timeZone).toDate().getTime();
@@ -13,7 +13,7 @@
13
13
  let formatterCache = new Map<string, Intl.DateTimeFormat>();
14
14
 
15
15
  interface DateRangeFormatPart extends Intl.DateTimeFormatPart {
16
- source: 'startRange' | 'endRange' | 'shared'
16
+ source: 'startRange' | 'endRange' | 'shared';
17
17
  }
18
18
 
19
19
  /** A wrapper around Intl.DateTimeFormat that fixes various browser bugs, and polyfills new features. */
@@ -27,7 +27,10 @@ export class DateFormatter implements Intl.DateTimeFormat {
27
27
  this.options = options;
28
28
  }
29
29
 
30
- /** Formats a date as a string according to the locale and format options passed to the constructor. */
30
+ /**
31
+ * Formats a date as a string according to the locale and format options passed to the
32
+ * constructor.
33
+ */
31
34
  format(value: Date): string {
32
35
  return this.formatter.format(value);
33
36
  }
@@ -68,9 +71,9 @@ export class DateFormatter implements Intl.DateTimeFormat {
68
71
  let startParts = this.formatter.formatToParts(start);
69
72
  let endParts = this.formatter.formatToParts(end);
70
73
  return [
71
- ...startParts.map(p => ({...p, source: 'startRange'} as DateRangeFormatPart)),
74
+ ...startParts.map(p => ({...p, source: 'startRange'}) as DateRangeFormatPart),
72
75
  {type: 'literal', value: ' – ', source: 'shared'},
73
- ...endParts.map(p => ({...p, source: 'endRange'} as DateRangeFormatPart))
76
+ ...endParts.map(p => ({...p, source: 'endRange'}) as DateRangeFormatPart)
74
77
  ];
75
78
  }
76
79
 
@@ -116,7 +119,10 @@ const hour12Preferences = {
116
119
  }
117
120
  };
118
121
 
119
- function getCachedDateFormatter(locale: string, options: Intl.DateTimeFormatOptions = {}): Intl.DateTimeFormat {
122
+ function getCachedDateFormatter(
123
+ locale: string,
124
+ options: Intl.DateTimeFormatOptions = {}
125
+ ): Intl.DateTimeFormat {
120
126
  // Work around buggy hour12 behavior in Chrome / ECMA 402 spec by using hourCycle instead.
121
127
  // Only apply the workaround if the issue is detected, because the hourCycle option is buggy in Safari.
122
128
  if (typeof options.hour12 === 'boolean' && hasBuggyHour12Behavior()) {
@@ -127,7 +133,13 @@ function getCachedDateFormatter(locale: string, options: Intl.DateTimeFormatOpti
127
133
  delete options.hour12;
128
134
  }
129
135
 
130
- let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
136
+ let cacheKey =
137
+ locale +
138
+ (options
139
+ ? Object.entries(options)
140
+ .sort((a, b) => (a[0] < b[0] ? -1 : 1))
141
+ .join()
142
+ : '');
131
143
  if (formatterCache.has(cacheKey)) {
132
144
  return formatterCache.get(cacheKey)!;
133
145
  }
@@ -140,10 +152,11 @@ function getCachedDateFormatter(locale: string, options: Intl.DateTimeFormatOpti
140
152
  let _hasBuggyHour12Behavior: boolean | null = null;
141
153
  function hasBuggyHour12Behavior() {
142
154
  if (_hasBuggyHour12Behavior == null) {
143
- _hasBuggyHour12Behavior = new Intl.DateTimeFormat('en-US', {
144
- hour: 'numeric',
145
- hour12: false
146
- }).format(new Date(2020, 2, 3, 0)) === '24';
155
+ _hasBuggyHour12Behavior =
156
+ new Intl.DateTimeFormat('en-US', {
157
+ hour: 'numeric',
158
+ hour12: false
159
+ }).format(new Date(2020, 2, 3, 0)) === '24';
147
160
  }
148
161
 
149
162
  return _hasBuggyHour12Behavior;
@@ -152,10 +165,11 @@ function hasBuggyHour12Behavior() {
152
165
  let _hasBuggyResolvedHourCycle: boolean | null = null;
153
166
  function hasBuggyResolvedHourCycle() {
154
167
  if (_hasBuggyResolvedHourCycle == null) {
155
- _hasBuggyResolvedHourCycle = new Intl.DateTimeFormat('fr', {
156
- hour: 'numeric',
157
- hour12: false
158
- }).resolvedOptions().hourCycle === 'h12';
168
+ _hasBuggyResolvedHourCycle =
169
+ new Intl.DateTimeFormat('fr', {
170
+ hour: 'numeric',
171
+ hour12: false
172
+ }).resolvedOptions().hourCycle === 'h12';
159
173
  }
160
174
 
161
175
  return _hasBuggyResolvedHourCycle;
@@ -175,8 +189,14 @@ function getResolvedHourCycle(locale: string, options: Intl.DateTimeFormatOption
175
189
  timeZone: undefined // use local timezone
176
190
  });
177
191
 
178
- let min = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 0)).find(p => p.type === 'hour')!.value, 10);
179
- let max = parseInt(formatter.formatToParts(new Date(2020, 2, 3, 23)).find(p => p.type === 'hour')!.value, 10);
192
+ let min = parseInt(
193
+ formatter.formatToParts(new Date(2020, 2, 3, 0)).find(p => p.type === 'hour')!.value,
194
+ 10
195
+ );
196
+ let max = parseInt(
197
+ formatter.formatToParts(new Date(2020, 2, 3, 23)).find(p => p.type === 'hour')!.value,
198
+ 10
199
+ );
180
200
 
181
201
  if (min === 0 && max === 23) {
182
202
  return 'h23';
@@ -55,10 +55,5 @@ export class BuddhistCalendar extends GregorianCalendar {
55
55
 
56
56
  function toGregorian(date: AnyCalendarDate) {
57
57
  let [era, year] = fromExtendedYear(date.year + BUDDHIST_ERA_START);
58
- return new CalendarDate(
59
- era,
60
- year,
61
- date.month,
62
- date.day
63
- );
58
+ return new CalendarDate(era, year, date.month, date.day);
64
59
  }
@@ -26,11 +26,12 @@ const AMETE_MIHRET_DELTA = 5500;
26
26
 
27
27
  function ceToJulianDay(epoch: number, year: number, month: number, day: number): number {
28
28
  return (
29
- epoch // difference from Julian epoch to 1,1,1
30
- + 365 * year // number of days from years
31
- + Math.floor(year / 4) // extra day of leap year
32
- + 30 * (month - 1) // number of days from months (1 based)
33
- + day - 1 // number of days for present month (1 based)
29
+ epoch + // difference from Julian epoch to 1,1,1
30
+ 365 * year + // number of days from years
31
+ Math.floor(year / 4) + // extra day of leap year
32
+ 30 * (month - 1) + // number of days from months (1 based)
33
+ day -
34
+ 1 // number of days for present month (1 based)
34
35
  );
35
36
  }
36
37
 
@@ -18,7 +18,12 @@ import {CalendarDate} from '../CalendarDate';
18
18
  import {mod, Mutable} from '../utils';
19
19
 
20
20
  const EPOCH = 1721426; // 001/01/03 Julian C.E.
21
- export function gregorianToJulianDay(era: string, year: number, month: number, day: number): number {
21
+ export function gregorianToJulianDay(
22
+ era: string,
23
+ year: number,
24
+ month: number,
25
+ day: number
26
+ ): number {
22
27
  year = getExtendedYear(era, year);
23
28
 
24
29
  let y1 = year - 1;
@@ -64,8 +69,9 @@ const daysInMonth = {
64
69
  };
65
70
 
66
71
  /**
67
- * The Gregorian calendar is the most commonly used calendar system in the world. It supports two eras: BC, and AD.
68
- * Years always contain 12 months, and 365 or 366 days depending on whether it is a leap year.
72
+ * The Gregorian calendar is the most commonly used calendar system in the world. It supports two
73
+ * eras: BC, and AD. Years always contain 12 months, and 365 or 366 days depending on whether it is
74
+ * a leap year.
69
75
  */
70
76
  export class GregorianCalendar implements Calendar {
71
77
  identifier: CalendarIdentifier = 'gregory';
@@ -81,7 +87,8 @@ export class GregorianCalendar implements Calendar {
81
87
  let dquad = mod(dcent, 1461);
82
88
  let yindex = Math.floor(dquad / 365);
83
89
 
84
- let extendedYear = quadricent * 400 + cent * 100 + quad * 4 + yindex + (cent !== 4 && yindex !== 4 ? 1 : 0);
90
+ let extendedYear =
91
+ quadricent * 400 + cent * 100 + quad * 4 + yindex + (cent !== 4 && yindex !== 4 ? 1 : 0);
85
92
  let [era, year] = fromExtendedYear(extendedYear);
86
93
  let yearDay = jd0 - gregorianToJulianDay(era, year, 1, 1);
87
94
  let leapAdj = 2;
@@ -22,7 +22,7 @@ const HEBREW_EPOCH = 347997;
22
22
  // Hebrew date calculations are performed in terms of days, hours, and
23
23
  // "parts" (or halakim), which are 1/1080 of an hour, or 3 1/3 seconds.
24
24
  const HOUR_PARTS = 1080;
25
- const DAY_PARTS = 24 * HOUR_PARTS;
25
+ const DAY_PARTS = 24 * HOUR_PARTS;
26
26
 
27
27
  // An approximate value for the length of a lunar month.
28
28
  // It is used to calculate the approximate year and month of a given
@@ -132,9 +132,9 @@ export class HebrewCalendar implements Calendar {
132
132
 
133
133
  fromJulianDay(jd: number): CalendarDate {
134
134
  let d = jd - HEBREW_EPOCH;
135
- let m = (d * DAY_PARTS) / MONTH_PARTS; // Months (approx)
135
+ let m = (d * DAY_PARTS) / MONTH_PARTS; // Months (approx)
136
136
  let year = Math.floor((19 * m + 234) / 235) + 1; // Years (approx)
137
- let ys = startOfYear(year); // 1st day of year
137
+ let ys = startOfYear(year); // 1st day of year
138
138
  let dayOfYear = Math.floor(d - ys);
139
139
 
140
140
  // Because of the postponement rules, it's possible to guess wrong. Fix it.
@@ -202,7 +202,11 @@ export class HebrewCalendar implements Calendar {
202
202
  if (previousDate.year !== date.year) {
203
203
  if (isLeapYear(previousDate.year) && !isLeapYear(date.year) && previousDate.month > 6) {
204
204
  date.month--;
205
- } else if (!isLeapYear(previousDate.year) && isLeapYear(date.year) && previousDate.month > 6) {
205
+ } else if (
206
+ !isLeapYear(previousDate.year) &&
207
+ isLeapYear(date.year) &&
208
+ previousDate.month > 6
209
+ ) {
206
210
  date.month++;
207
211
  }
208
212
  }
@@ -15,7 +15,12 @@
15
15
 
16
16
  import {AnyCalendarDate, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
- import {fromExtendedYear, GregorianCalendar, gregorianToJulianDay, isLeapYear} from './GregorianCalendar';
18
+ import {
19
+ fromExtendedYear,
20
+ GregorianCalendar,
21
+ gregorianToJulianDay,
22
+ isLeapYear
23
+ } from './GregorianCalendar';
19
24
 
20
25
  // Starts in 78 AD,
21
26
  const INDIAN_ERA_START = 78;
@@ -48,7 +53,7 @@ export class IndianCalendar extends GregorianCalendar {
48
53
 
49
54
  // Days in leapMonth this year, previous Gregorian year
50
55
  leapMonth = isLeapYear(date.year - 1) ? 31 : 30;
51
- yDay += leapMonth + (31 * 5) + (30 * 3) + 10;
56
+ yDay += leapMonth + 31 * 5 + 30 * 3 + 10;
52
57
  } else {
53
58
  // Days in leapMonth this year
54
59
  leapMonth = isLeapYear(date.year) ? 31 : 30;
@@ -62,7 +67,7 @@ export class IndianCalendar extends GregorianCalendar {
62
67
  indianDay = yDay + 1;
63
68
  } else {
64
69
  let mDay = yDay - leapMonth;
65
- if (mDay < (31 * 5)) {
70
+ if (mDay < 31 * 5) {
66
71
  indianMonth = Math.floor(mDay / 31) + 2;
67
72
  indianDay = (mDay % 31) + 1;
68
73
  } else {