@internationalized/date 3.7.0 → 3.8.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 (64) hide show
  1. package/dist/BuddhistCalendar.main.js.map +1 -1
  2. package/dist/BuddhistCalendar.module.js.map +1 -1
  3. package/dist/CalendarDate.main.js.map +1 -1
  4. package/dist/CalendarDate.module.js.map +1 -1
  5. package/dist/EthiopicCalendar.main.js.map +1 -1
  6. package/dist/EthiopicCalendar.module.js.map +1 -1
  7. package/dist/GregorianCalendar.main.js.map +1 -1
  8. package/dist/GregorianCalendar.module.js.map +1 -1
  9. package/dist/HebrewCalendar.main.js.map +1 -1
  10. package/dist/HebrewCalendar.module.js.map +1 -1
  11. package/dist/IndianCalendar.main.js.map +1 -1
  12. package/dist/IndianCalendar.module.js.map +1 -1
  13. package/dist/IslamicCalendar.main.js.map +1 -1
  14. package/dist/IslamicCalendar.module.js.map +1 -1
  15. package/dist/JapaneseCalendar.main.js.map +1 -1
  16. package/dist/JapaneseCalendar.module.js.map +1 -1
  17. package/dist/PersianCalendar.main.js.map +1 -1
  18. package/dist/PersianCalendar.module.js.map +1 -1
  19. package/dist/TaiwanCalendar.main.js.map +1 -1
  20. package/dist/TaiwanCalendar.module.js.map +1 -1
  21. package/dist/conversion.main.js +1 -1
  22. package/dist/conversion.main.js.map +1 -1
  23. package/dist/conversion.mjs +2 -2
  24. package/dist/conversion.module.js +2 -2
  25. package/dist/conversion.module.js.map +1 -1
  26. package/dist/createCalendar.main.js.map +1 -1
  27. package/dist/createCalendar.module.js.map +1 -1
  28. package/dist/import.mjs +2 -2
  29. package/dist/main.js +1 -0
  30. package/dist/main.js.map +1 -1
  31. package/dist/manipulation.main.js.map +1 -1
  32. package/dist/manipulation.module.js.map +1 -1
  33. package/dist/module.js +2 -2
  34. package/dist/module.js.map +1 -1
  35. package/dist/queries.main.js +9 -7
  36. package/dist/queries.main.js.map +1 -1
  37. package/dist/queries.mjs +9 -8
  38. package/dist/queries.module.js +9 -8
  39. package/dist/queries.module.js.map +1 -1
  40. package/dist/types.d.ts +31 -16
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/utils.main.js +1 -12
  43. package/dist/utils.main.js.map +1 -1
  44. package/dist/utils.mjs +2 -13
  45. package/dist/utils.module.js +2 -13
  46. package/dist/utils.module.js.map +1 -1
  47. package/package.json +2 -2
  48. package/src/CalendarDate.ts +14 -14
  49. package/src/calendars/BuddhistCalendar.ts +5 -5
  50. package/src/calendars/EthiopicCalendar.ts +10 -10
  51. package/src/calendars/GregorianCalendar.ts +4 -4
  52. package/src/calendars/HebrewCalendar.ts +5 -5
  53. package/src/calendars/IndianCalendar.ts +5 -5
  54. package/src/calendars/IslamicCalendar.ts +7 -7
  55. package/src/calendars/JapaneseCalendar.ts +6 -6
  56. package/src/calendars/PersianCalendar.ts +3 -3
  57. package/src/calendars/TaiwanCalendar.ts +5 -5
  58. package/src/conversion.ts +6 -6
  59. package/src/createCalendar.ts +2 -2
  60. package/src/index.ts +3 -1
  61. package/src/manipulation.ts +7 -7
  62. package/src/queries.ts +11 -10
  63. package/src/types.ts +17 -2
  64. package/src/utils.ts +0 -18
@@ -155,17 +155,17 @@ export class Time {
155
155
  }
156
156
 
157
157
  /** Returns a new `Time` with the given duration added to it. */
158
- add(duration: TimeDuration) {
158
+ add(duration: TimeDuration): Time {
159
159
  return addTime(this, duration);
160
160
  }
161
161
 
162
162
  /** Returns a new `Time` with the given duration subtracted from it. */
163
- subtract(duration: TimeDuration) {
163
+ subtract(duration: TimeDuration): Time {
164
164
  return subtractTime(this, duration);
165
165
  }
166
166
 
167
167
  /** Returns a new `Time` with the given fields set to the provided values. Other fields will be constrained accordingly. */
168
- set(fields: TimeFields) {
168
+ set(fields: TimeFields): Time {
169
169
  return setTime(this, fields);
170
170
  }
171
171
 
@@ -173,17 +173,17 @@ export class Time {
173
173
  * Returns a new `Time` with the given field adjusted by a specified amount.
174
174
  * When the resulting value reaches the limits of the field, it wraps around.
175
175
  */
176
- cycle(field: TimeField, amount: number, options?: CycleTimeOptions) {
176
+ cycle(field: TimeField, amount: number, options?: CycleTimeOptions): Time {
177
177
  return cycleTime(this, field, amount, options);
178
178
  }
179
179
 
180
180
  /** Converts the time to an ISO 8601 formatted string. */
181
- toString() {
181
+ toString(): string {
182
182
  return timeToString(this);
183
183
  }
184
184
 
185
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. */
186
- compare(b: AnyTime) {
186
+ compare(b: AnyTime): number {
187
187
  return compareTime(this, b);
188
188
  }
189
189
  }
@@ -361,17 +361,17 @@ export class ZonedDateTime {
361
361
  }
362
362
 
363
363
  /** Returns a new `ZonedDateTime` with the given duration added to it. */
364
- add(duration: DateTimeDuration) {
364
+ add(duration: DateTimeDuration): ZonedDateTime {
365
365
  return addZoned(this, duration);
366
366
  }
367
367
 
368
368
  /** Returns a new `ZonedDateTime` with the given duration subtracted from it. */
369
- subtract(duration: DateTimeDuration) {
369
+ subtract(duration: DateTimeDuration): ZonedDateTime {
370
370
  return subtractZoned(this, duration);
371
371
  }
372
372
 
373
373
  /** Returns a new `ZonedDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */
374
- set(fields: DateFields & TimeFields, disambiguation?: Disambiguation) {
374
+ set(fields: DateFields & TimeFields, disambiguation?: Disambiguation): ZonedDateTime {
375
375
  return setZoned(this, fields, disambiguation);
376
376
  }
377
377
 
@@ -379,27 +379,27 @@ export class ZonedDateTime {
379
379
  * Returns a new `ZonedDateTime` with the given field adjusted by a specified amount.
380
380
  * When the resulting value reaches the limits of the field, it wraps around.
381
381
  */
382
- cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions) {
382
+ cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions): ZonedDateTime {
383
383
  return cycleZoned(this, field, amount, options);
384
384
  }
385
385
 
386
386
  /** Converts the date to a native JavaScript Date object. */
387
- toDate() {
387
+ toDate(): Date {
388
388
  return zonedToDate(this);
389
389
  }
390
390
 
391
391
  /** Converts the date to an ISO 8601 formatted string, including the UTC offset and time zone identifier. */
392
- toString() {
392
+ toString(): string {
393
393
  return zonedDateTimeToString(this);
394
394
  }
395
395
 
396
396
  /** Converts the date to an ISO 8601 formatted string in UTC. */
397
- toAbsoluteString() {
397
+ toAbsoluteString(): string {
398
398
  return this.toDate().toISOString();
399
399
  }
400
400
 
401
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. */
402
- compare(b: CalendarDate | CalendarDateTime | ZonedDateTime) {
402
+ compare(b: CalendarDate | CalendarDateTime | ZonedDateTime): number {
403
403
  // TODO: Is this a bad idea??
404
404
  return this.toDate().getTime() - toZoned(b, this.timeZone).toDate().getTime();
405
405
  }
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate} from '../types';
16
+ import {AnyCalendarDate, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {fromExtendedYear, getExtendedYear, GregorianCalendar} from './GregorianCalendar';
19
19
 
@@ -25,7 +25,7 @@ const BUDDHIST_ERA_START = -543;
25
25
  * era, identified as 'BE'.
26
26
  */
27
27
  export class BuddhistCalendar extends GregorianCalendar {
28
- identifier = 'buddhist';
28
+ identifier: CalendarIdentifier = 'buddhist';
29
29
 
30
30
  fromJulianDay(jd: number): CalendarDate {
31
31
  let gregorianDate = super.fromJulianDay(jd);
@@ -38,11 +38,11 @@ export class BuddhistCalendar extends GregorianCalendar {
38
38
  );
39
39
  }
40
40
 
41
- toJulianDay(date: AnyCalendarDate) {
41
+ toJulianDay(date: AnyCalendarDate): number {
42
42
  return super.toJulianDay(toGregorian(date));
43
43
  }
44
44
 
45
- getEras() {
45
+ getEras(): string[] {
46
46
  return ['BE'];
47
47
  }
48
48
 
@@ -50,7 +50,7 @@ export class BuddhistCalendar extends GregorianCalendar {
50
50
  return super.getDaysInMonth(toGregorian(date));
51
51
  }
52
52
 
53
- balanceDate() {}
53
+ balanceDate(): void {}
54
54
  }
55
55
 
56
56
  function toGregorian(date: AnyCalendarDate) {
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate, Calendar} from '../types';
16
+ import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {Mutable} from '../utils';
19
19
 
@@ -66,7 +66,7 @@ function getDaysInMonth(year: number, month: number) {
66
66
  * on whether it is a leap year. Two eras are supported: 'AA' and 'AM'.
67
67
  */
68
68
  export class EthiopicCalendar implements Calendar {
69
- identifier = 'ethiopic';
69
+ identifier: CalendarIdentifier = 'ethiopic';
70
70
 
71
71
  fromJulianDay(jd: number): CalendarDate {
72
72
  let [year, month, day] = julianDayToCE(ETHIOPIC_EPOCH, jd);
@@ -79,7 +79,7 @@ export class EthiopicCalendar implements Calendar {
79
79
  return new CalendarDate(this, era, year, month, day);
80
80
  }
81
81
 
82
- toJulianDay(date: AnyCalendarDate) {
82
+ toJulianDay(date: AnyCalendarDate): number {
83
83
  let year = date.year;
84
84
  if (date.era === 'AA') {
85
85
  year -= AMETE_MIHRET_DELTA;
@@ -107,7 +107,7 @@ export class EthiopicCalendar implements Calendar {
107
107
  return date.era === 'AA' ? 9999 : 9991;
108
108
  }
109
109
 
110
- getEras() {
110
+ getEras(): string[] {
111
111
  return ['AA', 'AM'];
112
112
  }
113
113
  }
@@ -117,7 +117,7 @@ export class EthiopicCalendar implements Calendar {
117
117
  * except years were measured from a different epoch. Only one era is supported: 'AA'.
118
118
  */
119
119
  export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
120
- identifier = 'ethioaa'; // also known as 'ethiopic-amete-alem' in ICU
120
+ identifier: CalendarIdentifier = 'ethioaa'; // also known as 'ethiopic-amete-alem' in ICU
121
121
 
122
122
  fromJulianDay(jd: number): CalendarDate {
123
123
  let [year, month, day] = julianDayToCE(ETHIOPIC_EPOCH, jd);
@@ -125,7 +125,7 @@ export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
125
125
  return new CalendarDate(this, 'AA', year, month, day);
126
126
  }
127
127
 
128
- getEras() {
128
+ getEras(): string[] {
129
129
  return ['AA'];
130
130
  }
131
131
 
@@ -141,7 +141,7 @@ export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
141
141
  * on whether it is a leap year. Two eras are supported: 'BCE' and 'CE'.
142
142
  */
143
143
  export class CopticCalendar extends EthiopicCalendar {
144
- identifier = 'coptic';
144
+ identifier: CalendarIdentifier = 'coptic';
145
145
 
146
146
  fromJulianDay(jd: number): CalendarDate {
147
147
  let [year, month, day] = julianDayToCE(COPTIC_EPOCH, jd);
@@ -154,7 +154,7 @@ export class CopticCalendar extends EthiopicCalendar {
154
154
  return new CalendarDate(this, era, year, month, day);
155
155
  }
156
156
 
157
- toJulianDay(date: AnyCalendarDate) {
157
+ toJulianDay(date: AnyCalendarDate): number {
158
158
  let year = date.year;
159
159
  if (date.era === 'BCE') {
160
160
  year = 1 - year;
@@ -176,14 +176,14 @@ export class CopticCalendar extends EthiopicCalendar {
176
176
  return date.era === 'BCE';
177
177
  }
178
178
 
179
- balanceDate(date: Mutable<AnyCalendarDate>) {
179
+ balanceDate(date: Mutable<AnyCalendarDate>): void {
180
180
  if (date.year <= 0) {
181
181
  date.era = date.era === 'BCE' ? 'CE' : 'BCE';
182
182
  date.year = 1 - date.year;
183
183
  }
184
184
  }
185
185
 
186
- getEras() {
186
+ getEras(): string[] {
187
187
  return ['BCE', 'CE'];
188
188
  }
189
189
 
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate, Calendar} from '../types';
16
+ import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {mod, Mutable} from '../utils';
19
19
 
@@ -68,7 +68,7 @@ const daysInMonth = {
68
68
  * Years always contain 12 months, and 365 or 366 days depending on whether it is a leap year.
69
69
  */
70
70
  export class GregorianCalendar implements Calendar {
71
- identifier = 'gregory';
71
+ identifier: CalendarIdentifier = 'gregory';
72
72
 
73
73
  fromJulianDay(jd: number): CalendarDate {
74
74
  let jd0 = jd;
@@ -118,7 +118,7 @@ export class GregorianCalendar implements Calendar {
118
118
  return 9999;
119
119
  }
120
120
 
121
- getEras() {
121
+ getEras(): string[] {
122
122
  return ['BC', 'AD'];
123
123
  }
124
124
 
@@ -126,7 +126,7 @@ export class GregorianCalendar implements Calendar {
126
126
  return date.era === 'BC';
127
127
  }
128
128
 
129
- balanceDate(date: Mutable<AnyCalendarDate>) {
129
+ balanceDate(date: Mutable<AnyCalendarDate>): void {
130
130
  if (date.year <= 0) {
131
131
  date.era = date.era === 'BC' ? 'AD' : 'BC';
132
132
  date.year = 1 - date.year;
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate, Calendar} from '../types';
16
+ import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {mod, Mutable} from '../utils';
19
19
 
@@ -128,7 +128,7 @@ function getDaysInMonth(year: number, month: number): number {
128
128
  * In leap years, an extra month is inserted at month 6.
129
129
  */
130
130
  export class HebrewCalendar implements Calendar {
131
- identifier = 'hebrew';
131
+ identifier: CalendarIdentifier = 'hebrew';
132
132
 
133
133
  fromJulianDay(jd: number): CalendarDate {
134
134
  let d = jd - HEBREW_EPOCH;
@@ -159,7 +159,7 @@ export class HebrewCalendar implements Calendar {
159
159
  return new CalendarDate(this, year, month, day);
160
160
  }
161
161
 
162
- toJulianDay(date: AnyCalendarDate) {
162
+ toJulianDay(date: AnyCalendarDate): number {
163
163
  let jd = startOfYear(date.year);
164
164
  for (let month = 1; month < date.month; month++) {
165
165
  jd += getDaysInMonth(date.year, month);
@@ -185,11 +185,11 @@ export class HebrewCalendar implements Calendar {
185
185
  return 9999;
186
186
  }
187
187
 
188
- getEras() {
188
+ getEras(): string[] {
189
189
  return ['AM'];
190
190
  }
191
191
 
192
- balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate) {
192
+ balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate): void {
193
193
  // Keep date in the same month when switching between leap years and non leap years
194
194
  if (previousDate.year !== date.year) {
195
195
  if (isLeapYear(previousDate.year) && !isLeapYear(date.year) && previousDate.month > 6) {
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate} from '../types';
16
+ import {AnyCalendarDate, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {fromExtendedYear, GregorianCalendar, gregorianToJulianDay, isLeapYear} from './GregorianCalendar';
19
19
 
@@ -29,7 +29,7 @@ const INDIAN_YEAR_START = 80;
29
29
  * in each year, with either 30 or 31 days. Only one era identifier is supported: 'saka'.
30
30
  */
31
31
  export class IndianCalendar extends GregorianCalendar {
32
- identifier = 'indian';
32
+ identifier: CalendarIdentifier = 'indian';
33
33
 
34
34
  fromJulianDay(jd: number): CalendarDate {
35
35
  // Gregorian date for Julian day
@@ -75,7 +75,7 @@ export class IndianCalendar extends GregorianCalendar {
75
75
  return new CalendarDate(this, indianYear, indianMonth, indianDay);
76
76
  }
77
77
 
78
- toJulianDay(date: AnyCalendarDate) {
78
+ toJulianDay(date: AnyCalendarDate): number {
79
79
  let extendedYear = date.year + INDIAN_ERA_START;
80
80
  let [era, year] = fromExtendedYear(extendedYear);
81
81
 
@@ -121,9 +121,9 @@ export class IndianCalendar extends GregorianCalendar {
121
121
  return 9919;
122
122
  }
123
123
 
124
- getEras() {
124
+ getEras(): string[] {
125
125
  return ['saka'];
126
126
  }
127
127
 
128
- balanceDate() {}
128
+ balanceDate(): void {}
129
129
  }
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate, Calendar} from '../types';
16
+ import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
 
19
19
  const CIVIL_EPOC = 1948440; // CE 622 July 16 Friday (Julian calendar) / CE 622 July 19 (Gregorian calendar)
@@ -50,13 +50,13 @@ function isLeapYear(year: number): boolean {
50
50
  * Learn more about the available Islamic calendars [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
51
51
  */
52
52
  export class IslamicCivilCalendar implements Calendar {
53
- identifier = 'islamic-civil';
53
+ identifier: CalendarIdentifier = 'islamic-civil';
54
54
 
55
55
  fromJulianDay(jd: number): CalendarDate {
56
56
  return julianDayToIslamic(this, CIVIL_EPOC, jd);
57
57
  }
58
58
 
59
- toJulianDay(date: AnyCalendarDate) {
59
+ toJulianDay(date: AnyCalendarDate): number {
60
60
  return islamicToJulianDay(CIVIL_EPOC, date.year, date.month, date.day);
61
61
  }
62
62
 
@@ -82,7 +82,7 @@ export class IslamicCivilCalendar implements Calendar {
82
82
  return 9665;
83
83
  }
84
84
 
85
- getEras() {
85
+ getEras(): string[] {
86
86
  return ['AH'];
87
87
  }
88
88
  }
@@ -95,13 +95,13 @@ export class IslamicCivilCalendar implements Calendar {
95
95
  * Learn more about the available Islamic calendars [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
96
96
  */
97
97
  export class IslamicTabularCalendar extends IslamicCivilCalendar {
98
- identifier = 'islamic-tbla';
98
+ identifier: CalendarIdentifier = 'islamic-tbla';
99
99
 
100
100
  fromJulianDay(jd: number): CalendarDate {
101
101
  return julianDayToIslamic(this, ASTRONOMICAL_EPOC, jd);
102
102
  }
103
103
 
104
- toJulianDay(date: AnyCalendarDate) {
104
+ toJulianDay(date: AnyCalendarDate): number {
105
105
  return islamicToJulianDay(ASTRONOMICAL_EPOC, date.year, date.month, date.day);
106
106
  }
107
107
  }
@@ -145,7 +145,7 @@ function umalquraYearLength(year: number): number {
145
145
  * Learn more about the available Islamic calendars [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
146
146
  */
147
147
  export class IslamicUmalquraCalendar extends IslamicCivilCalendar {
148
- identifier = 'islamic-umalqura';
148
+ identifier: CalendarIdentifier = 'islamic-umalqura';
149
149
 
150
150
  constructor() {
151
151
  super();
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from the TC39 Temporal proposal.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate} from '../types';
16
+ import {AnyCalendarDate, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {GregorianCalendar} from './GregorianCalendar';
19
19
  import {Mutable} from '../utils';
@@ -70,7 +70,7 @@ function toGregorian(date: AnyCalendarDate) {
70
70
  * Note that eras before 1868 (Gregorian) are not currently supported by this implementation.
71
71
  */
72
72
  export class JapaneseCalendar extends GregorianCalendar {
73
- identifier = 'japanese';
73
+ identifier: CalendarIdentifier = 'japanese';
74
74
 
75
75
  fromJulianDay(jd: number): CalendarDate {
76
76
  let date = super.fromJulianDay(jd);
@@ -85,11 +85,11 @@ export class JapaneseCalendar extends GregorianCalendar {
85
85
  );
86
86
  }
87
87
 
88
- toJulianDay(date: AnyCalendarDate) {
88
+ toJulianDay(date: AnyCalendarDate): number {
89
89
  return super.toJulianDay(toGregorian(date));
90
90
  }
91
91
 
92
- balanceDate(date: Mutable<AnyCalendarDate>) {
92
+ balanceDate(date: Mutable<AnyCalendarDate>): void {
93
93
  let gregorianDate = toGregorian(date);
94
94
  let era = findEraFromGregorianDate(gregorianDate);
95
95
 
@@ -102,7 +102,7 @@ export class JapaneseCalendar extends GregorianCalendar {
102
102
  this.constrainDate(date);
103
103
  }
104
104
 
105
- constrainDate(date: Mutable<AnyCalendarDate>) {
105
+ constrainDate(date: Mutable<AnyCalendarDate>): void {
106
106
  let idx = ERA_NAMES.indexOf(date.era);
107
107
  let end = ERA_END_DATES[idx];
108
108
  if (end != null) {
@@ -131,7 +131,7 @@ export class JapaneseCalendar extends GregorianCalendar {
131
131
  }
132
132
  }
133
133
 
134
- getEras() {
134
+ getEras(): string[] {
135
135
  return ERA_NAMES;
136
136
  }
137
137
 
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate, Calendar} from '../types';
16
+ import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {mod} from '../utils';
19
19
 
@@ -42,7 +42,7 @@ const MONTH_START = [
42
42
  * around the March equinox.
43
43
  */
44
44
  export class PersianCalendar implements Calendar {
45
- identifier = 'persian';
45
+ identifier: CalendarIdentifier = 'persian';
46
46
 
47
47
  fromJulianDay(jd: number): CalendarDate {
48
48
  let daysSinceEpoch = jd - PERSIAN_EPOCH;
@@ -80,7 +80,7 @@ export class PersianCalendar implements Calendar {
80
80
  return isLeapYear ? 30 : 29;
81
81
  }
82
82
 
83
- getEras() {
83
+ getEras(): string[] {
84
84
  return ['AP'];
85
85
  }
86
86
 
@@ -13,7 +13,7 @@
13
13
  // Portions of the code in this file are based on code from ICU.
14
14
  // Original licensing can be found in the NOTICE file in the root directory of this source tree.
15
15
 
16
- import {AnyCalendarDate} from '../types';
16
+ import {AnyCalendarDate, CalendarIdentifier} from '../types';
17
17
  import {CalendarDate} from '../CalendarDate';
18
18
  import {fromExtendedYear, getExtendedYear, GregorianCalendar} from './GregorianCalendar';
19
19
  import {Mutable} from '../utils';
@@ -41,7 +41,7 @@ function gregorianToTaiwan(year: number): [string, number] {
41
41
  * 'before_minguo' and 'minguo'.
42
42
  */
43
43
  export class TaiwanCalendar extends GregorianCalendar {
44
- identifier = 'roc'; // Republic of China
44
+ identifier: CalendarIdentifier = 'roc'; // Republic of China
45
45
 
46
46
  fromJulianDay(jd: number): CalendarDate {
47
47
  let date = super.fromJulianDay(jd);
@@ -50,15 +50,15 @@ export class TaiwanCalendar extends GregorianCalendar {
50
50
  return new CalendarDate(this, era, year, date.month, date.day);
51
51
  }
52
52
 
53
- toJulianDay(date: AnyCalendarDate) {
53
+ toJulianDay(date: AnyCalendarDate): number {
54
54
  return super.toJulianDay(toGregorian(date));
55
55
  }
56
56
 
57
- getEras() {
57
+ getEras(): string[] {
58
58
  return ['before_minguo', 'minguo'];
59
59
  }
60
60
 
61
- balanceDate(date: Mutable<AnyCalendarDate>) {
61
+ balanceDate(date: Mutable<AnyCalendarDate>): void {
62
62
  let [era, year] = gregorianToTaiwan(gregorianYear(date));
63
63
  date.era = era;
64
64
  date.year = year;
package/src/conversion.ts CHANGED
@@ -17,16 +17,16 @@ import {AnyCalendarDate, AnyDateTime, AnyTime, Calendar, DateFields, Disambiguat
17
17
  import {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';
18
18
  import {constrain} from './manipulation';
19
19
  import {getExtendedYear, GregorianCalendar} from './calendars/GregorianCalendar';
20
- import {getLocalTimeZone} from './queries';
20
+ import {getLocalTimeZone, isEqualCalendar} from './queries';
21
21
  import {Mutable} from './utils';
22
22
 
23
- export function epochFromDate(date: AnyDateTime) {
23
+ export function epochFromDate(date: AnyDateTime): number {
24
24
  date = toCalendar(date, new GregorianCalendar());
25
25
  let year = getExtendedYear(date.era, date.year);
26
26
  return epochFromParts(year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);
27
27
  }
28
28
 
29
- function epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number) {
29
+ function epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number): number {
30
30
  // Note: Date.UTC() interprets one and two-digit years as being in the
31
31
  // 20th century, so don't use it
32
32
  let date = new Date();
@@ -35,7 +35,7 @@ function epochFromParts(year: number, month: number, day: number, hour: number,
35
35
  return date.getTime();
36
36
  }
37
37
 
38
- export function getTimeZoneOffset(ms: number, timeZone: string) {
38
+ export function getTimeZoneOffset(ms: number, timeZone: string): number {
39
39
  // Fast path for UTC.
40
40
  if (timeZone === 'UTC') {
41
41
  return 0;
@@ -260,7 +260,7 @@ export function toTime(dateTime: CalendarDateTime | ZonedDateTime): Time {
260
260
 
261
261
  /** Converts a date from one calendar system to another. */
262
262
  export function toCalendar<T extends AnyCalendarDate>(date: T, calendar: Calendar): T {
263
- if (date.calendar.identifier === calendar.identifier) {
263
+ if (isEqualCalendar(date.calendar, calendar)) {
264
264
  return date;
265
265
  }
266
266
 
@@ -292,7 +292,7 @@ export function toZoned(date: CalendarDate | CalendarDateTime | ZonedDateTime, t
292
292
  return fromAbsolute(ms, timeZone);
293
293
  }
294
294
 
295
- export function zonedToDate(date: ZonedDateTime) {
295
+ export function zonedToDate(date: ZonedDateTime): Date {
296
296
  let ms = epochFromDate(date) - date.offset;
297
297
  return new Date(ms);
298
298
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {BuddhistCalendar} from './calendars/BuddhistCalendar';
14
- import {Calendar} from './types';
14
+ import {Calendar, CalendarIdentifier} from './types';
15
15
  import {CopticCalendar, EthiopicAmeteAlemCalendar, EthiopicCalendar} from './calendars/EthiopicCalendar';
16
16
  import {GregorianCalendar} from './calendars/GregorianCalendar';
17
17
  import {HebrewCalendar} from './calendars/HebrewCalendar';
@@ -22,7 +22,7 @@ import {PersianCalendar} from './calendars/PersianCalendar';
22
22
  import {TaiwanCalendar} from './calendars/TaiwanCalendar';
23
23
 
24
24
  /** Creates a `Calendar` instance from a Unicode calendar identifier string. */
25
- export function createCalendar(name: string): Calendar {
25
+ export function createCalendar(name: CalendarIdentifier): Calendar {
26
26
  switch (name) {
27
27
  case 'buddhist':
28
28
  return new BuddhistCalendar();
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export type {
15
15
  AnyTime,
16
16
  AnyDateTime,
17
17
  Calendar,
18
+ CalendarIdentifier,
18
19
  DateDuration,
19
20
  TimeDuration,
20
21
  DateTimeDuration,
@@ -74,7 +75,8 @@ export {
74
75
  minDate,
75
76
  maxDate,
76
77
  isWeekend,
77
- isWeekday
78
+ isWeekday,
79
+ isEqualCalendar
78
80
  } from './queries';
79
81
  export {
80
82
  parseDate,
@@ -21,7 +21,7 @@ const ONE_HOUR = 3600000;
21
21
  export function add(date: CalendarDateTime, duration: DateTimeDuration): CalendarDateTime;
22
22
  export function add(date: CalendarDate, duration: DateDuration): CalendarDate;
23
23
  export function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): CalendarDate | CalendarDateTime;
24
- export function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration) {
24
+ export function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): Mutable<AnyCalendarDate | AnyDateTime> {
25
25
  let mutableDate: Mutable<AnyCalendarDate | AnyDateTime> = date.copy();
26
26
  let days = 'hour' in mutableDate ? addTimeFields(mutableDate, duration) : 0;
27
27
 
@@ -118,7 +118,7 @@ function constrainMonthDay(date: Mutable<AnyCalendarDate>) {
118
118
  date.day = Math.max(1, Math.min(date.calendar.getDaysInMonth(date), date.day));
119
119
  }
120
120
 
121
- export function constrain(date: Mutable<AnyCalendarDate>) {
121
+ export function constrain(date: Mutable<AnyCalendarDate>): void {
122
122
  if (date.calendar.constrainDate) {
123
123
  date.calendar.constrainDate(date);
124
124
  }
@@ -146,7 +146,7 @@ export function subtract(date: CalendarDate | CalendarDateTime, duration: DateTi
146
146
 
147
147
  export function set(date: CalendarDateTime, fields: DateFields): CalendarDateTime;
148
148
  export function set(date: CalendarDate, fields: DateFields): CalendarDate;
149
- export function set(date: CalendarDate | CalendarDateTime, fields: DateFields) {
149
+ export function set(date: CalendarDate | CalendarDateTime, fields: DateFields): Mutable<AnyCalendarDate> {
150
150
  let mutableDate: Mutable<AnyCalendarDate> = date.copy();
151
151
 
152
152
  if (fields.era != null) {
@@ -171,7 +171,7 @@ export function set(date: CalendarDate | CalendarDateTime, fields: DateFields) {
171
171
 
172
172
  export function setTime(value: CalendarDateTime, fields: TimeFields): CalendarDateTime;
173
173
  export function setTime(value: Time, fields: TimeFields): Time;
174
- export function setTime(value: Time | CalendarDateTime, fields: TimeFields) {
174
+ export function setTime(value: Time | CalendarDateTime, fields: TimeFields): Mutable<Time | CalendarDateTime> {
175
175
  let mutableValue: Mutable<Time | CalendarDateTime> = value.copy();
176
176
 
177
177
  if (fields.hour != null) {
@@ -210,7 +210,7 @@ function balanceTime(time: Mutable<AnyTime>): number {
210
210
  return days;
211
211
  }
212
212
 
213
- export function constrainTime(time: Mutable<AnyTime>) {
213
+ export function constrainTime(time: Mutable<AnyTime>): void {
214
214
  time.millisecond = Math.max(0, Math.min(time.millisecond, 1000));
215
215
  time.second = Math.max(0, Math.min(time.second, 59));
216
216
  time.minute = Math.max(0, Math.min(time.minute, 59));
@@ -245,7 +245,7 @@ export function subtractTime(time: Time, duration: TimeDuration): Time {
245
245
 
246
246
  export function cycleDate(value: CalendarDateTime, field: DateField, amount: number, options?: CycleOptions): CalendarDateTime;
247
247
  export function cycleDate(value: CalendarDate, field: DateField, amount: number, options?: CycleOptions): CalendarDate;
248
- export function cycleDate(value: CalendarDate | CalendarDateTime, field: DateField, amount: number, options?: CycleOptions) {
248
+ export function cycleDate(value: CalendarDate | CalendarDateTime, field: DateField, amount: number, options?: CycleOptions): Mutable<CalendarDate | CalendarDateTime> {
249
249
  let mutable: Mutable<CalendarDate | CalendarDateTime> = value.copy();
250
250
 
251
251
  switch (field) {
@@ -300,7 +300,7 @@ export function cycleDate(value: CalendarDate | CalendarDateTime, field: DateFie
300
300
 
301
301
  export function cycleTime(value: CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions): CalendarDateTime;
302
302
  export function cycleTime(value: Time, field: TimeField, amount: number, options?: CycleTimeOptions): Time;
303
- export function cycleTime(value: Time | CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions) {
303
+ export function cycleTime(value: Time | CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions): Mutable<Time | CalendarDateTime> {
304
304
  let mutable: Mutable<Time | CalendarDateTime> = value.copy();
305
305
 
306
306
  switch (field) {