@tsdotnet/date-time 2.0.8 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cjs/CalendarDate.d.ts +13 -0
  2. package/dist/cjs/Calendars/Gregorian.d.ts +27 -0
  3. package/dist/cjs/Calendars/Gregorian.js.map +1 -1
  4. package/dist/cjs/ClockTime.d.ts +20 -0
  5. package/dist/cjs/ClockTime.js.map +1 -1
  6. package/dist/cjs/ClockTimeValue.d.ts +15 -0
  7. package/dist/cjs/DateTime.d.ts +60 -0
  8. package/dist/cjs/DateTime.js.map +1 -1
  9. package/dist/cjs/DateTimeKind.d.ts +10 -0
  10. package/dist/cjs/DateTimeKind.js.map +1 -1
  11. package/dist/cjs/JsDateConvertible.d.ts +11 -0
  12. package/dist/cjs/TimeMeasurement.d.ts +16 -0
  13. package/dist/cjs/TimeQuantity.d.ts +19 -0
  14. package/dist/cjs/TimeQuantity.js.map +1 -1
  15. package/dist/cjs/TimeSpan.d.ts +33 -0
  16. package/dist/cjs/TimeSpan.js.map +1 -1
  17. package/dist/cjs/TimeStamp.d.ts +22 -0
  18. package/dist/cjs/TimeStamp.js.map +1 -1
  19. package/dist/cjs/TimeStampValue.d.ts +14 -0
  20. package/dist/cjs/TimeUnit.d.ts +21 -0
  21. package/dist/cjs/TimeUnit.js.map +1 -1
  22. package/dist/cjs/TimeUnitValue.d.ts +16 -0
  23. package/dist/cjs/TimeUnitValue.js.map +1 -1
  24. package/dist/cjs/date-time.d.ts +21 -0
  25. package/dist/cjs/date-time.js.map +1 -1
  26. package/dist/cjs/howMany.d.ts +36 -0
  27. package/dist/cjs/howMany.js.map +1 -1
  28. package/dist/cjs/howManyConstEnums.d.ts +55 -0
  29. package/dist/cjs/howManyConstEnums.js.map +1 -1
  30. package/dist/cjs/package.json +1 -0
  31. package/dist/esm/Calendars/Gregorian.js.map +1 -1
  32. package/dist/esm/ClockTime.js.map +1 -1
  33. package/dist/esm/DateTime.js.map +1 -1
  34. package/dist/esm/DateTimeKind.js.map +1 -1
  35. package/dist/esm/TimeQuantity.js.map +1 -1
  36. package/dist/esm/TimeSpan.js.map +1 -1
  37. package/dist/esm/TimeStamp.js.map +1 -1
  38. package/dist/esm/TimeUnit.js.map +1 -1
  39. package/dist/esm/TimeUnitValue.js.map +1 -1
  40. package/dist/esm/howMany.js.map +1 -1
  41. package/dist/umd/date-time.js +692 -0
  42. package/dist/umd/date-time.js.map +1 -0
  43. package/dist/umd/date-time.min.js +41 -0
  44. package/dist/umd/date-time.min.js.map +1 -0
  45. package/dist/umd/package.json +1 -0
  46. package/package.json +55 -24
@@ -0,0 +1,692 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsdotnet/compare'), require('@tsdotnet/exceptions'), require('@tsdotnet/lazy'), require('@tsdotnet/type')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tsdotnet/compare', '@tsdotnet/exceptions', '@tsdotnet/lazy', '@tsdotnet/type'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.tsdotnet = global.tsdotnet || {}, global.tsdotnet.dateTime = global.tsdotnet.dateTime || {}), global.tsdotnet.compare, global.tsdotnet.exceptions, global.tsdotnet.lazy, global.tsdotnet.type));
5
+ })(this, (function (exports, compare, exceptions, Lazy, type) { 'use strict';
6
+
7
+ /*!
8
+ * @author electricessence / https://github.com/electricessence/
9
+ * @license MIT
10
+ */
11
+ var Month;
12
+ (function (Month) {
13
+ Month[Month["January"] = 1] = "January";
14
+ Month[Month["February"] = 2] = "February";
15
+ Month[Month["March"] = 3] = "March";
16
+ Month[Month["April"] = 4] = "April";
17
+ Month[Month["May"] = 5] = "May";
18
+ Month[Month["June"] = 6] = "June";
19
+ Month[Month["July"] = 7] = "July";
20
+ Month[Month["August"] = 8] = "August";
21
+ Month[Month["September"] = 9] = "September";
22
+ Month[Month["October"] = 10] = "October";
23
+ Month[Month["November"] = 11] = "November";
24
+ Month[Month["December"] = 12] = "December";
25
+ })(Month || (Month = {}));
26
+ var DayOfWeek;
27
+ (function (DayOfWeek) {
28
+ DayOfWeek[DayOfWeek["Sunday"] = 0] = "Sunday";
29
+ DayOfWeek[DayOfWeek["Monday"] = 1] = "Monday";
30
+ DayOfWeek[DayOfWeek["Tuesday"] = 2] = "Tuesday";
31
+ DayOfWeek[DayOfWeek["Wednesday"] = 3] = "Wednesday";
32
+ DayOfWeek[DayOfWeek["Thursday"] = 4] = "Thursday";
33
+ DayOfWeek[DayOfWeek["Friday"] = 5] = "Friday";
34
+ DayOfWeek[DayOfWeek["Saturday"] = 6] = "Saturday";
35
+ })(DayOfWeek || (DayOfWeek = {}));
36
+
37
+ var Gregorian = /*#__PURE__*/Object.freeze({
38
+ __proto__: null,
39
+ get DayOfWeek () { return DayOfWeek; },
40
+ get Month () { return Month; }
41
+ });
42
+
43
+ /*!
44
+ * @author electricessence / https://github.com/electricessence/
45
+ * Originally based upon .NET source but with many additions and improvements.
46
+ * @license MIT
47
+ */
48
+ var TimeUnit;
49
+ (function (TimeUnit) {
50
+ let UnitType;
51
+ (function (UnitType) {
52
+ UnitType[UnitType["Ticks"] = 0] = "Ticks";
53
+ UnitType[UnitType["Milliseconds"] = 1] = "Milliseconds";
54
+ UnitType[UnitType["Seconds"] = 2] = "Seconds";
55
+ UnitType[UnitType["Minutes"] = 3] = "Minutes";
56
+ UnitType[UnitType["Hours"] = 4] = "Hours";
57
+ UnitType[UnitType["Days"] = 5] = "Days";
58
+ })(UnitType = TimeUnit.UnitType || (TimeUnit.UnitType = {}));
59
+ function toMilliseconds(value, units) {
60
+ switch (units) {
61
+ case UnitType.Days:
62
+ value *= 24;
63
+ case UnitType.Hours:
64
+ value *= 60;
65
+ case UnitType.Minutes:
66
+ value *= 60;
67
+ case UnitType.Seconds:
68
+ value *= 1000;
69
+ case UnitType.Milliseconds:
70
+ return value;
71
+ case UnitType.Ticks:
72
+ return value / 10000;
73
+ default:
74
+ throw new Error('Invalid TimeUnit.');
75
+ }
76
+ }
77
+ TimeUnit.toMilliseconds = toMilliseconds;
78
+ function fromMilliseconds(ms, units) {
79
+ switch (units) {
80
+ case UnitType.Days:
81
+ return ms / 86400000;
82
+ case UnitType.Hours:
83
+ return ms / 3600000;
84
+ case UnitType.Minutes:
85
+ return ms / 60000;
86
+ case UnitType.Seconds:
87
+ return ms / 1000;
88
+ case UnitType.Milliseconds:
89
+ return ms;
90
+ case UnitType.Ticks:
91
+ return ms * 10000;
92
+ default:
93
+ throw new Error('Invalid TimeUnit.');
94
+ }
95
+ }
96
+ TimeUnit.fromMilliseconds = fromMilliseconds;
97
+ function from(quantity, toUnits) {
98
+ return quantity && fromMilliseconds(quantity.getTotalMilliseconds(), toUnits);
99
+ }
100
+ TimeUnit.from = from;
101
+ function assertValid(unit) {
102
+ if (isNaN(unit) || unit > UnitType.Days || unit < UnitType.Ticks || Math.floor(unit) !== unit)
103
+ throw new Error('Invalid TimeUnit.');
104
+ return true;
105
+ }
106
+ TimeUnit.assertValid = assertValid;
107
+ })(TimeUnit || (TimeUnit = {}));
108
+ Object.freeze(TimeUnit.UnitType);
109
+ Object.freeze(TimeUnit);
110
+ var TimeUnit$1 = TimeUnit;
111
+
112
+ /*!
113
+ * @author electricessence / https://github.com/electricessence/
114
+ * @license MIT
115
+ */
116
+ class TimeQuantity {
117
+ _quantity;
118
+ constructor(_quantity = 0) {
119
+ this._quantity = _quantity;
120
+ this._total = Lazy.ResettableLazy.create(() => {
121
+ const ms = this.getTotalMilliseconds();
122
+ return Object.freeze({
123
+ ticks: ms * 10000,
124
+ milliseconds: ms,
125
+ seconds: ms / 1000,
126
+ minutes: ms / 60000,
127
+ hours: ms / 3600000,
128
+ days: ms / 86400000
129
+ });
130
+ });
131
+ }
132
+ static getTotalMillisecondsFrom(values) {
133
+ if (!values)
134
+ return 0;
135
+ return (values.days || 0) * 86400000 +
136
+ (values.hours || 0) * 3600000 +
137
+ (values.minutes || 0) * 60000 +
138
+ (values.seconds || 0) * 1000 +
139
+ (values.milliseconds || 0) +
140
+ (values.ticks || 0) / 10000;
141
+ }
142
+ get direction() {
143
+ return compare.compare(this.getTotalMilliseconds(), 0);
144
+ }
145
+ _total;
146
+ get total() {
147
+ return this._total.value;
148
+ }
149
+ getTotalMilliseconds() {
150
+ return this._quantity;
151
+ }
152
+ equals(other) {
153
+ if (!other || !other.total)
154
+ return false;
155
+ return compare.areEqual(this.getTotalMilliseconds(), other.total.milliseconds);
156
+ }
157
+ compareTo(other) {
158
+ if (!other)
159
+ throw new exceptions.ArgumentNullException('other');
160
+ if (!other.total)
161
+ throw new exceptions.ArgumentNullException('other.total');
162
+ return compare.compare(this.getTotalMilliseconds(), other && other.total && other.total.milliseconds);
163
+ }
164
+ getTotal(units) {
165
+ return TimeUnit$1.fromMilliseconds(this.getTotalMilliseconds(), units);
166
+ }
167
+ }
168
+
169
+ /*!
170
+ * @author electricessence / https://github.com/electricessence/
171
+ * @license MIT
172
+ */
173
+ class ClockTime extends TimeQuantity {
174
+ day;
175
+ hour;
176
+ minute;
177
+ second;
178
+ millisecond;
179
+ tick;
180
+ constructor(...args) {
181
+ super(args.length > 1
182
+ ? ClockTime.millisecondsFromTime(args[0] || 0, args[1] || 0, args.length > 2 && args[2] || 0, args.length > 3 && args[3] || 0)
183
+ : (args.length > 0 && args[0] || 0));
184
+ const ms = Math.abs(this.getTotalMilliseconds());
185
+ let msi = Math.floor(ms);
186
+ this.tick = (ms - msi) * 10000;
187
+ this.day = (msi / 86400000) | 0;
188
+ msi -= this.day * 86400000;
189
+ this.hour = (msi / 3600000) | 0;
190
+ msi -= this.hour * 3600000;
191
+ this.minute = (msi / 60000) | 0;
192
+ msi -= this.minute * 60000;
193
+ this.second = (msi / 1000) | 0;
194
+ msi -= this.second * 1000;
195
+ this.millisecond = msi;
196
+ Object.freeze(this);
197
+ }
198
+ static from(hours, minutes, seconds = 0, milliseconds = 0) {
199
+ return new ClockTime(hours, minutes, seconds, milliseconds);
200
+ }
201
+ static millisecondsFromTime(hours, minutes, seconds = 0, milliseconds = 0) {
202
+ let value = hours;
203
+ value *= 60;
204
+ value += minutes;
205
+ value *= 60;
206
+ value += seconds;
207
+ value *= 1000;
208
+ value += milliseconds;
209
+ return value;
210
+ }
211
+ toString() {
212
+ const _ = this;
213
+ const a = [];
214
+ if (_.day)
215
+ a.push(pluralize(_.day, 'day'));
216
+ if (_.hour)
217
+ a.push(pluralize(_.hour, 'hour'));
218
+ if (_.minute)
219
+ a.push(pluralize(_.minute, 'minute'));
220
+ if (_.second)
221
+ a.push(pluralize(_.second, 'second'));
222
+ if (a.length > 1)
223
+ a.splice(a.length - 1, 0, 'and');
224
+ return a.join(', ').replace(', and, ', ' and ');
225
+ }
226
+ }
227
+ function pluralize(value, label) {
228
+ if (Math.abs(value) !== 1)
229
+ label += 's';
230
+ return label;
231
+ }
232
+
233
+ /*!
234
+ * @author electricessence / https://github.com/electricessence/
235
+ * Originally based upon .NET source but with many additions and improvements.
236
+ * @license MIT
237
+ */
238
+ class TimeSpan extends TimeQuantity {
239
+ ticks;
240
+ milliseconds;
241
+ seconds;
242
+ minutes;
243
+ hours;
244
+ days;
245
+ constructor(value, units = TimeUnit$1.UnitType.Milliseconds) {
246
+ if (isNaN(value))
247
+ throw Error('Cannot construct a TimeSpan from NaN value.');
248
+ const ms = TimeUnit$1.toMilliseconds(value, units);
249
+ super(ms);
250
+ this.ticks = ms * 10000;
251
+ this.milliseconds = ms;
252
+ this.seconds = ms / 1000;
253
+ this.minutes = ms / 60000;
254
+ this.hours = ms / 3600000;
255
+ this.days = ms / 86400000;
256
+ this._time = Lazy.create(() => new ClockTime(this.getTotalMilliseconds()));
257
+ Object.freeze(this);
258
+ }
259
+ static get zero() {
260
+ return timeSpanZero || (timeSpanZero = new TimeSpan(0));
261
+ }
262
+ get total() {
263
+ return this;
264
+ }
265
+ _time;
266
+ get time() {
267
+ return this._time.value;
268
+ }
269
+ static from(value, units) {
270
+ if (!value)
271
+ return TimeSpan.zero;
272
+ if (typeof value === 'number') {
273
+ if (units === undefined)
274
+ throw new Error('A numerical value requires a TimeUnit.');
275
+ return new TimeSpan(value, units);
276
+ }
277
+ const ms = TimeQuantity.getTotalMillisecondsFrom(value);
278
+ return ms ? new TimeSpan(ms) : TimeSpan.zero;
279
+ }
280
+ static fromDays(value) {
281
+ return value ? new TimeSpan(value, TimeUnit$1.UnitType.Days) : TimeSpan.zero;
282
+ }
283
+ static fromHours(value) {
284
+ return value ? new TimeSpan(value, TimeUnit$1.UnitType.Hours) : TimeSpan.zero;
285
+ }
286
+ static fromMinutes(value) {
287
+ return value ? new TimeSpan(value, TimeUnit$1.UnitType.Minutes) : TimeSpan.zero;
288
+ }
289
+ static fromSeconds(value) {
290
+ return value ? new TimeSpan(value, TimeUnit$1.UnitType.Seconds) : TimeSpan.zero;
291
+ }
292
+ static fromMilliseconds(value) {
293
+ return value ? new TimeSpan(value) : TimeSpan.zero;
294
+ }
295
+ static fromTicks(value) {
296
+ return value ? new TimeSpan(value, TimeUnit$1.UnitType.Ticks) : TimeSpan.zero;
297
+ }
298
+ add(other) {
299
+ if (!other)
300
+ return this;
301
+ if (type.isNumber(other))
302
+ throw new Error('Use .addUnit(value:number, units:TimeUnit) to add a numerical value amount. Default units are milliseconds.\n' +
303
+ '.add only supports quantifiable time values (TimeQuantity).');
304
+ const otherMs = other instanceof TimeQuantity
305
+ ? other.total.milliseconds
306
+ : TimeQuantity.getTotalMillisecondsFrom(other);
307
+ return new TimeSpan(this.getTotalMilliseconds() + otherMs);
308
+ }
309
+ addUnit(value, units = TimeUnit$1.UnitType.Milliseconds) {
310
+ return value
311
+ ? new TimeSpan(this.getTotalMilliseconds() + TimeUnit$1.toMilliseconds(value, units))
312
+ : this;
313
+ }
314
+ }
315
+ let timeSpanZero;
316
+
317
+ /*!
318
+ * @author electricessence / https://github.com/electricessence/
319
+ * @license MIT
320
+ */
321
+ class TimeStamp {
322
+ year;
323
+ month;
324
+ day;
325
+ hour;
326
+ minute;
327
+ second;
328
+ millisecond;
329
+ tick;
330
+ constructor(year, month, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0, tick = 0) {
331
+ this.year = year;
332
+ this.month = month;
333
+ this.day = day;
334
+ this.hour = hour;
335
+ this.minute = minute;
336
+ this.second = second;
337
+ this.millisecond = millisecond;
338
+ this.tick = tick;
339
+ Object.freeze(this);
340
+ }
341
+ static from(d) {
342
+ if (!(d instanceof Date) && type.hasMember(d, 'toJsDate'))
343
+ d = d.toJsDate();
344
+ if (d instanceof Date) {
345
+ return new TimeStamp(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
346
+ }
347
+ else {
348
+ throw Error('Invalid date type.');
349
+ }
350
+ }
351
+ static now() {
352
+ return TimeStamp.from(new Date());
353
+ }
354
+ toJsDate() {
355
+ const _ = this;
356
+ return new Date(_.year, _.month, _.day, _.hour, _.minute, _.second, _.millisecond + _.tick / 10000);
357
+ }
358
+ }
359
+
360
+ /*!
361
+ * @author electricessence / https://github.com/electricessence/
362
+ * Based on .NET DateTime's interface.
363
+ * @license MIT
364
+ */
365
+ const VOID0 = void 0;
366
+ class DateTime {
367
+ _value;
368
+ _kind;
369
+ _time;
370
+ constructor(value = new Date(), kind = 1) {
371
+ this._kind = kind;
372
+ if (value instanceof DateTime) {
373
+ this._value = value.toJsDate();
374
+ if (kind === VOID0)
375
+ this._kind = value._kind;
376
+ }
377
+ else {
378
+ if (value instanceof Date)
379
+ this._value = new Date(value.getTime());
380
+ else
381
+ this._value = value === VOID0
382
+ ? new Date()
383
+ : new Date(value);
384
+ }
385
+ }
386
+ static get now() {
387
+ return new DateTime();
388
+ }
389
+ static get today() {
390
+ return DateTime.now.date;
391
+ }
392
+ static get tomorrow() {
393
+ const today = DateTime.today;
394
+ return today.addDays(1);
395
+ }
396
+ get kind() {
397
+ return this._kind;
398
+ }
399
+ get year() {
400
+ return this._value.getFullYear();
401
+ }
402
+ get month() {
403
+ return this._value.getMonth();
404
+ }
405
+ get calendarMonth() {
406
+ return this._value.getMonth() + 1;
407
+ }
408
+ get calendar() {
409
+ return {
410
+ year: this.year,
411
+ month: this.calendarMonth,
412
+ day: this.day
413
+ };
414
+ }
415
+ get day() {
416
+ return this._value.getDate();
417
+ }
418
+ get dayIndex() {
419
+ return this._value.getDate() - 1;
420
+ }
421
+ get dayOfWeek() {
422
+ return this._value.getDay();
423
+ }
424
+ get date() {
425
+ const _ = this;
426
+ return new DateTime(new Date(_.year, _.month, _.day), _._kind);
427
+ }
428
+ get timeOfDay() {
429
+ const _ = this;
430
+ let t = _._time;
431
+ if (!t) {
432
+ const d = this._value;
433
+ _._time = t = new ClockTime(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
434
+ }
435
+ return t;
436
+ }
437
+ static between(first, last) {
438
+ const f = first instanceof DateTime ? first._value : first, l = last instanceof DateTime ? last._value : last;
439
+ return TimeSpan.fromMilliseconds(l.getTime() - f.getTime());
440
+ }
441
+ static isLeapYear(year) {
442
+ return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
443
+ }
444
+ static daysInMonth(year, month) {
445
+ return (new Date(year, month + 1, 0)).getDate();
446
+ }
447
+ static from(yearOrDate, month = 0, day = 1) {
448
+ let year;
449
+ if (typeof yearOrDate == 'object') {
450
+ day = yearOrDate.day;
451
+ month = yearOrDate.month;
452
+ year = yearOrDate.year;
453
+ }
454
+ else {
455
+ year = yearOrDate;
456
+ }
457
+ return new DateTime(new Date(year, month, day));
458
+ }
459
+ static fromCalendarDate(yearOrDate, month = 1, day = 1) {
460
+ let year;
461
+ if (typeof yearOrDate == 'object') {
462
+ day = yearOrDate.day;
463
+ month = yearOrDate.month;
464
+ year = yearOrDate.year;
465
+ }
466
+ else {
467
+ year = yearOrDate;
468
+ }
469
+ return new DateTime(new Date(year, month - 1, day));
470
+ }
471
+ toJsDate() {
472
+ return new Date(this._value.getTime());
473
+ }
474
+ addMilliseconds(ms) {
475
+ ms = ms || 0;
476
+ return new DateTime(this._value.getTime() + ms, this._kind);
477
+ }
478
+ addSeconds(seconds) {
479
+ seconds = seconds || 0;
480
+ return this.addMilliseconds(seconds * 1000);
481
+ }
482
+ addMinutes(minutes) {
483
+ minutes = minutes || 0;
484
+ return this.addMilliseconds(minutes * 60000);
485
+ }
486
+ addHours(hours) {
487
+ hours = hours || 0;
488
+ return this.addMilliseconds(hours * 3600000);
489
+ }
490
+ addDays(days) {
491
+ days = days || 0;
492
+ return this.addMilliseconds(days * 86400000);
493
+ }
494
+ addMonths(months) {
495
+ months = months || 0;
496
+ const d = this.toJsDate();
497
+ d.setMonth(d.getMonth() + months);
498
+ return new DateTime(d, this._kind);
499
+ }
500
+ addYears(years) {
501
+ years = years || 0;
502
+ const d = this.toJsDate();
503
+ d.setFullYear(d.getFullYear() + years);
504
+ return new DateTime(d, this._kind);
505
+ }
506
+ add(time) {
507
+ return this.addMilliseconds(time.getTotalMilliseconds());
508
+ }
509
+ subtract(time) {
510
+ return this.addMilliseconds(-time.getTotalMilliseconds());
511
+ }
512
+ timePassedSince(previous) {
513
+ return DateTime.between(previous, this);
514
+ }
515
+ toTimeStamp() {
516
+ return TimeStamp.from(this);
517
+ }
518
+ toUniversalTime() {
519
+ const _ = this;
520
+ if (_._kind != 1)
521
+ return new DateTime(_, _._kind);
522
+ const d = _._value;
523
+ return new DateTime(new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()), 2);
524
+ }
525
+ equals(other, strict = false) {
526
+ if (!other)
527
+ return false;
528
+ if (other == this)
529
+ return true;
530
+ if (other instanceof Date) {
531
+ const v = this._value;
532
+ return other == v || other.getTime() == v.getTime();
533
+ }
534
+ if (other instanceof DateTime) {
535
+ if (strict) {
536
+ const ok = other._kind;
537
+ if (!ok && this._kind || ok != this._kind)
538
+ return false;
539
+ }
540
+ return this.equals(other._value);
541
+ }
542
+ else if (strict)
543
+ return false;
544
+ return this.equals(other.toJsDate());
545
+ }
546
+ compareTo(other) {
547
+ if (!other)
548
+ throw new exceptions.ArgumentNullException('other');
549
+ if (other == this)
550
+ return 0;
551
+ if (other instanceof DateTime) {
552
+ other = other._value;
553
+ }
554
+ const ms = this._value.getTime();
555
+ if (other instanceof Date) {
556
+ return ms - other.getTime();
557
+ }
558
+ return ms - other.toJsDate().getTime();
559
+ }
560
+ equivalent(other) {
561
+ if (!other)
562
+ return false;
563
+ if (other == this)
564
+ return true;
565
+ if (other instanceof Date) {
566
+ const v = this._value;
567
+ return v.toUTCString() == other.toUTCString();
568
+ }
569
+ if (this.equals(other, true))
570
+ return true;
571
+ return this.equivalent(other.toJsDate());
572
+ }
573
+ }
574
+
575
+ /*!
576
+ * @author electricessence / https://github.com/electricessence/
577
+ * @license MIT
578
+ */
579
+ var DateTimeKind;
580
+ (function (DateTimeKind) {
581
+ DateTimeKind[DateTimeKind["Unspecified"] = 0] = "Unspecified";
582
+ DateTimeKind[DateTimeKind["Local"] = 1] = "Local";
583
+ DateTimeKind[DateTimeKind["Utc"] = 2] = "Utc";
584
+ })(DateTimeKind || (DateTimeKind = {}));
585
+ var DateTimeKind_default = DateTimeKind;
586
+
587
+ var hours;
588
+ (function (hours) {
589
+ hours.per = Object.freeze({
590
+ day: 24
591
+ });
592
+ })(hours || (hours = {}));
593
+ Object.freeze(hours.per);
594
+ var minutes;
595
+ (function (minutes) {
596
+ minutes.per = Object.freeze({
597
+ hour: 60,
598
+ day: 1440
599
+ });
600
+ })(minutes || (minutes = {}));
601
+ Object.freeze(minutes.per);
602
+ var seconds;
603
+ (function (seconds) {
604
+ seconds.per = Object.freeze({
605
+ minute: 60,
606
+ hour: 3600,
607
+ day: 86400
608
+ });
609
+ })(seconds || (seconds = {}));
610
+ Object.freeze(seconds.per);
611
+ var milliseconds;
612
+ (function (milliseconds) {
613
+ milliseconds.per = Object.freeze({
614
+ second: 1000,
615
+ minute: 60000,
616
+ hour: 3600000,
617
+ day: 86400000
618
+ });
619
+ })(milliseconds || (milliseconds = {}));
620
+ Object.freeze(milliseconds.per);
621
+ var ticks;
622
+ (function (ticks) {
623
+ ticks.per = Object.freeze({
624
+ millisecond: 10000,
625
+ second: 10000000,
626
+ minute: 600000000,
627
+ hour: 36000000000,
628
+ day: 864000000000
629
+ });
630
+ })(ticks || (ticks = {}));
631
+ Object.freeze(ticks.per);
632
+
633
+ var howMany = /*#__PURE__*/Object.freeze({
634
+ __proto__: null,
635
+ get hours () { return hours; },
636
+ get milliseconds () { return milliseconds; },
637
+ get minutes () { return minutes; },
638
+ get seconds () { return seconds; },
639
+ get ticks () { return ticks; }
640
+ });
641
+
642
+ /*!
643
+ * @author electricessence / https://github.com/electricessence/
644
+ * @license MIT
645
+ */
646
+ class TimeUnitValue extends TimeQuantity {
647
+ _units;
648
+ constructor(value, _units) {
649
+ super(typeof value == 'number'
650
+ ? value
651
+ : getUnitQuantityFrom(value, _units));
652
+ this._units = _units;
653
+ TimeUnit$1.assertValid(_units);
654
+ }
655
+ get value() {
656
+ return this._quantity;
657
+ }
658
+ set value(v) {
659
+ this._quantity = v;
660
+ if (!this._total.tryReset())
661
+ throw new Error('Unable to update underlying value.');
662
+ }
663
+ get units() {
664
+ return this._units;
665
+ }
666
+ static from(value, units = TimeUnit$1.UnitType.Milliseconds) {
667
+ return new TimeUnitValue(value, units);
668
+ }
669
+ getTotalMilliseconds() {
670
+ return TimeUnit$1.toMilliseconds(this._quantity, this._units);
671
+ }
672
+ to(units = this.units) {
673
+ return TimeUnitValue.from(this, units);
674
+ }
675
+ }
676
+ function getUnitQuantityFrom(q, units) {
677
+ return TimeUnit$1.fromMilliseconds(q.getTotalMilliseconds(), units);
678
+ }
679
+
680
+ exports.ClockTime = ClockTime;
681
+ exports.DateTime = DateTime;
682
+ exports.DateTimeKind = DateTimeKind_default;
683
+ exports.Gregorian = Gregorian;
684
+ exports.TimeQuantity = TimeQuantity;
685
+ exports.TimeSpan = TimeSpan;
686
+ exports.TimeStamp = TimeStamp;
687
+ exports.TimeUnit = TimeUnit$1;
688
+ exports.TimeUnitValue = TimeUnitValue;
689
+ exports.howMany = howMany;
690
+
691
+ }));
692
+ //# sourceMappingURL=date-time.js.map