@isrd-isi-edu/ermrestjs 2.7.0 → 2.8.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.
@@ -286,6 +286,7 @@ export const _handlebarsHelpersList = [
286
286
  'toTitleCase',
287
287
  'replace',
288
288
  'humanizeBytes',
289
+ 'datetimeDuration',
289
290
  'printf',
290
291
  'stringLength',
291
292
  'isUserInAcl',
@@ -529,6 +530,83 @@ export const _sourceProperties = Object.freeze({
529
530
 
530
531
  export const _exportKnownAPIs = ['entity', 'attribute', 'attributegroup', 'aggregate'];
531
532
 
533
+ /**
534
+ * Named constants for the `unit` argument of `datetimeDuration`. Source of
535
+ * truth for valid unit values — `_datetimeDuration.VALID_UNITS` and
536
+ * `UNIT_ORDER` are derived from this object below.
537
+ *
538
+ * Includes the three pseudo-units (`AUTO`, `MULTI`, `CALENDAR`) alongside the
539
+ * seven real time units. Use `DurationRealUnit` for the real-unit subset.
540
+ */
541
+ export const DURATION_UNIT = Object.freeze({
542
+ AUTO: 'auto',
543
+ MULTI: 'multi',
544
+ CALENDAR: 'calendar',
545
+ YEAR: 'year',
546
+ MONTH: 'month',
547
+ DAY: 'day',
548
+ HOUR: 'hour',
549
+ MINUTE: 'minute',
550
+ SECOND: 'second',
551
+ MILLISECOND: 'millisecond',
552
+ } as const);
553
+ export type DurationUnit = (typeof DURATION_UNIT)[keyof typeof DURATION_UNIT];
554
+
555
+ /**
556
+ * Named constants for the `direction` argument of `datetimeDuration`. Source
557
+ * of truth for valid direction values — `_datetimeDuration.VALID_DIRECTIONS`
558
+ * is derived from this object below.
559
+ */
560
+ export const DURATION_DIRECTION = Object.freeze({
561
+ SIGN: 'sign',
562
+ BEFORE_AFTER: 'before/after',
563
+ EARLIER_LATER: 'earlier/later',
564
+ UNSIGNED: 'unsigned',
565
+ } as const);
566
+ export type DurationDirection = (typeof DURATION_DIRECTION)[keyof typeof DURATION_DIRECTION];
567
+
568
+ export const _datetimeDuration = Object.freeze({
569
+ // Real units in walking order (largest first). The source of truth for what
570
+ // counts as a "real" (non-pseudo) duration unit.
571
+ UNIT_ORDER: [
572
+ DURATION_UNIT.YEAR,
573
+ DURATION_UNIT.MONTH,
574
+ DURATION_UNIT.DAY,
575
+ DURATION_UNIT.HOUR,
576
+ DURATION_UNIT.MINUTE,
577
+ DURATION_UNIT.SECOND,
578
+ DURATION_UNIT.MILLISECOND,
579
+ ] as const,
580
+ ABBREVIATIONS: {
581
+ [DURATION_UNIT.YEAR]: 'Y',
582
+ [DURATION_UNIT.MONTH]: 'M',
583
+ [DURATION_UNIT.DAY]: 'D',
584
+ [DURATION_UNIT.HOUR]: 'h',
585
+ [DURATION_UNIT.MINUTE]: 'm',
586
+ [DURATION_UNIT.SECOND]: 's',
587
+ [DURATION_UNIT.MILLISECOND]: 'ms',
588
+ },
589
+ // Julian fixed-math constants (1Y = 365.25d, 1M = 365.25/12d).
590
+ // Self-consistent (12 * MONTH === YEAR), matches moment.js / date-fns / astronomy.
591
+ CONVERSION_RATES: {
592
+ [DURATION_UNIT.MILLISECOND]: 1,
593
+ [DURATION_UNIT.SECOND]: 1000,
594
+ [DURATION_UNIT.MINUTE]: 60 * 1000,
595
+ [DURATION_UNIT.HOUR]: 60 * 60 * 1000,
596
+ [DURATION_UNIT.DAY]: 24 * 60 * 60 * 1000,
597
+ [DURATION_UNIT.MONTH]: (365.25 / 12) * 24 * 60 * 60 * 1000, // 2,629,800,000
598
+ [DURATION_UNIT.YEAR]: 365.25 * 24 * 60 * 60 * 1000, // 31,557,600,000
599
+ },
600
+ VALID_UNITS: Object.values(DURATION_UNIT) as readonly DurationUnit[],
601
+ VALID_DIRECTIONS: Object.values(DURATION_DIRECTION) as readonly DurationDirection[],
602
+ });
603
+
604
+ /**
605
+ * The real (non-pseudo) subset of `DurationUnit`, derived from `UNIT_ORDER`
606
+ * so it stays in sync automatically.
607
+ */
608
+ export type DurationRealUnit = (typeof _datetimeDuration.UNIT_ORDER)[number];
609
+
532
610
  export const FILTER_TYPES = Object.freeze({
533
611
  BINARYPREDICATE: 'BinaryPredicate',
534
612
  CONJUNCTION: 'Conjunction',