@dartcom/ui-kit 10.4.0 → 10.4.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 (36) hide show
  1. package/dist/components/buttons/delete/delete.stories.d.ts.map +1 -1
  2. package/dist/components/copy-text/copy-text.d.ts +5 -0
  3. package/dist/components/copy-text/copy-text.d.ts.map +1 -0
  4. package/dist/components/copy-text/copy-text.stories.d.ts +8 -0
  5. package/dist/components/copy-text/copy-text.stories.d.ts.map +1 -0
  6. package/dist/components/copy-text/index.d.ts +3 -0
  7. package/dist/components/copy-text/index.d.ts.map +1 -0
  8. package/dist/components/copy-text/styles.d.ts +6 -0
  9. package/dist/components/copy-text/styles.d.ts.map +1 -0
  10. package/dist/components/copy-text/types.d.ts +9 -0
  11. package/dist/components/copy-text/types.d.ts.map +1 -0
  12. package/dist/components/index.d.ts +1 -0
  13. package/dist/components/index.d.ts.map +1 -1
  14. package/dist/components/paragraph/index.d.ts +1 -0
  15. package/dist/components/paragraph/index.d.ts.map +1 -1
  16. package/dist/components/paragraph/paragraph.d.ts +2 -2
  17. package/dist/components/paragraph/paragraph.d.ts.map +1 -1
  18. package/dist/components/paragraph/styles.d.ts +2 -0
  19. package/dist/components/paragraph/styles.d.ts.map +1 -0
  20. package/dist/components/paragraph/types.d.ts +3 -0
  21. package/dist/components/paragraph/types.d.ts.map +1 -0
  22. package/dist/index.cjs +2961 -387
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.esm.js +7 -7
  25. package/dist/index.esm.js.map +1 -1
  26. package/dist/services/index.d.ts +1 -0
  27. package/dist/services/index.d.ts.map +1 -1
  28. package/dist/services/localization/index.d.ts +2 -0
  29. package/dist/services/localization/index.d.ts.map +1 -0
  30. package/dist/services/localization/localization.d.ts +10 -0
  31. package/dist/services/localization/localization.d.ts.map +1 -0
  32. package/dist/services/localization/localization.spec.d.ts +2 -0
  33. package/dist/services/localization/localization.spec.d.ts.map +1 -0
  34. package/dist/shared/index.d.ts +1 -0
  35. package/dist/shared/index.d.ts.map +1 -0
  36. package/package.json +5 -5
package/dist/index.cjs CHANGED
@@ -19,7 +19,6 @@ var SaveIcon = require('@mui/icons-material/Save');
19
19
  var CloudUploadIcon = require('@mui/icons-material/CloudUpload');
20
20
  var Checkbox = require('@mui/material/Checkbox');
21
21
  var FormControlLabel = require('@mui/material/FormControlLabel');
22
- var Typography = require('@mui/material/Typography');
23
22
  var DateField$1 = require('@mui/x-date-pickers/DateField');
24
23
  var Box = require('@mui/material/Box');
25
24
  var Modal = require('@mui/material/Modal');
@@ -7562,6 +7561,2837 @@ class LocalStateService {
7562
7561
  }
7563
7562
  const localStateService = new LocalStateService();
7564
7563
 
7564
+ /**
7565
+ * @module constants
7566
+ * @summary Useful constants
7567
+ * @description
7568
+ * Collection of useful date constants.
7569
+ *
7570
+ * The constants could be imported from `date-fns/constants`:
7571
+ *
7572
+ * ```ts
7573
+ * import { maxTime, minTime } from "./constants/date-fns/constants";
7574
+ *
7575
+ * function isAllowedTime(time) {
7576
+ * return time <= maxTime && time >= minTime;
7577
+ * }
7578
+ * ```
7579
+ */
7580
+
7581
+
7582
+ /**
7583
+ * @constant
7584
+ * @name millisecondsInWeek
7585
+ * @summary Milliseconds in 1 week.
7586
+ */
7587
+ const millisecondsInWeek = 604800000;
7588
+
7589
+ /**
7590
+ * @constant
7591
+ * @name millisecondsInDay
7592
+ * @summary Milliseconds in 1 day.
7593
+ */
7594
+ const millisecondsInDay = 86400000;
7595
+
7596
+ /**
7597
+ * @constant
7598
+ * @name constructFromSymbol
7599
+ * @summary Symbol enabling Date extensions to inherit properties from the reference date.
7600
+ *
7601
+ * The symbol is used to enable the `constructFrom` function to construct a date
7602
+ * using a reference date and a value. It allows to transfer extra properties
7603
+ * from the reference date to the new date. It's useful for extensions like
7604
+ * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
7605
+ * a constructor argument.
7606
+ */
7607
+ const constructFromSymbol = Symbol.for("constructDateFrom");
7608
+
7609
+ /**
7610
+ * @name constructFrom
7611
+ * @category Generic Helpers
7612
+ * @summary Constructs a date using the reference date and the value
7613
+ *
7614
+ * @description
7615
+ * The function constructs a new date using the constructor from the reference
7616
+ * date and the given value. It helps to build generic functions that accept
7617
+ * date extensions.
7618
+ *
7619
+ * It defaults to `Date` if the passed reference date is a number or a string.
7620
+ *
7621
+ * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
7622
+ * enabling to transfer extra properties from the reference date to the new date.
7623
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
7624
+ * that accept a time zone as a constructor argument.
7625
+ *
7626
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
7627
+ *
7628
+ * @param date - The reference date to take constructor from
7629
+ * @param value - The value to create the date
7630
+ *
7631
+ * @returns Date initialized using the given date and value
7632
+ *
7633
+ * @example
7634
+ * import { constructFrom } from "./constructFrom/date-fns";
7635
+ *
7636
+ * // A function that clones a date preserving the original type
7637
+ * function cloneDate<DateType extends Date>(date: DateType): DateType {
7638
+ * return constructFrom(
7639
+ * date, // Use constructor from the given date
7640
+ * date.getTime() // Use the date value to create a new date
7641
+ * );
7642
+ * }
7643
+ */
7644
+ function constructFrom(date, value) {
7645
+ if (typeof date === "function") return date(value);
7646
+
7647
+ if (date && typeof date === "object" && constructFromSymbol in date)
7648
+ return date[constructFromSymbol](value);
7649
+
7650
+ if (date instanceof Date) return new date.constructor(value);
7651
+
7652
+ return new Date(value);
7653
+ }
7654
+
7655
+ /**
7656
+ * @name toDate
7657
+ * @category Common Helpers
7658
+ * @summary Convert the given argument to an instance of Date.
7659
+ *
7660
+ * @description
7661
+ * Convert the given argument to an instance of Date.
7662
+ *
7663
+ * If the argument is an instance of Date, the function returns its clone.
7664
+ *
7665
+ * If the argument is a number, it is treated as a timestamp.
7666
+ *
7667
+ * If the argument is none of the above, the function returns Invalid Date.
7668
+ *
7669
+ * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
7670
+ * enabling to transfer extra properties from the reference date to the new date.
7671
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
7672
+ * that accept a time zone as a constructor argument.
7673
+ *
7674
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
7675
+ *
7676
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
7677
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
7678
+ *
7679
+ * @param argument - The value to convert
7680
+ *
7681
+ * @returns The parsed date in the local time zone
7682
+ *
7683
+ * @example
7684
+ * // Clone the date:
7685
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
7686
+ * //=> Tue Feb 11 2014 11:30:30
7687
+ *
7688
+ * @example
7689
+ * // Convert the timestamp to date:
7690
+ * const result = toDate(1392098430000)
7691
+ * //=> Tue Feb 11 2014 11:30:30
7692
+ */
7693
+ function toDate(argument, context) {
7694
+ // [TODO] Get rid of `toDate` or `constructFrom`?
7695
+ return constructFrom(context || argument, argument);
7696
+ }
7697
+
7698
+ let defaultOptions$2 = {};
7699
+
7700
+ function getDefaultOptions() {
7701
+ return defaultOptions$2;
7702
+ }
7703
+
7704
+ /**
7705
+ * The {@link startOfWeek} function options.
7706
+ */
7707
+
7708
+ /**
7709
+ * @name startOfWeek
7710
+ * @category Week Helpers
7711
+ * @summary Return the start of a week for the given date.
7712
+ *
7713
+ * @description
7714
+ * Return the start of a week for the given date.
7715
+ * The result will be in the local timezone.
7716
+ *
7717
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
7718
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
7719
+ *
7720
+ * @param date - The original date
7721
+ * @param options - An object with options
7722
+ *
7723
+ * @returns The start of a week
7724
+ *
7725
+ * @example
7726
+ * // The start of a week for 2 September 2014 11:55:00:
7727
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
7728
+ * //=> Sun Aug 31 2014 00:00:00
7729
+ *
7730
+ * @example
7731
+ * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
7732
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
7733
+ * //=> Mon Sep 01 2014 00:00:00
7734
+ */
7735
+ function startOfWeek(date, options) {
7736
+ const defaultOptions = getDefaultOptions();
7737
+ const weekStartsOn =
7738
+ options?.weekStartsOn ??
7739
+ options?.locale?.options?.weekStartsOn ??
7740
+ defaultOptions.weekStartsOn ??
7741
+ defaultOptions.locale?.options?.weekStartsOn ??
7742
+ 0;
7743
+
7744
+ const _date = toDate(date, options?.in);
7745
+ const day = _date.getDay();
7746
+ const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
7747
+
7748
+ _date.setDate(_date.getDate() - diff);
7749
+ _date.setHours(0, 0, 0, 0);
7750
+ return _date;
7751
+ }
7752
+
7753
+ /**
7754
+ * The {@link startOfISOWeek} function options.
7755
+ */
7756
+
7757
+ /**
7758
+ * @name startOfISOWeek
7759
+ * @category ISO Week Helpers
7760
+ * @summary Return the start of an ISO week for the given date.
7761
+ *
7762
+ * @description
7763
+ * Return the start of an ISO week for the given date.
7764
+ * The result will be in the local timezone.
7765
+ *
7766
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
7767
+ *
7768
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
7769
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
7770
+ *
7771
+ * @param date - The original date
7772
+ * @param options - An object with options
7773
+ *
7774
+ * @returns The start of an ISO week
7775
+ *
7776
+ * @example
7777
+ * // The start of an ISO week for 2 September 2014 11:55:00:
7778
+ * const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0))
7779
+ * //=> Mon Sep 01 2014 00:00:00
7780
+ */
7781
+ function startOfISOWeek(date, options) {
7782
+ return startOfWeek(date, { ...options, weekStartsOn: 1 });
7783
+ }
7784
+
7785
+ /**
7786
+ * The {@link getISOWeekYear} function options.
7787
+ */
7788
+
7789
+ /**
7790
+ * @name getISOWeekYear
7791
+ * @category ISO Week-Numbering Year Helpers
7792
+ * @summary Get the ISO week-numbering year of the given date.
7793
+ *
7794
+ * @description
7795
+ * Get the ISO week-numbering year of the given date,
7796
+ * which always starts 3 days before the year's first Thursday.
7797
+ *
7798
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
7799
+ *
7800
+ * @param date - The given date
7801
+ *
7802
+ * @returns The ISO week-numbering year
7803
+ *
7804
+ * @example
7805
+ * // Which ISO-week numbering year is 2 January 2005?
7806
+ * const result = getISOWeekYear(new Date(2005, 0, 2))
7807
+ * //=> 2004
7808
+ */
7809
+ function getISOWeekYear(date, options) {
7810
+ const _date = toDate(date, options?.in);
7811
+ const year = _date.getFullYear();
7812
+
7813
+ const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
7814
+ fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
7815
+ fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
7816
+ const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
7817
+
7818
+ const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
7819
+ fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
7820
+ fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
7821
+ const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
7822
+
7823
+ if (_date.getTime() >= startOfNextYear.getTime()) {
7824
+ return year + 1;
7825
+ } else if (_date.getTime() >= startOfThisYear.getTime()) {
7826
+ return year;
7827
+ } else {
7828
+ return year - 1;
7829
+ }
7830
+ }
7831
+
7832
+ /**
7833
+ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
7834
+ * They usually appear for dates that denote time before the timezones were introduced
7835
+ * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
7836
+ * and GMT+01:00:00 after that date)
7837
+ *
7838
+ * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
7839
+ * which would lead to incorrect calculations.
7840
+ *
7841
+ * This function returns the timezone offset in milliseconds that takes seconds in account.
7842
+ */
7843
+ function getTimezoneOffsetInMilliseconds(date) {
7844
+ const _date = toDate(date);
7845
+ const utcDate = new Date(
7846
+ Date.UTC(
7847
+ _date.getFullYear(),
7848
+ _date.getMonth(),
7849
+ _date.getDate(),
7850
+ _date.getHours(),
7851
+ _date.getMinutes(),
7852
+ _date.getSeconds(),
7853
+ _date.getMilliseconds(),
7854
+ ),
7855
+ );
7856
+ utcDate.setUTCFullYear(_date.getFullYear());
7857
+ return +date - +utcDate;
7858
+ }
7859
+
7860
+ function normalizeDates(context, ...dates) {
7861
+ const normalize = constructFrom.bind(
7862
+ null,
7863
+ context || dates.find((date) => typeof date === "object"),
7864
+ );
7865
+ return dates.map(normalize);
7866
+ }
7867
+
7868
+ /**
7869
+ * The {@link startOfDay} function options.
7870
+ */
7871
+
7872
+ /**
7873
+ * @name startOfDay
7874
+ * @category Day Helpers
7875
+ * @summary Return the start of a day for the given date.
7876
+ *
7877
+ * @description
7878
+ * Return the start of a day for the given date.
7879
+ * The result will be in the local timezone.
7880
+ *
7881
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
7882
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
7883
+ *
7884
+ * @param date - The original date
7885
+ * @param options - The options
7886
+ *
7887
+ * @returns The start of a day
7888
+ *
7889
+ * @example
7890
+ * // The start of a day for 2 September 2014 11:55:00:
7891
+ * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
7892
+ * //=> Tue Sep 02 2014 00:00:00
7893
+ */
7894
+ function startOfDay(date, options) {
7895
+ const _date = toDate(date, options?.in);
7896
+ _date.setHours(0, 0, 0, 0);
7897
+ return _date;
7898
+ }
7899
+
7900
+ /**
7901
+ * The {@link differenceInCalendarDays} function options.
7902
+ */
7903
+
7904
+ /**
7905
+ * @name differenceInCalendarDays
7906
+ * @category Day Helpers
7907
+ * @summary Get the number of calendar days between the given dates.
7908
+ *
7909
+ * @description
7910
+ * Get the number of calendar days between the given dates. This means that the times are removed
7911
+ * from the dates and then the difference in days is calculated.
7912
+ *
7913
+ * @param laterDate - The later date
7914
+ * @param earlierDate - The earlier date
7915
+ * @param options - The options object
7916
+ *
7917
+ * @returns The number of calendar days
7918
+ *
7919
+ * @example
7920
+ * // How many calendar days are between
7921
+ * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
7922
+ * const result = differenceInCalendarDays(
7923
+ * new Date(2012, 6, 2, 0, 0),
7924
+ * new Date(2011, 6, 2, 23, 0)
7925
+ * )
7926
+ * //=> 366
7927
+ * // How many calendar days are between
7928
+ * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
7929
+ * const result = differenceInCalendarDays(
7930
+ * new Date(2011, 6, 3, 0, 1),
7931
+ * new Date(2011, 6, 2, 23, 59)
7932
+ * )
7933
+ * //=> 1
7934
+ */
7935
+ function differenceInCalendarDays(laterDate, earlierDate, options) {
7936
+ const [laterDate_, earlierDate_] = normalizeDates(
7937
+ options?.in,
7938
+ laterDate,
7939
+ earlierDate,
7940
+ );
7941
+
7942
+ const laterStartOfDay = startOfDay(laterDate_);
7943
+ const earlierStartOfDay = startOfDay(earlierDate_);
7944
+
7945
+ const laterTimestamp =
7946
+ +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
7947
+ const earlierTimestamp =
7948
+ +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
7949
+
7950
+ // Round the number of days to the nearest integer because the number of
7951
+ // milliseconds in a day is not constant (e.g. it's different in the week of
7952
+ // the daylight saving time clock shift).
7953
+ return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
7954
+ }
7955
+
7956
+ /**
7957
+ * The {@link startOfISOWeekYear} function options.
7958
+ */
7959
+
7960
+ /**
7961
+ * @name startOfISOWeekYear
7962
+ * @category ISO Week-Numbering Year Helpers
7963
+ * @summary Return the start of an ISO week-numbering year for the given date.
7964
+ *
7965
+ * @description
7966
+ * Return the start of an ISO week-numbering year,
7967
+ * which always starts 3 days before the year's first Thursday.
7968
+ * The result will be in the local timezone.
7969
+ *
7970
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
7971
+ *
7972
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
7973
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
7974
+ *
7975
+ * @param date - The original date
7976
+ * @param options - An object with options
7977
+ *
7978
+ * @returns The start of an ISO week-numbering year
7979
+ *
7980
+ * @example
7981
+ * // The start of an ISO week-numbering year for 2 July 2005:
7982
+ * const result = startOfISOWeekYear(new Date(2005, 6, 2))
7983
+ * //=> Mon Jan 03 2005 00:00:00
7984
+ */
7985
+ function startOfISOWeekYear(date, options) {
7986
+ const year = getISOWeekYear(date, options);
7987
+ const fourthOfJanuary = constructFrom(date, 0);
7988
+ fourthOfJanuary.setFullYear(year, 0, 4);
7989
+ fourthOfJanuary.setHours(0, 0, 0, 0);
7990
+ return startOfISOWeek(fourthOfJanuary);
7991
+ }
7992
+
7993
+ /**
7994
+ * @name isDate
7995
+ * @category Common Helpers
7996
+ * @summary Is the given value a date?
7997
+ *
7998
+ * @description
7999
+ * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
8000
+ *
8001
+ * @param value - The value to check
8002
+ *
8003
+ * @returns True if the given value is a date
8004
+ *
8005
+ * @example
8006
+ * // For a valid date:
8007
+ * const result = isDate(new Date())
8008
+ * //=> true
8009
+ *
8010
+ * @example
8011
+ * // For an invalid date:
8012
+ * const result = isDate(new Date(NaN))
8013
+ * //=> true
8014
+ *
8015
+ * @example
8016
+ * // For some value:
8017
+ * const result = isDate('2014-02-31')
8018
+ * //=> false
8019
+ *
8020
+ * @example
8021
+ * // For an object:
8022
+ * const result = isDate({})
8023
+ * //=> false
8024
+ */
8025
+ function isDate$1(value) {
8026
+ return (
8027
+ value instanceof Date ||
8028
+ (typeof value === "object" &&
8029
+ Object.prototype.toString.call(value) === "[object Date]")
8030
+ );
8031
+ }
8032
+
8033
+ /**
8034
+ * @name isValid
8035
+ * @category Common Helpers
8036
+ * @summary Is the given date valid?
8037
+ *
8038
+ * @description
8039
+ * Returns false if argument is Invalid Date and true otherwise.
8040
+ * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate)
8041
+ * Invalid Date is a Date, whose time value is NaN.
8042
+ *
8043
+ * Time value of Date: http://es5.github.io/#x15.9.1.1
8044
+ *
8045
+ * @param date - The date to check
8046
+ *
8047
+ * @returns The date is valid
8048
+ *
8049
+ * @example
8050
+ * // For the valid date:
8051
+ * const result = isValid(new Date(2014, 1, 31))
8052
+ * //=> true
8053
+ *
8054
+ * @example
8055
+ * // For the value, convertible into a date:
8056
+ * const result = isValid(1393804800000)
8057
+ * //=> true
8058
+ *
8059
+ * @example
8060
+ * // For the invalid date:
8061
+ * const result = isValid(new Date(''))
8062
+ * //=> false
8063
+ */
8064
+ function isValid(date) {
8065
+ return !((!isDate$1(date) && typeof date !== "number") || isNaN(+toDate(date)));
8066
+ }
8067
+
8068
+ /**
8069
+ * The {@link startOfYear} function options.
8070
+ */
8071
+
8072
+ /**
8073
+ * @name startOfYear
8074
+ * @category Year Helpers
8075
+ * @summary Return the start of a year for the given date.
8076
+ *
8077
+ * @description
8078
+ * Return the start of a year for the given date.
8079
+ * The result will be in the local timezone.
8080
+ *
8081
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
8082
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
8083
+ *
8084
+ * @param date - The original date
8085
+ * @param options - The options
8086
+ *
8087
+ * @returns The start of a year
8088
+ *
8089
+ * @example
8090
+ * // The start of a year for 2 September 2014 11:55:00:
8091
+ * const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00))
8092
+ * //=> Wed Jan 01 2014 00:00:00
8093
+ */
8094
+ function startOfYear(date, options) {
8095
+ const date_ = toDate(date, options?.in);
8096
+ date_.setFullYear(date_.getFullYear(), 0, 1);
8097
+ date_.setHours(0, 0, 0, 0);
8098
+ return date_;
8099
+ }
8100
+
8101
+ const formatDistanceLocale$1 = {
8102
+ lessThanXSeconds: {
8103
+ one: "less than a second",
8104
+ other: "less than {{count}} seconds",
8105
+ },
8106
+
8107
+ xSeconds: {
8108
+ one: "1 second",
8109
+ other: "{{count}} seconds",
8110
+ },
8111
+
8112
+ halfAMinute: "half a minute",
8113
+
8114
+ lessThanXMinutes: {
8115
+ one: "less than a minute",
8116
+ other: "less than {{count}} minutes",
8117
+ },
8118
+
8119
+ xMinutes: {
8120
+ one: "1 minute",
8121
+ other: "{{count}} minutes",
8122
+ },
8123
+
8124
+ aboutXHours: {
8125
+ one: "about 1 hour",
8126
+ other: "about {{count}} hours",
8127
+ },
8128
+
8129
+ xHours: {
8130
+ one: "1 hour",
8131
+ other: "{{count}} hours",
8132
+ },
8133
+
8134
+ xDays: {
8135
+ one: "1 day",
8136
+ other: "{{count}} days",
8137
+ },
8138
+
8139
+ aboutXWeeks: {
8140
+ one: "about 1 week",
8141
+ other: "about {{count}} weeks",
8142
+ },
8143
+
8144
+ xWeeks: {
8145
+ one: "1 week",
8146
+ other: "{{count}} weeks",
8147
+ },
8148
+
8149
+ aboutXMonths: {
8150
+ one: "about 1 month",
8151
+ other: "about {{count}} months",
8152
+ },
8153
+
8154
+ xMonths: {
8155
+ one: "1 month",
8156
+ other: "{{count}} months",
8157
+ },
8158
+
8159
+ aboutXYears: {
8160
+ one: "about 1 year",
8161
+ other: "about {{count}} years",
8162
+ },
8163
+
8164
+ xYears: {
8165
+ one: "1 year",
8166
+ other: "{{count}} years",
8167
+ },
8168
+
8169
+ overXYears: {
8170
+ one: "over 1 year",
8171
+ other: "over {{count}} years",
8172
+ },
8173
+
8174
+ almostXYears: {
8175
+ one: "almost 1 year",
8176
+ other: "almost {{count}} years",
8177
+ },
8178
+ };
8179
+
8180
+ const formatDistance$1 = (token, count, options) => {
8181
+ let result;
8182
+
8183
+ const tokenValue = formatDistanceLocale$1[token];
8184
+ if (typeof tokenValue === "string") {
8185
+ result = tokenValue;
8186
+ } else if (count === 1) {
8187
+ result = tokenValue.one;
8188
+ } else {
8189
+ result = tokenValue.other.replace("{{count}}", count.toString());
8190
+ }
8191
+
8192
+ if (options?.addSuffix) {
8193
+ if (options.comparison && options.comparison > 0) {
8194
+ return "in " + result;
8195
+ } else {
8196
+ return result + " ago";
8197
+ }
8198
+ }
8199
+
8200
+ return result;
8201
+ };
8202
+
8203
+ function buildFormatLongFn(args) {
8204
+ return (options = {}) => {
8205
+ // TODO: Remove String()
8206
+ const width = options.width ? String(options.width) : args.defaultWidth;
8207
+ const format = args.formats[width] || args.formats[args.defaultWidth];
8208
+ return format;
8209
+ };
8210
+ }
8211
+
8212
+ const dateFormats$1 = {
8213
+ full: "EEEE, MMMM do, y",
8214
+ long: "MMMM do, y",
8215
+ medium: "MMM d, y",
8216
+ short: "MM/dd/yyyy",
8217
+ };
8218
+
8219
+ const timeFormats$1 = {
8220
+ full: "h:mm:ss a zzzz",
8221
+ long: "h:mm:ss a z",
8222
+ medium: "h:mm:ss a",
8223
+ short: "h:mm a",
8224
+ };
8225
+
8226
+ const dateTimeFormats$1 = {
8227
+ full: "{{date}} 'at' {{time}}",
8228
+ long: "{{date}} 'at' {{time}}",
8229
+ medium: "{{date}}, {{time}}",
8230
+ short: "{{date}}, {{time}}",
8231
+ };
8232
+
8233
+ const formatLong$1 = {
8234
+ date: buildFormatLongFn({
8235
+ formats: dateFormats$1,
8236
+ defaultWidth: "full",
8237
+ }),
8238
+
8239
+ time: buildFormatLongFn({
8240
+ formats: timeFormats$1,
8241
+ defaultWidth: "full",
8242
+ }),
8243
+
8244
+ dateTime: buildFormatLongFn({
8245
+ formats: dateTimeFormats$1,
8246
+ defaultWidth: "full",
8247
+ }),
8248
+ };
8249
+
8250
+ const formatRelativeLocale$1 = {
8251
+ lastWeek: "'last' eeee 'at' p",
8252
+ yesterday: "'yesterday at' p",
8253
+ today: "'today at' p",
8254
+ tomorrow: "'tomorrow at' p",
8255
+ nextWeek: "eeee 'at' p",
8256
+ other: "P",
8257
+ };
8258
+
8259
+ const formatRelative$1 = (token, _date, _baseDate, _options) =>
8260
+ formatRelativeLocale$1[token];
8261
+
8262
+ /**
8263
+ * The localize function argument callback which allows to convert raw value to
8264
+ * the actual type.
8265
+ *
8266
+ * @param value - The value to convert
8267
+ *
8268
+ * @returns The converted value
8269
+ */
8270
+
8271
+ /**
8272
+ * The map of localized values for each width.
8273
+ */
8274
+
8275
+ /**
8276
+ * The index type of the locale unit value. It types conversion of units of
8277
+ * values that don't start at 0 (i.e. quarters).
8278
+ */
8279
+
8280
+ /**
8281
+ * Converts the unit value to the tuple of values.
8282
+ */
8283
+
8284
+ /**
8285
+ * The tuple of localized era values. The first element represents BC,
8286
+ * the second element represents AD.
8287
+ */
8288
+
8289
+ /**
8290
+ * The tuple of localized quarter values. The first element represents Q1.
8291
+ */
8292
+
8293
+ /**
8294
+ * The tuple of localized day values. The first element represents Sunday.
8295
+ */
8296
+
8297
+ /**
8298
+ * The tuple of localized month values. The first element represents January.
8299
+ */
8300
+
8301
+ function buildLocalizeFn(args) {
8302
+ return (value, options) => {
8303
+ const context = options?.context ? String(options.context) : "standalone";
8304
+
8305
+ let valuesArray;
8306
+ if (context === "formatting" && args.formattingValues) {
8307
+ const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
8308
+ const width = options?.width ? String(options.width) : defaultWidth;
8309
+
8310
+ valuesArray =
8311
+ args.formattingValues[width] || args.formattingValues[defaultWidth];
8312
+ } else {
8313
+ const defaultWidth = args.defaultWidth;
8314
+ const width = options?.width ? String(options.width) : args.defaultWidth;
8315
+
8316
+ valuesArray = args.values[width] || args.values[defaultWidth];
8317
+ }
8318
+ const index = args.argumentCallback ? args.argumentCallback(value) : value;
8319
+
8320
+ // @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
8321
+ return valuesArray[index];
8322
+ };
8323
+ }
8324
+
8325
+ const eraValues$1 = {
8326
+ narrow: ["B", "A"],
8327
+ abbreviated: ["BC", "AD"],
8328
+ wide: ["Before Christ", "Anno Domini"],
8329
+ };
8330
+
8331
+ const quarterValues$1 = {
8332
+ narrow: ["1", "2", "3", "4"],
8333
+ abbreviated: ["Q1", "Q2", "Q3", "Q4"],
8334
+ wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
8335
+ };
8336
+
8337
+ // Note: in English, the names of days of the week and months are capitalized.
8338
+ // If you are making a new locale based on this one, check if the same is true for the language you're working on.
8339
+ // Generally, formatted dates should look like they are in the middle of a sentence,
8340
+ // e.g. in Spanish language the weekdays and months should be in the lowercase.
8341
+ const monthValues$1 = {
8342
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
8343
+ abbreviated: [
8344
+ "Jan",
8345
+ "Feb",
8346
+ "Mar",
8347
+ "Apr",
8348
+ "May",
8349
+ "Jun",
8350
+ "Jul",
8351
+ "Aug",
8352
+ "Sep",
8353
+ "Oct",
8354
+ "Nov",
8355
+ "Dec",
8356
+ ],
8357
+
8358
+ wide: [
8359
+ "January",
8360
+ "February",
8361
+ "March",
8362
+ "April",
8363
+ "May",
8364
+ "June",
8365
+ "July",
8366
+ "August",
8367
+ "September",
8368
+ "October",
8369
+ "November",
8370
+ "December",
8371
+ ],
8372
+ };
8373
+
8374
+ const dayValues$1 = {
8375
+ narrow: ["S", "M", "T", "W", "T", "F", "S"],
8376
+ short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
8377
+ abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
8378
+ wide: [
8379
+ "Sunday",
8380
+ "Monday",
8381
+ "Tuesday",
8382
+ "Wednesday",
8383
+ "Thursday",
8384
+ "Friday",
8385
+ "Saturday",
8386
+ ],
8387
+ };
8388
+
8389
+ const dayPeriodValues$1 = {
8390
+ narrow: {
8391
+ am: "a",
8392
+ pm: "p",
8393
+ midnight: "mi",
8394
+ noon: "n",
8395
+ morning: "morning",
8396
+ afternoon: "afternoon",
8397
+ evening: "evening",
8398
+ night: "night",
8399
+ },
8400
+ abbreviated: {
8401
+ am: "AM",
8402
+ pm: "PM",
8403
+ midnight: "midnight",
8404
+ noon: "noon",
8405
+ morning: "morning",
8406
+ afternoon: "afternoon",
8407
+ evening: "evening",
8408
+ night: "night",
8409
+ },
8410
+ wide: {
8411
+ am: "a.m.",
8412
+ pm: "p.m.",
8413
+ midnight: "midnight",
8414
+ noon: "noon",
8415
+ morning: "morning",
8416
+ afternoon: "afternoon",
8417
+ evening: "evening",
8418
+ night: "night",
8419
+ },
8420
+ };
8421
+
8422
+ const formattingDayPeriodValues$1 = {
8423
+ narrow: {
8424
+ am: "a",
8425
+ pm: "p",
8426
+ midnight: "mi",
8427
+ noon: "n",
8428
+ morning: "in the morning",
8429
+ afternoon: "in the afternoon",
8430
+ evening: "in the evening",
8431
+ night: "at night",
8432
+ },
8433
+ abbreviated: {
8434
+ am: "AM",
8435
+ pm: "PM",
8436
+ midnight: "midnight",
8437
+ noon: "noon",
8438
+ morning: "in the morning",
8439
+ afternoon: "in the afternoon",
8440
+ evening: "in the evening",
8441
+ night: "at night",
8442
+ },
8443
+ wide: {
8444
+ am: "a.m.",
8445
+ pm: "p.m.",
8446
+ midnight: "midnight",
8447
+ noon: "noon",
8448
+ morning: "in the morning",
8449
+ afternoon: "in the afternoon",
8450
+ evening: "in the evening",
8451
+ night: "at night",
8452
+ },
8453
+ };
8454
+
8455
+ const ordinalNumber$1 = (dirtyNumber, _options) => {
8456
+ const number = Number(dirtyNumber);
8457
+
8458
+ // If ordinal numbers depend on context, for example,
8459
+ // if they are different for different grammatical genders,
8460
+ // use `options.unit`.
8461
+ //
8462
+ // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
8463
+ // 'day', 'hour', 'minute', 'second'.
8464
+
8465
+ const rem100 = number % 100;
8466
+ if (rem100 > 20 || rem100 < 10) {
8467
+ switch (rem100 % 10) {
8468
+ case 1:
8469
+ return number + "st";
8470
+ case 2:
8471
+ return number + "nd";
8472
+ case 3:
8473
+ return number + "rd";
8474
+ }
8475
+ }
8476
+ return number + "th";
8477
+ };
8478
+
8479
+ const localize$1 = {
8480
+ ordinalNumber: ordinalNumber$1,
8481
+
8482
+ era: buildLocalizeFn({
8483
+ values: eraValues$1,
8484
+ defaultWidth: "wide",
8485
+ }),
8486
+
8487
+ quarter: buildLocalizeFn({
8488
+ values: quarterValues$1,
8489
+ defaultWidth: "wide",
8490
+ argumentCallback: (quarter) => quarter - 1,
8491
+ }),
8492
+
8493
+ month: buildLocalizeFn({
8494
+ values: monthValues$1,
8495
+ defaultWidth: "wide",
8496
+ }),
8497
+
8498
+ day: buildLocalizeFn({
8499
+ values: dayValues$1,
8500
+ defaultWidth: "wide",
8501
+ }),
8502
+
8503
+ dayPeriod: buildLocalizeFn({
8504
+ values: dayPeriodValues$1,
8505
+ defaultWidth: "wide",
8506
+ formattingValues: formattingDayPeriodValues$1,
8507
+ defaultFormattingWidth: "wide",
8508
+ }),
8509
+ };
8510
+
8511
+ function buildMatchFn(args) {
8512
+ return (string, options = {}) => {
8513
+ const width = options.width;
8514
+
8515
+ const matchPattern =
8516
+ (width && args.matchPatterns[width]) ||
8517
+ args.matchPatterns[args.defaultMatchWidth];
8518
+ const matchResult = string.match(matchPattern);
8519
+
8520
+ if (!matchResult) {
8521
+ return null;
8522
+ }
8523
+ const matchedString = matchResult[0];
8524
+
8525
+ const parsePatterns =
8526
+ (width && args.parsePatterns[width]) ||
8527
+ args.parsePatterns[args.defaultParseWidth];
8528
+
8529
+ const key = Array.isArray(parsePatterns)
8530
+ ? findIndex$1(parsePatterns, (pattern) => pattern.test(matchedString))
8531
+ : // [TODO] -- I challenge you to fix the type
8532
+ findKey(parsePatterns, (pattern) => pattern.test(matchedString));
8533
+
8534
+ let value;
8535
+
8536
+ value = args.valueCallback ? args.valueCallback(key) : key;
8537
+ value = options.valueCallback
8538
+ ? // [TODO] -- I challenge you to fix the type
8539
+ options.valueCallback(value)
8540
+ : value;
8541
+
8542
+ const rest = string.slice(matchedString.length);
8543
+
8544
+ return { value, rest };
8545
+ };
8546
+ }
8547
+
8548
+ function findKey(object, predicate) {
8549
+ for (const key in object) {
8550
+ if (
8551
+ Object.prototype.hasOwnProperty.call(object, key) &&
8552
+ predicate(object[key])
8553
+ ) {
8554
+ return key;
8555
+ }
8556
+ }
8557
+ return undefined;
8558
+ }
8559
+
8560
+ function findIndex$1(array, predicate) {
8561
+ for (let key = 0; key < array.length; key++) {
8562
+ if (predicate(array[key])) {
8563
+ return key;
8564
+ }
8565
+ }
8566
+ return undefined;
8567
+ }
8568
+
8569
+ function buildMatchPatternFn(args) {
8570
+ return (string, options = {}) => {
8571
+ const matchResult = string.match(args.matchPattern);
8572
+ if (!matchResult) return null;
8573
+ const matchedString = matchResult[0];
8574
+
8575
+ const parseResult = string.match(args.parsePattern);
8576
+ if (!parseResult) return null;
8577
+ let value = args.valueCallback
8578
+ ? args.valueCallback(parseResult[0])
8579
+ : parseResult[0];
8580
+
8581
+ // [TODO] I challenge you to fix the type
8582
+ value = options.valueCallback ? options.valueCallback(value) : value;
8583
+
8584
+ const rest = string.slice(matchedString.length);
8585
+
8586
+ return { value, rest };
8587
+ };
8588
+ }
8589
+
8590
+ const matchOrdinalNumberPattern$1 = /^(\d+)(th|st|nd|rd)?/i;
8591
+ const parseOrdinalNumberPattern$1 = /\d+/i;
8592
+
8593
+ const matchEraPatterns$1 = {
8594
+ narrow: /^(b|a)/i,
8595
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
8596
+ wide: /^(before christ|before common era|anno domini|common era)/i,
8597
+ };
8598
+ const parseEraPatterns$1 = {
8599
+ any: [/^b/i, /^(a|c)/i],
8600
+ };
8601
+
8602
+ const matchQuarterPatterns$1 = {
8603
+ narrow: /^[1234]/i,
8604
+ abbreviated: /^q[1234]/i,
8605
+ wide: /^[1234](th|st|nd|rd)? quarter/i,
8606
+ };
8607
+ const parseQuarterPatterns$1 = {
8608
+ any: [/1/i, /2/i, /3/i, /4/i],
8609
+ };
8610
+
8611
+ const matchMonthPatterns$1 = {
8612
+ narrow: /^[jfmasond]/i,
8613
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
8614
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i,
8615
+ };
8616
+ const parseMonthPatterns$1 = {
8617
+ narrow: [
8618
+ /^j/i,
8619
+ /^f/i,
8620
+ /^m/i,
8621
+ /^a/i,
8622
+ /^m/i,
8623
+ /^j/i,
8624
+ /^j/i,
8625
+ /^a/i,
8626
+ /^s/i,
8627
+ /^o/i,
8628
+ /^n/i,
8629
+ /^d/i,
8630
+ ],
8631
+
8632
+ any: [
8633
+ /^ja/i,
8634
+ /^f/i,
8635
+ /^mar/i,
8636
+ /^ap/i,
8637
+ /^may/i,
8638
+ /^jun/i,
8639
+ /^jul/i,
8640
+ /^au/i,
8641
+ /^s/i,
8642
+ /^o/i,
8643
+ /^n/i,
8644
+ /^d/i,
8645
+ ],
8646
+ };
8647
+
8648
+ const matchDayPatterns$1 = {
8649
+ narrow: /^[smtwf]/i,
8650
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
8651
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
8652
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i,
8653
+ };
8654
+ const parseDayPatterns$1 = {
8655
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
8656
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i],
8657
+ };
8658
+
8659
+ const matchDayPeriodPatterns$1 = {
8660
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
8661
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i,
8662
+ };
8663
+ const parseDayPeriodPatterns$1 = {
8664
+ any: {
8665
+ am: /^a/i,
8666
+ pm: /^p/i,
8667
+ midnight: /^mi/i,
8668
+ noon: /^no/i,
8669
+ morning: /morning/i,
8670
+ afternoon: /afternoon/i,
8671
+ evening: /evening/i,
8672
+ night: /night/i,
8673
+ },
8674
+ };
8675
+
8676
+ const match$1 = {
8677
+ ordinalNumber: buildMatchPatternFn({
8678
+ matchPattern: matchOrdinalNumberPattern$1,
8679
+ parsePattern: parseOrdinalNumberPattern$1,
8680
+ valueCallback: (value) => parseInt(value, 10),
8681
+ }),
8682
+
8683
+ era: buildMatchFn({
8684
+ matchPatterns: matchEraPatterns$1,
8685
+ defaultMatchWidth: "wide",
8686
+ parsePatterns: parseEraPatterns$1,
8687
+ defaultParseWidth: "any",
8688
+ }),
8689
+
8690
+ quarter: buildMatchFn({
8691
+ matchPatterns: matchQuarterPatterns$1,
8692
+ defaultMatchWidth: "wide",
8693
+ parsePatterns: parseQuarterPatterns$1,
8694
+ defaultParseWidth: "any",
8695
+ valueCallback: (index) => index + 1,
8696
+ }),
8697
+
8698
+ month: buildMatchFn({
8699
+ matchPatterns: matchMonthPatterns$1,
8700
+ defaultMatchWidth: "wide",
8701
+ parsePatterns: parseMonthPatterns$1,
8702
+ defaultParseWidth: "any",
8703
+ }),
8704
+
8705
+ day: buildMatchFn({
8706
+ matchPatterns: matchDayPatterns$1,
8707
+ defaultMatchWidth: "wide",
8708
+ parsePatterns: parseDayPatterns$1,
8709
+ defaultParseWidth: "any",
8710
+ }),
8711
+
8712
+ dayPeriod: buildMatchFn({
8713
+ matchPatterns: matchDayPeriodPatterns$1,
8714
+ defaultMatchWidth: "any",
8715
+ parsePatterns: parseDayPeriodPatterns$1,
8716
+ defaultParseWidth: "any",
8717
+ }),
8718
+ };
8719
+
8720
+ /**
8721
+ * @category Locales
8722
+ * @summary English locale (United States).
8723
+ * @language English
8724
+ * @iso-639-2 eng
8725
+ * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp)
8726
+ * @author Lesha Koss [@leshakoss](https://github.com/leshakoss)
8727
+ */
8728
+ const enUS = {
8729
+ code: "en-US",
8730
+ formatDistance: formatDistance$1,
8731
+ formatLong: formatLong$1,
8732
+ formatRelative: formatRelative$1,
8733
+ localize: localize$1,
8734
+ match: match$1,
8735
+ options: {
8736
+ weekStartsOn: 0 /* Sunday */,
8737
+ firstWeekContainsDate: 1,
8738
+ },
8739
+ };
8740
+
8741
+ /**
8742
+ * The {@link getDayOfYear} function options.
8743
+ */
8744
+
8745
+ /**
8746
+ * @name getDayOfYear
8747
+ * @category Day Helpers
8748
+ * @summary Get the day of the year of the given date.
8749
+ *
8750
+ * @description
8751
+ * Get the day of the year of the given date.
8752
+ *
8753
+ * @param date - The given date
8754
+ * @param options - The options
8755
+ *
8756
+ * @returns The day of year
8757
+ *
8758
+ * @example
8759
+ * // Which day of the year is 2 July 2014?
8760
+ * const result = getDayOfYear(new Date(2014, 6, 2))
8761
+ * //=> 183
8762
+ */
8763
+ function getDayOfYear(date, options) {
8764
+ const _date = toDate(date, options?.in);
8765
+ const diff = differenceInCalendarDays(_date, startOfYear(_date));
8766
+ const dayOfYear = diff + 1;
8767
+ return dayOfYear;
8768
+ }
8769
+
8770
+ /**
8771
+ * The {@link getISOWeek} function options.
8772
+ */
8773
+
8774
+ /**
8775
+ * @name getISOWeek
8776
+ * @category ISO Week Helpers
8777
+ * @summary Get the ISO week of the given date.
8778
+ *
8779
+ * @description
8780
+ * Get the ISO week of the given date.
8781
+ *
8782
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
8783
+ *
8784
+ * @param date - The given date
8785
+ * @param options - The options
8786
+ *
8787
+ * @returns The ISO week
8788
+ *
8789
+ * @example
8790
+ * // Which week of the ISO-week numbering year is 2 January 2005?
8791
+ * const result = getISOWeek(new Date(2005, 0, 2))
8792
+ * //=> 53
8793
+ */
8794
+ function getISOWeek(date, options) {
8795
+ const _date = toDate(date, options?.in);
8796
+ const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
8797
+
8798
+ // Round the number of weeks to the nearest integer because the number of
8799
+ // milliseconds in a week is not constant (e.g. it's different in the week of
8800
+ // the daylight saving time clock shift).
8801
+ return Math.round(diff / millisecondsInWeek) + 1;
8802
+ }
8803
+
8804
+ /**
8805
+ * The {@link getWeekYear} function options.
8806
+ */
8807
+
8808
+ /**
8809
+ * @name getWeekYear
8810
+ * @category Week-Numbering Year Helpers
8811
+ * @summary Get the local week-numbering year of the given date.
8812
+ *
8813
+ * @description
8814
+ * Get the local week-numbering year of the given date.
8815
+ * The exact calculation depends on the values of
8816
+ * `options.weekStartsOn` (which is the index of the first day of the week)
8817
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
8818
+ * the first week of the week-numbering year)
8819
+ *
8820
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
8821
+ *
8822
+ * @param date - The given date
8823
+ * @param options - An object with options.
8824
+ *
8825
+ * @returns The local week-numbering year
8826
+ *
8827
+ * @example
8828
+ * // Which week numbering year is 26 December 2004 with the default settings?
8829
+ * const result = getWeekYear(new Date(2004, 11, 26))
8830
+ * //=> 2005
8831
+ *
8832
+ * @example
8833
+ * // Which week numbering year is 26 December 2004 if week starts on Saturday?
8834
+ * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
8835
+ * //=> 2004
8836
+ *
8837
+ * @example
8838
+ * // Which week numbering year is 26 December 2004 if the first week contains 4 January?
8839
+ * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
8840
+ * //=> 2004
8841
+ */
8842
+ function getWeekYear(date, options) {
8843
+ const _date = toDate(date, options?.in);
8844
+ const year = _date.getFullYear();
8845
+
8846
+ const defaultOptions = getDefaultOptions();
8847
+ const firstWeekContainsDate =
8848
+ options?.firstWeekContainsDate ??
8849
+ options?.locale?.options?.firstWeekContainsDate ??
8850
+ defaultOptions.firstWeekContainsDate ??
8851
+ defaultOptions.locale?.options?.firstWeekContainsDate ??
8852
+ 1;
8853
+
8854
+ const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
8855
+ firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
8856
+ firstWeekOfNextYear.setHours(0, 0, 0, 0);
8857
+ const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
8858
+
8859
+ const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
8860
+ firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
8861
+ firstWeekOfThisYear.setHours(0, 0, 0, 0);
8862
+ const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
8863
+
8864
+ if (+_date >= +startOfNextYear) {
8865
+ return year + 1;
8866
+ } else if (+_date >= +startOfThisYear) {
8867
+ return year;
8868
+ } else {
8869
+ return year - 1;
8870
+ }
8871
+ }
8872
+
8873
+ /**
8874
+ * The {@link startOfWeekYear} function options.
8875
+ */
8876
+
8877
+ /**
8878
+ * @name startOfWeekYear
8879
+ * @category Week-Numbering Year Helpers
8880
+ * @summary Return the start of a local week-numbering year for the given date.
8881
+ *
8882
+ * @description
8883
+ * Return the start of a local week-numbering year.
8884
+ * The exact calculation depends on the values of
8885
+ * `options.weekStartsOn` (which is the index of the first day of the week)
8886
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
8887
+ * the first week of the week-numbering year)
8888
+ *
8889
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
8890
+ *
8891
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
8892
+ * @typeParam ResultDate - The result `Date` type.
8893
+ *
8894
+ * @param date - The original date
8895
+ * @param options - An object with options
8896
+ *
8897
+ * @returns The start of a week-numbering year
8898
+ *
8899
+ * @example
8900
+ * // The start of an a week-numbering year for 2 July 2005 with default settings:
8901
+ * const result = startOfWeekYear(new Date(2005, 6, 2))
8902
+ * //=> Sun Dec 26 2004 00:00:00
8903
+ *
8904
+ * @example
8905
+ * // The start of a week-numbering year for 2 July 2005
8906
+ * // if Monday is the first day of week
8907
+ * // and 4 January is always in the first week of the year:
8908
+ * const result = startOfWeekYear(new Date(2005, 6, 2), {
8909
+ * weekStartsOn: 1,
8910
+ * firstWeekContainsDate: 4
8911
+ * })
8912
+ * //=> Mon Jan 03 2005 00:00:00
8913
+ */
8914
+ function startOfWeekYear(date, options) {
8915
+ const defaultOptions = getDefaultOptions();
8916
+ const firstWeekContainsDate =
8917
+ options?.firstWeekContainsDate ??
8918
+ options?.locale?.options?.firstWeekContainsDate ??
8919
+ defaultOptions.firstWeekContainsDate ??
8920
+ defaultOptions.locale?.options?.firstWeekContainsDate ??
8921
+ 1;
8922
+
8923
+ const year = getWeekYear(date, options);
8924
+ const firstWeek = constructFrom(options?.in || date, 0);
8925
+ firstWeek.setFullYear(year, 0, firstWeekContainsDate);
8926
+ firstWeek.setHours(0, 0, 0, 0);
8927
+ const _date = startOfWeek(firstWeek, options);
8928
+ return _date;
8929
+ }
8930
+
8931
+ /**
8932
+ * The {@link getWeek} function options.
8933
+ */
8934
+
8935
+ /**
8936
+ * @name getWeek
8937
+ * @category Week Helpers
8938
+ * @summary Get the local week index of the given date.
8939
+ *
8940
+ * @description
8941
+ * Get the local week index of the given date.
8942
+ * The exact calculation depends on the values of
8943
+ * `options.weekStartsOn` (which is the index of the first day of the week)
8944
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
8945
+ * the first week of the week-numbering year)
8946
+ *
8947
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
8948
+ *
8949
+ * @param date - The given date
8950
+ * @param options - An object with options
8951
+ *
8952
+ * @returns The week
8953
+ *
8954
+ * @example
8955
+ * // Which week of the local week numbering year is 2 January 2005 with default options?
8956
+ * const result = getWeek(new Date(2005, 0, 2))
8957
+ * //=> 2
8958
+ *
8959
+ * @example
8960
+ * // Which week of the local week numbering year is 2 January 2005,
8961
+ * // if Monday is the first day of the week,
8962
+ * // and the first week of the year always contains 4 January?
8963
+ * const result = getWeek(new Date(2005, 0, 2), {
8964
+ * weekStartsOn: 1,
8965
+ * firstWeekContainsDate: 4
8966
+ * })
8967
+ * //=> 53
8968
+ */
8969
+ function getWeek(date, options) {
8970
+ const _date = toDate(date, options?.in);
8971
+ const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
8972
+
8973
+ // Round the number of weeks to the nearest integer because the number of
8974
+ // milliseconds in a week is not constant (e.g. it's different in the week of
8975
+ // the daylight saving time clock shift).
8976
+ return Math.round(diff / millisecondsInWeek) + 1;
8977
+ }
8978
+
8979
+ function addLeadingZeros(number, targetLength) {
8980
+ const sign = number < 0 ? "-" : "";
8981
+ const output = Math.abs(number).toString().padStart(targetLength, "0");
8982
+ return sign + output;
8983
+ }
8984
+
8985
+ /*
8986
+ * | | Unit | | Unit |
8987
+ * |-----|--------------------------------|-----|--------------------------------|
8988
+ * | a | AM, PM | A* | |
8989
+ * | d | Day of month | D | |
8990
+ * | h | Hour [1-12] | H | Hour [0-23] |
8991
+ * | m | Minute | M | Month |
8992
+ * | s | Second | S | Fraction of second |
8993
+ * | y | Year (abs) | Y | |
8994
+ *
8995
+ * Letters marked by * are not implemented but reserved by Unicode standard.
8996
+ */
8997
+
8998
+ const lightFormatters = {
8999
+ // Year
9000
+ y(date, token) {
9001
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
9002
+ // | Year | y | yy | yyy | yyyy | yyyyy |
9003
+ // |----------|-------|----|-------|-------|-------|
9004
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
9005
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
9006
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
9007
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
9008
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
9009
+
9010
+ const signedYear = date.getFullYear();
9011
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
9012
+ const year = signedYear > 0 ? signedYear : 1 - signedYear;
9013
+ return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
9014
+ },
9015
+
9016
+ // Month
9017
+ M(date, token) {
9018
+ const month = date.getMonth();
9019
+ return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
9020
+ },
9021
+
9022
+ // Day of the month
9023
+ d(date, token) {
9024
+ return addLeadingZeros(date.getDate(), token.length);
9025
+ },
9026
+
9027
+ // AM or PM
9028
+ a(date, token) {
9029
+ const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
9030
+
9031
+ switch (token) {
9032
+ case "a":
9033
+ case "aa":
9034
+ return dayPeriodEnumValue.toUpperCase();
9035
+ case "aaa":
9036
+ return dayPeriodEnumValue;
9037
+ case "aaaaa":
9038
+ return dayPeriodEnumValue[0];
9039
+ case "aaaa":
9040
+ default:
9041
+ return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
9042
+ }
9043
+ },
9044
+
9045
+ // Hour [1-12]
9046
+ h(date, token) {
9047
+ return addLeadingZeros(date.getHours() % 12 || 12, token.length);
9048
+ },
9049
+
9050
+ // Hour [0-23]
9051
+ H(date, token) {
9052
+ return addLeadingZeros(date.getHours(), token.length);
9053
+ },
9054
+
9055
+ // Minute
9056
+ m(date, token) {
9057
+ return addLeadingZeros(date.getMinutes(), token.length);
9058
+ },
9059
+
9060
+ // Second
9061
+ s(date, token) {
9062
+ return addLeadingZeros(date.getSeconds(), token.length);
9063
+ },
9064
+
9065
+ // Fraction of second
9066
+ S(date, token) {
9067
+ const numberOfDigits = token.length;
9068
+ const milliseconds = date.getMilliseconds();
9069
+ const fractionalSeconds = Math.trunc(
9070
+ milliseconds * Math.pow(10, numberOfDigits - 3),
9071
+ );
9072
+ return addLeadingZeros(fractionalSeconds, token.length);
9073
+ },
9074
+ };
9075
+
9076
+ const dayPeriodEnum = {
9077
+ midnight: "midnight",
9078
+ noon: "noon",
9079
+ morning: "morning",
9080
+ afternoon: "afternoon",
9081
+ evening: "evening",
9082
+ night: "night",
9083
+ };
9084
+
9085
+ /*
9086
+ * | | Unit | | Unit |
9087
+ * |-----|--------------------------------|-----|--------------------------------|
9088
+ * | a | AM, PM | A* | Milliseconds in day |
9089
+ * | b | AM, PM, noon, midnight | B | Flexible day period |
9090
+ * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
9091
+ * | d | Day of month | D | Day of year |
9092
+ * | e | Local day of week | E | Day of week |
9093
+ * | f | | F* | Day of week in month |
9094
+ * | g* | Modified Julian day | G | Era |
9095
+ * | h | Hour [1-12] | H | Hour [0-23] |
9096
+ * | i! | ISO day of week | I! | ISO week of year |
9097
+ * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
9098
+ * | k | Hour [1-24] | K | Hour [0-11] |
9099
+ * | l* | (deprecated) | L | Stand-alone month |
9100
+ * | m | Minute | M | Month |
9101
+ * | n | | N | |
9102
+ * | o! | Ordinal number modifier | O | Timezone (GMT) |
9103
+ * | p! | Long localized time | P! | Long localized date |
9104
+ * | q | Stand-alone quarter | Q | Quarter |
9105
+ * | r* | Related Gregorian year | R! | ISO week-numbering year |
9106
+ * | s | Second | S | Fraction of second |
9107
+ * | t! | Seconds timestamp | T! | Milliseconds timestamp |
9108
+ * | u | Extended year | U* | Cyclic year |
9109
+ * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
9110
+ * | w | Local week of year | W* | Week of month |
9111
+ * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
9112
+ * | y | Year (abs) | Y | Local week-numbering year |
9113
+ * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
9114
+ *
9115
+ * Letters marked by * are not implemented but reserved by Unicode standard.
9116
+ *
9117
+ * Letters marked by ! are non-standard, but implemented by date-fns:
9118
+ * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
9119
+ * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
9120
+ * i.e. 7 for Sunday, 1 for Monday, etc.
9121
+ * - `I` is ISO week of year, as opposed to `w` which is local week of year.
9122
+ * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
9123
+ * `R` is supposed to be used in conjunction with `I` and `i`
9124
+ * for universal ISO week-numbering date, whereas
9125
+ * `Y` is supposed to be used in conjunction with `w` and `e`
9126
+ * for week-numbering date specific to the locale.
9127
+ * - `P` is long localized date format
9128
+ * - `p` is long localized time format
9129
+ */
9130
+
9131
+ const formatters = {
9132
+ // Era
9133
+ G: function (date, token, localize) {
9134
+ const era = date.getFullYear() > 0 ? 1 : 0;
9135
+ switch (token) {
9136
+ // AD, BC
9137
+ case "G":
9138
+ case "GG":
9139
+ case "GGG":
9140
+ return localize.era(era, { width: "abbreviated" });
9141
+ // A, B
9142
+ case "GGGGG":
9143
+ return localize.era(era, { width: "narrow" });
9144
+ // Anno Domini, Before Christ
9145
+ case "GGGG":
9146
+ default:
9147
+ return localize.era(era, { width: "wide" });
9148
+ }
9149
+ },
9150
+
9151
+ // Year
9152
+ y: function (date, token, localize) {
9153
+ // Ordinal number
9154
+ if (token === "yo") {
9155
+ const signedYear = date.getFullYear();
9156
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
9157
+ const year = signedYear > 0 ? signedYear : 1 - signedYear;
9158
+ return localize.ordinalNumber(year, { unit: "year" });
9159
+ }
9160
+
9161
+ return lightFormatters.y(date, token);
9162
+ },
9163
+
9164
+ // Local week-numbering year
9165
+ Y: function (date, token, localize, options) {
9166
+ const signedWeekYear = getWeekYear(date, options);
9167
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
9168
+ const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
9169
+
9170
+ // Two digit year
9171
+ if (token === "YY") {
9172
+ const twoDigitYear = weekYear % 100;
9173
+ return addLeadingZeros(twoDigitYear, 2);
9174
+ }
9175
+
9176
+ // Ordinal number
9177
+ if (token === "Yo") {
9178
+ return localize.ordinalNumber(weekYear, { unit: "year" });
9179
+ }
9180
+
9181
+ // Padding
9182
+ return addLeadingZeros(weekYear, token.length);
9183
+ },
9184
+
9185
+ // ISO week-numbering year
9186
+ R: function (date, token) {
9187
+ const isoWeekYear = getISOWeekYear(date);
9188
+
9189
+ // Padding
9190
+ return addLeadingZeros(isoWeekYear, token.length);
9191
+ },
9192
+
9193
+ // Extended year. This is a single number designating the year of this calendar system.
9194
+ // The main difference between `y` and `u` localizers are B.C. years:
9195
+ // | Year | `y` | `u` |
9196
+ // |------|-----|-----|
9197
+ // | AC 1 | 1 | 1 |
9198
+ // | BC 1 | 1 | 0 |
9199
+ // | BC 2 | 2 | -1 |
9200
+ // Also `yy` always returns the last two digits of a year,
9201
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
9202
+ u: function (date, token) {
9203
+ const year = date.getFullYear();
9204
+ return addLeadingZeros(year, token.length);
9205
+ },
9206
+
9207
+ // Quarter
9208
+ Q: function (date, token, localize) {
9209
+ const quarter = Math.ceil((date.getMonth() + 1) / 3);
9210
+ switch (token) {
9211
+ // 1, 2, 3, 4
9212
+ case "Q":
9213
+ return String(quarter);
9214
+ // 01, 02, 03, 04
9215
+ case "QQ":
9216
+ return addLeadingZeros(quarter, 2);
9217
+ // 1st, 2nd, 3rd, 4th
9218
+ case "Qo":
9219
+ return localize.ordinalNumber(quarter, { unit: "quarter" });
9220
+ // Q1, Q2, Q3, Q4
9221
+ case "QQQ":
9222
+ return localize.quarter(quarter, {
9223
+ width: "abbreviated",
9224
+ context: "formatting",
9225
+ });
9226
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
9227
+ case "QQQQQ":
9228
+ return localize.quarter(quarter, {
9229
+ width: "narrow",
9230
+ context: "formatting",
9231
+ });
9232
+ // 1st quarter, 2nd quarter, ...
9233
+ case "QQQQ":
9234
+ default:
9235
+ return localize.quarter(quarter, {
9236
+ width: "wide",
9237
+ context: "formatting",
9238
+ });
9239
+ }
9240
+ },
9241
+
9242
+ // Stand-alone quarter
9243
+ q: function (date, token, localize) {
9244
+ const quarter = Math.ceil((date.getMonth() + 1) / 3);
9245
+ switch (token) {
9246
+ // 1, 2, 3, 4
9247
+ case "q":
9248
+ return String(quarter);
9249
+ // 01, 02, 03, 04
9250
+ case "qq":
9251
+ return addLeadingZeros(quarter, 2);
9252
+ // 1st, 2nd, 3rd, 4th
9253
+ case "qo":
9254
+ return localize.ordinalNumber(quarter, { unit: "quarter" });
9255
+ // Q1, Q2, Q3, Q4
9256
+ case "qqq":
9257
+ return localize.quarter(quarter, {
9258
+ width: "abbreviated",
9259
+ context: "standalone",
9260
+ });
9261
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
9262
+ case "qqqqq":
9263
+ return localize.quarter(quarter, {
9264
+ width: "narrow",
9265
+ context: "standalone",
9266
+ });
9267
+ // 1st quarter, 2nd quarter, ...
9268
+ case "qqqq":
9269
+ default:
9270
+ return localize.quarter(quarter, {
9271
+ width: "wide",
9272
+ context: "standalone",
9273
+ });
9274
+ }
9275
+ },
9276
+
9277
+ // Month
9278
+ M: function (date, token, localize) {
9279
+ const month = date.getMonth();
9280
+ switch (token) {
9281
+ case "M":
9282
+ case "MM":
9283
+ return lightFormatters.M(date, token);
9284
+ // 1st, 2nd, ..., 12th
9285
+ case "Mo":
9286
+ return localize.ordinalNumber(month + 1, { unit: "month" });
9287
+ // Jan, Feb, ..., Dec
9288
+ case "MMM":
9289
+ return localize.month(month, {
9290
+ width: "abbreviated",
9291
+ context: "formatting",
9292
+ });
9293
+ // J, F, ..., D
9294
+ case "MMMMM":
9295
+ return localize.month(month, {
9296
+ width: "narrow",
9297
+ context: "formatting",
9298
+ });
9299
+ // January, February, ..., December
9300
+ case "MMMM":
9301
+ default:
9302
+ return localize.month(month, { width: "wide", context: "formatting" });
9303
+ }
9304
+ },
9305
+
9306
+ // Stand-alone month
9307
+ L: function (date, token, localize) {
9308
+ const month = date.getMonth();
9309
+ switch (token) {
9310
+ // 1, 2, ..., 12
9311
+ case "L":
9312
+ return String(month + 1);
9313
+ // 01, 02, ..., 12
9314
+ case "LL":
9315
+ return addLeadingZeros(month + 1, 2);
9316
+ // 1st, 2nd, ..., 12th
9317
+ case "Lo":
9318
+ return localize.ordinalNumber(month + 1, { unit: "month" });
9319
+ // Jan, Feb, ..., Dec
9320
+ case "LLL":
9321
+ return localize.month(month, {
9322
+ width: "abbreviated",
9323
+ context: "standalone",
9324
+ });
9325
+ // J, F, ..., D
9326
+ case "LLLLL":
9327
+ return localize.month(month, {
9328
+ width: "narrow",
9329
+ context: "standalone",
9330
+ });
9331
+ // January, February, ..., December
9332
+ case "LLLL":
9333
+ default:
9334
+ return localize.month(month, { width: "wide", context: "standalone" });
9335
+ }
9336
+ },
9337
+
9338
+ // Local week of year
9339
+ w: function (date, token, localize, options) {
9340
+ const week = getWeek(date, options);
9341
+
9342
+ if (token === "wo") {
9343
+ return localize.ordinalNumber(week, { unit: "week" });
9344
+ }
9345
+
9346
+ return addLeadingZeros(week, token.length);
9347
+ },
9348
+
9349
+ // ISO week of year
9350
+ I: function (date, token, localize) {
9351
+ const isoWeek = getISOWeek(date);
9352
+
9353
+ if (token === "Io") {
9354
+ return localize.ordinalNumber(isoWeek, { unit: "week" });
9355
+ }
9356
+
9357
+ return addLeadingZeros(isoWeek, token.length);
9358
+ },
9359
+
9360
+ // Day of the month
9361
+ d: function (date, token, localize) {
9362
+ if (token === "do") {
9363
+ return localize.ordinalNumber(date.getDate(), { unit: "date" });
9364
+ }
9365
+
9366
+ return lightFormatters.d(date, token);
9367
+ },
9368
+
9369
+ // Day of year
9370
+ D: function (date, token, localize) {
9371
+ const dayOfYear = getDayOfYear(date);
9372
+
9373
+ if (token === "Do") {
9374
+ return localize.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
9375
+ }
9376
+
9377
+ return addLeadingZeros(dayOfYear, token.length);
9378
+ },
9379
+
9380
+ // Day of week
9381
+ E: function (date, token, localize) {
9382
+ const dayOfWeek = date.getDay();
9383
+ switch (token) {
9384
+ // Tue
9385
+ case "E":
9386
+ case "EE":
9387
+ case "EEE":
9388
+ return localize.day(dayOfWeek, {
9389
+ width: "abbreviated",
9390
+ context: "formatting",
9391
+ });
9392
+ // T
9393
+ case "EEEEE":
9394
+ return localize.day(dayOfWeek, {
9395
+ width: "narrow",
9396
+ context: "formatting",
9397
+ });
9398
+ // Tu
9399
+ case "EEEEEE":
9400
+ return localize.day(dayOfWeek, {
9401
+ width: "short",
9402
+ context: "formatting",
9403
+ });
9404
+ // Tuesday
9405
+ case "EEEE":
9406
+ default:
9407
+ return localize.day(dayOfWeek, {
9408
+ width: "wide",
9409
+ context: "formatting",
9410
+ });
9411
+ }
9412
+ },
9413
+
9414
+ // Local day of week
9415
+ e: function (date, token, localize, options) {
9416
+ const dayOfWeek = date.getDay();
9417
+ const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
9418
+ switch (token) {
9419
+ // Numerical value (Nth day of week with current locale or weekStartsOn)
9420
+ case "e":
9421
+ return String(localDayOfWeek);
9422
+ // Padded numerical value
9423
+ case "ee":
9424
+ return addLeadingZeros(localDayOfWeek, 2);
9425
+ // 1st, 2nd, ..., 7th
9426
+ case "eo":
9427
+ return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
9428
+ case "eee":
9429
+ return localize.day(dayOfWeek, {
9430
+ width: "abbreviated",
9431
+ context: "formatting",
9432
+ });
9433
+ // T
9434
+ case "eeeee":
9435
+ return localize.day(dayOfWeek, {
9436
+ width: "narrow",
9437
+ context: "formatting",
9438
+ });
9439
+ // Tu
9440
+ case "eeeeee":
9441
+ return localize.day(dayOfWeek, {
9442
+ width: "short",
9443
+ context: "formatting",
9444
+ });
9445
+ // Tuesday
9446
+ case "eeee":
9447
+ default:
9448
+ return localize.day(dayOfWeek, {
9449
+ width: "wide",
9450
+ context: "formatting",
9451
+ });
9452
+ }
9453
+ },
9454
+
9455
+ // Stand-alone local day of week
9456
+ c: function (date, token, localize, options) {
9457
+ const dayOfWeek = date.getDay();
9458
+ const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
9459
+ switch (token) {
9460
+ // Numerical value (same as in `e`)
9461
+ case "c":
9462
+ return String(localDayOfWeek);
9463
+ // Padded numerical value
9464
+ case "cc":
9465
+ return addLeadingZeros(localDayOfWeek, token.length);
9466
+ // 1st, 2nd, ..., 7th
9467
+ case "co":
9468
+ return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
9469
+ case "ccc":
9470
+ return localize.day(dayOfWeek, {
9471
+ width: "abbreviated",
9472
+ context: "standalone",
9473
+ });
9474
+ // T
9475
+ case "ccccc":
9476
+ return localize.day(dayOfWeek, {
9477
+ width: "narrow",
9478
+ context: "standalone",
9479
+ });
9480
+ // Tu
9481
+ case "cccccc":
9482
+ return localize.day(dayOfWeek, {
9483
+ width: "short",
9484
+ context: "standalone",
9485
+ });
9486
+ // Tuesday
9487
+ case "cccc":
9488
+ default:
9489
+ return localize.day(dayOfWeek, {
9490
+ width: "wide",
9491
+ context: "standalone",
9492
+ });
9493
+ }
9494
+ },
9495
+
9496
+ // ISO day of week
9497
+ i: function (date, token, localize) {
9498
+ const dayOfWeek = date.getDay();
9499
+ const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
9500
+ switch (token) {
9501
+ // 2
9502
+ case "i":
9503
+ return String(isoDayOfWeek);
9504
+ // 02
9505
+ case "ii":
9506
+ return addLeadingZeros(isoDayOfWeek, token.length);
9507
+ // 2nd
9508
+ case "io":
9509
+ return localize.ordinalNumber(isoDayOfWeek, { unit: "day" });
9510
+ // Tue
9511
+ case "iii":
9512
+ return localize.day(dayOfWeek, {
9513
+ width: "abbreviated",
9514
+ context: "formatting",
9515
+ });
9516
+ // T
9517
+ case "iiiii":
9518
+ return localize.day(dayOfWeek, {
9519
+ width: "narrow",
9520
+ context: "formatting",
9521
+ });
9522
+ // Tu
9523
+ case "iiiiii":
9524
+ return localize.day(dayOfWeek, {
9525
+ width: "short",
9526
+ context: "formatting",
9527
+ });
9528
+ // Tuesday
9529
+ case "iiii":
9530
+ default:
9531
+ return localize.day(dayOfWeek, {
9532
+ width: "wide",
9533
+ context: "formatting",
9534
+ });
9535
+ }
9536
+ },
9537
+
9538
+ // AM or PM
9539
+ a: function (date, token, localize) {
9540
+ const hours = date.getHours();
9541
+ const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
9542
+
9543
+ switch (token) {
9544
+ case "a":
9545
+ case "aa":
9546
+ return localize.dayPeriod(dayPeriodEnumValue, {
9547
+ width: "abbreviated",
9548
+ context: "formatting",
9549
+ });
9550
+ case "aaa":
9551
+ return localize
9552
+ .dayPeriod(dayPeriodEnumValue, {
9553
+ width: "abbreviated",
9554
+ context: "formatting",
9555
+ })
9556
+ .toLowerCase();
9557
+ case "aaaaa":
9558
+ return localize.dayPeriod(dayPeriodEnumValue, {
9559
+ width: "narrow",
9560
+ context: "formatting",
9561
+ });
9562
+ case "aaaa":
9563
+ default:
9564
+ return localize.dayPeriod(dayPeriodEnumValue, {
9565
+ width: "wide",
9566
+ context: "formatting",
9567
+ });
9568
+ }
9569
+ },
9570
+
9571
+ // AM, PM, midnight, noon
9572
+ b: function (date, token, localize) {
9573
+ const hours = date.getHours();
9574
+ let dayPeriodEnumValue;
9575
+ if (hours === 12) {
9576
+ dayPeriodEnumValue = dayPeriodEnum.noon;
9577
+ } else if (hours === 0) {
9578
+ dayPeriodEnumValue = dayPeriodEnum.midnight;
9579
+ } else {
9580
+ dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
9581
+ }
9582
+
9583
+ switch (token) {
9584
+ case "b":
9585
+ case "bb":
9586
+ return localize.dayPeriod(dayPeriodEnumValue, {
9587
+ width: "abbreviated",
9588
+ context: "formatting",
9589
+ });
9590
+ case "bbb":
9591
+ return localize
9592
+ .dayPeriod(dayPeriodEnumValue, {
9593
+ width: "abbreviated",
9594
+ context: "formatting",
9595
+ })
9596
+ .toLowerCase();
9597
+ case "bbbbb":
9598
+ return localize.dayPeriod(dayPeriodEnumValue, {
9599
+ width: "narrow",
9600
+ context: "formatting",
9601
+ });
9602
+ case "bbbb":
9603
+ default:
9604
+ return localize.dayPeriod(dayPeriodEnumValue, {
9605
+ width: "wide",
9606
+ context: "formatting",
9607
+ });
9608
+ }
9609
+ },
9610
+
9611
+ // in the morning, in the afternoon, in the evening, at night
9612
+ B: function (date, token, localize) {
9613
+ const hours = date.getHours();
9614
+ let dayPeriodEnumValue;
9615
+ if (hours >= 17) {
9616
+ dayPeriodEnumValue = dayPeriodEnum.evening;
9617
+ } else if (hours >= 12) {
9618
+ dayPeriodEnumValue = dayPeriodEnum.afternoon;
9619
+ } else if (hours >= 4) {
9620
+ dayPeriodEnumValue = dayPeriodEnum.morning;
9621
+ } else {
9622
+ dayPeriodEnumValue = dayPeriodEnum.night;
9623
+ }
9624
+
9625
+ switch (token) {
9626
+ case "B":
9627
+ case "BB":
9628
+ case "BBB":
9629
+ return localize.dayPeriod(dayPeriodEnumValue, {
9630
+ width: "abbreviated",
9631
+ context: "formatting",
9632
+ });
9633
+ case "BBBBB":
9634
+ return localize.dayPeriod(dayPeriodEnumValue, {
9635
+ width: "narrow",
9636
+ context: "formatting",
9637
+ });
9638
+ case "BBBB":
9639
+ default:
9640
+ return localize.dayPeriod(dayPeriodEnumValue, {
9641
+ width: "wide",
9642
+ context: "formatting",
9643
+ });
9644
+ }
9645
+ },
9646
+
9647
+ // Hour [1-12]
9648
+ h: function (date, token, localize) {
9649
+ if (token === "ho") {
9650
+ let hours = date.getHours() % 12;
9651
+ if (hours === 0) hours = 12;
9652
+ return localize.ordinalNumber(hours, { unit: "hour" });
9653
+ }
9654
+
9655
+ return lightFormatters.h(date, token);
9656
+ },
9657
+
9658
+ // Hour [0-23]
9659
+ H: function (date, token, localize) {
9660
+ if (token === "Ho") {
9661
+ return localize.ordinalNumber(date.getHours(), { unit: "hour" });
9662
+ }
9663
+
9664
+ return lightFormatters.H(date, token);
9665
+ },
9666
+
9667
+ // Hour [0-11]
9668
+ K: function (date, token, localize) {
9669
+ const hours = date.getHours() % 12;
9670
+
9671
+ if (token === "Ko") {
9672
+ return localize.ordinalNumber(hours, { unit: "hour" });
9673
+ }
9674
+
9675
+ return addLeadingZeros(hours, token.length);
9676
+ },
9677
+
9678
+ // Hour [1-24]
9679
+ k: function (date, token, localize) {
9680
+ let hours = date.getHours();
9681
+ if (hours === 0) hours = 24;
9682
+
9683
+ if (token === "ko") {
9684
+ return localize.ordinalNumber(hours, { unit: "hour" });
9685
+ }
9686
+
9687
+ return addLeadingZeros(hours, token.length);
9688
+ },
9689
+
9690
+ // Minute
9691
+ m: function (date, token, localize) {
9692
+ if (token === "mo") {
9693
+ return localize.ordinalNumber(date.getMinutes(), { unit: "minute" });
9694
+ }
9695
+
9696
+ return lightFormatters.m(date, token);
9697
+ },
9698
+
9699
+ // Second
9700
+ s: function (date, token, localize) {
9701
+ if (token === "so") {
9702
+ return localize.ordinalNumber(date.getSeconds(), { unit: "second" });
9703
+ }
9704
+
9705
+ return lightFormatters.s(date, token);
9706
+ },
9707
+
9708
+ // Fraction of second
9709
+ S: function (date, token) {
9710
+ return lightFormatters.S(date, token);
9711
+ },
9712
+
9713
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
9714
+ X: function (date, token, _localize) {
9715
+ const timezoneOffset = date.getTimezoneOffset();
9716
+
9717
+ if (timezoneOffset === 0) {
9718
+ return "Z";
9719
+ }
9720
+
9721
+ switch (token) {
9722
+ // Hours and optional minutes
9723
+ case "X":
9724
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
9725
+
9726
+ // Hours, minutes and optional seconds without `:` delimiter
9727
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
9728
+ // so this token always has the same output as `XX`
9729
+ case "XXXX":
9730
+ case "XX": // Hours and minutes without `:` delimiter
9731
+ return formatTimezone(timezoneOffset);
9732
+
9733
+ // Hours, minutes and optional seconds with `:` delimiter
9734
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
9735
+ // so this token always has the same output as `XXX`
9736
+ case "XXXXX":
9737
+ case "XXX": // Hours and minutes with `:` delimiter
9738
+ default:
9739
+ return formatTimezone(timezoneOffset, ":");
9740
+ }
9741
+ },
9742
+
9743
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
9744
+ x: function (date, token, _localize) {
9745
+ const timezoneOffset = date.getTimezoneOffset();
9746
+
9747
+ switch (token) {
9748
+ // Hours and optional minutes
9749
+ case "x":
9750
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
9751
+
9752
+ // Hours, minutes and optional seconds without `:` delimiter
9753
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
9754
+ // so this token always has the same output as `xx`
9755
+ case "xxxx":
9756
+ case "xx": // Hours and minutes without `:` delimiter
9757
+ return formatTimezone(timezoneOffset);
9758
+
9759
+ // Hours, minutes and optional seconds with `:` delimiter
9760
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
9761
+ // so this token always has the same output as `xxx`
9762
+ case "xxxxx":
9763
+ case "xxx": // Hours and minutes with `:` delimiter
9764
+ default:
9765
+ return formatTimezone(timezoneOffset, ":");
9766
+ }
9767
+ },
9768
+
9769
+ // Timezone (GMT)
9770
+ O: function (date, token, _localize) {
9771
+ const timezoneOffset = date.getTimezoneOffset();
9772
+
9773
+ switch (token) {
9774
+ // Short
9775
+ case "O":
9776
+ case "OO":
9777
+ case "OOO":
9778
+ return "GMT" + formatTimezoneShort(timezoneOffset, ":");
9779
+ // Long
9780
+ case "OOOO":
9781
+ default:
9782
+ return "GMT" + formatTimezone(timezoneOffset, ":");
9783
+ }
9784
+ },
9785
+
9786
+ // Timezone (specific non-location)
9787
+ z: function (date, token, _localize) {
9788
+ const timezoneOffset = date.getTimezoneOffset();
9789
+
9790
+ switch (token) {
9791
+ // Short
9792
+ case "z":
9793
+ case "zz":
9794
+ case "zzz":
9795
+ return "GMT" + formatTimezoneShort(timezoneOffset, ":");
9796
+ // Long
9797
+ case "zzzz":
9798
+ default:
9799
+ return "GMT" + formatTimezone(timezoneOffset, ":");
9800
+ }
9801
+ },
9802
+
9803
+ // Seconds timestamp
9804
+ t: function (date, token, _localize) {
9805
+ const timestamp = Math.trunc(+date / 1000);
9806
+ return addLeadingZeros(timestamp, token.length);
9807
+ },
9808
+
9809
+ // Milliseconds timestamp
9810
+ T: function (date, token, _localize) {
9811
+ return addLeadingZeros(+date, token.length);
9812
+ },
9813
+ };
9814
+
9815
+ function formatTimezoneShort(offset, delimiter = "") {
9816
+ const sign = offset > 0 ? "-" : "+";
9817
+ const absOffset = Math.abs(offset);
9818
+ const hours = Math.trunc(absOffset / 60);
9819
+ const minutes = absOffset % 60;
9820
+ if (minutes === 0) {
9821
+ return sign + String(hours);
9822
+ }
9823
+ return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
9824
+ }
9825
+
9826
+ function formatTimezoneWithOptionalMinutes(offset, delimiter) {
9827
+ if (offset % 60 === 0) {
9828
+ const sign = offset > 0 ? "-" : "+";
9829
+ return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
9830
+ }
9831
+ return formatTimezone(offset, delimiter);
9832
+ }
9833
+
9834
+ function formatTimezone(offset, delimiter = "") {
9835
+ const sign = offset > 0 ? "-" : "+";
9836
+ const absOffset = Math.abs(offset);
9837
+ const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
9838
+ const minutes = addLeadingZeros(absOffset % 60, 2);
9839
+ return sign + hours + delimiter + minutes;
9840
+ }
9841
+
9842
+ const dateLongFormatter = (pattern, formatLong) => {
9843
+ switch (pattern) {
9844
+ case "P":
9845
+ return formatLong.date({ width: "short" });
9846
+ case "PP":
9847
+ return formatLong.date({ width: "medium" });
9848
+ case "PPP":
9849
+ return formatLong.date({ width: "long" });
9850
+ case "PPPP":
9851
+ default:
9852
+ return formatLong.date({ width: "full" });
9853
+ }
9854
+ };
9855
+
9856
+ const timeLongFormatter = (pattern, formatLong) => {
9857
+ switch (pattern) {
9858
+ case "p":
9859
+ return formatLong.time({ width: "short" });
9860
+ case "pp":
9861
+ return formatLong.time({ width: "medium" });
9862
+ case "ppp":
9863
+ return formatLong.time({ width: "long" });
9864
+ case "pppp":
9865
+ default:
9866
+ return formatLong.time({ width: "full" });
9867
+ }
9868
+ };
9869
+
9870
+ const dateTimeLongFormatter = (pattern, formatLong) => {
9871
+ const matchResult = pattern.match(/(P+)(p+)?/) || [];
9872
+ const datePattern = matchResult[1];
9873
+ const timePattern = matchResult[2];
9874
+
9875
+ if (!timePattern) {
9876
+ return dateLongFormatter(pattern, formatLong);
9877
+ }
9878
+
9879
+ let dateTimeFormat;
9880
+
9881
+ switch (datePattern) {
9882
+ case "P":
9883
+ dateTimeFormat = formatLong.dateTime({ width: "short" });
9884
+ break;
9885
+ case "PP":
9886
+ dateTimeFormat = formatLong.dateTime({ width: "medium" });
9887
+ break;
9888
+ case "PPP":
9889
+ dateTimeFormat = formatLong.dateTime({ width: "long" });
9890
+ break;
9891
+ case "PPPP":
9892
+ default:
9893
+ dateTimeFormat = formatLong.dateTime({ width: "full" });
9894
+ break;
9895
+ }
9896
+
9897
+ return dateTimeFormat
9898
+ .replace("{{date}}", dateLongFormatter(datePattern, formatLong))
9899
+ .replace("{{time}}", timeLongFormatter(timePattern, formatLong));
9900
+ };
9901
+
9902
+ const longFormatters = {
9903
+ p: timeLongFormatter,
9904
+ P: dateTimeLongFormatter,
9905
+ };
9906
+
9907
+ const dayOfYearTokenRE = /^D+$/;
9908
+ const weekYearTokenRE = /^Y+$/;
9909
+
9910
+ const throwTokens = ["D", "DD", "YY", "YYYY"];
9911
+
9912
+ function isProtectedDayOfYearToken(token) {
9913
+ return dayOfYearTokenRE.test(token);
9914
+ }
9915
+
9916
+ function isProtectedWeekYearToken(token) {
9917
+ return weekYearTokenRE.test(token);
9918
+ }
9919
+
9920
+ function warnOrThrowProtectedError(token, format, input) {
9921
+ const _message = message(token, format, input);
9922
+ console.warn(_message);
9923
+ if (throwTokens.includes(token)) throw new RangeError(_message);
9924
+ }
9925
+
9926
+ function message(token, format, input) {
9927
+ const subject = token[0] === "Y" ? "years" : "days of the month";
9928
+ return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
9929
+ }
9930
+
9931
+ // This RegExp consists of three parts separated by `|`:
9932
+ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
9933
+ // (one of the certain letters followed by `o`)
9934
+ // - (\w)\1* matches any sequences of the same letter
9935
+ // - '' matches two quote characters in a row
9936
+ // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
9937
+ // except a single quote symbol, which ends the sequence.
9938
+ // Two quote characters do not end the sequence.
9939
+ // If there is no matching single quote
9940
+ // then the sequence will continue until the end of the string.
9941
+ // - . matches any single character unmatched by previous parts of the RegExps
9942
+ const formattingTokensRegExp =
9943
+ /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
9944
+
9945
+ // This RegExp catches symbols escaped by quotes, and also
9946
+ // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
9947
+ const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
9948
+
9949
+ const escapedStringRegExp = /^'([^]*?)'?$/;
9950
+ const doubleQuoteRegExp = /''/g;
9951
+ const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
9952
+
9953
+ /**
9954
+ * The {@link format} function options.
9955
+ */
9956
+
9957
+ /**
9958
+ * @name format
9959
+ * @alias formatDate
9960
+ * @category Common Helpers
9961
+ * @summary Format the date.
9962
+ *
9963
+ * @description
9964
+ * Return the formatted date string in the given format. The result may vary by locale.
9965
+ *
9966
+ * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
9967
+ * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
9968
+ *
9969
+ * The characters wrapped between two single quotes characters (') are escaped.
9970
+ * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
9971
+ * (see the last example)
9972
+ *
9973
+ * Format of the string is based on Unicode Technical Standard #35:
9974
+ * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
9975
+ * with a few additions (see note 7 below the table).
9976
+ *
9977
+ * Accepted patterns:
9978
+ * | Unit | Pattern | Result examples | Notes |
9979
+ * |---------------------------------|---------|-----------------------------------|-------|
9980
+ * | Era | G..GGG | AD, BC | |
9981
+ * | | GGGG | Anno Domini, Before Christ | 2 |
9982
+ * | | GGGGG | A, B | |
9983
+ * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
9984
+ * | | yo | 44th, 1st, 0th, 17th | 5,7 |
9985
+ * | | yy | 44, 01, 00, 17 | 5 |
9986
+ * | | yyy | 044, 001, 1900, 2017 | 5 |
9987
+ * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
9988
+ * | | yyyyy | ... | 3,5 |
9989
+ * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
9990
+ * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
9991
+ * | | YY | 44, 01, 00, 17 | 5,8 |
9992
+ * | | YYY | 044, 001, 1900, 2017 | 5 |
9993
+ * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
9994
+ * | | YYYYY | ... | 3,5 |
9995
+ * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
9996
+ * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
9997
+ * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
9998
+ * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
9999
+ * | | RRRRR | ... | 3,5,7 |
10000
+ * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
10001
+ * | | uu | -43, 01, 1900, 2017 | 5 |
10002
+ * | | uuu | -043, 001, 1900, 2017 | 5 |
10003
+ * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
10004
+ * | | uuuuu | ... | 3,5 |
10005
+ * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
10006
+ * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
10007
+ * | | QQ | 01, 02, 03, 04 | |
10008
+ * | | QQQ | Q1, Q2, Q3, Q4 | |
10009
+ * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
10010
+ * | | QQQQQ | 1, 2, 3, 4 | 4 |
10011
+ * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
10012
+ * | | qo | 1st, 2nd, 3rd, 4th | 7 |
10013
+ * | | qq | 01, 02, 03, 04 | |
10014
+ * | | qqq | Q1, Q2, Q3, Q4 | |
10015
+ * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
10016
+ * | | qqqqq | 1, 2, 3, 4 | 4 |
10017
+ * | Month (formatting) | M | 1, 2, ..., 12 | |
10018
+ * | | Mo | 1st, 2nd, ..., 12th | 7 |
10019
+ * | | MM | 01, 02, ..., 12 | |
10020
+ * | | MMM | Jan, Feb, ..., Dec | |
10021
+ * | | MMMM | January, February, ..., December | 2 |
10022
+ * | | MMMMM | J, F, ..., D | |
10023
+ * | Month (stand-alone) | L | 1, 2, ..., 12 | |
10024
+ * | | Lo | 1st, 2nd, ..., 12th | 7 |
10025
+ * | | LL | 01, 02, ..., 12 | |
10026
+ * | | LLL | Jan, Feb, ..., Dec | |
10027
+ * | | LLLL | January, February, ..., December | 2 |
10028
+ * | | LLLLL | J, F, ..., D | |
10029
+ * | Local week of year | w | 1, 2, ..., 53 | |
10030
+ * | | wo | 1st, 2nd, ..., 53th | 7 |
10031
+ * | | ww | 01, 02, ..., 53 | |
10032
+ * | ISO week of year | I | 1, 2, ..., 53 | 7 |
10033
+ * | | Io | 1st, 2nd, ..., 53th | 7 |
10034
+ * | | II | 01, 02, ..., 53 | 7 |
10035
+ * | Day of month | d | 1, 2, ..., 31 | |
10036
+ * | | do | 1st, 2nd, ..., 31st | 7 |
10037
+ * | | dd | 01, 02, ..., 31 | |
10038
+ * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
10039
+ * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
10040
+ * | | DD | 01, 02, ..., 365, 366 | 9 |
10041
+ * | | DDD | 001, 002, ..., 365, 366 | |
10042
+ * | | DDDD | ... | 3 |
10043
+ * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
10044
+ * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
10045
+ * | | EEEEE | M, T, W, T, F, S, S | |
10046
+ * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
10047
+ * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
10048
+ * | | io | 1st, 2nd, ..., 7th | 7 |
10049
+ * | | ii | 01, 02, ..., 07 | 7 |
10050
+ * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
10051
+ * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
10052
+ * | | iiiii | M, T, W, T, F, S, S | 7 |
10053
+ * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
10054
+ * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
10055
+ * | | eo | 2nd, 3rd, ..., 1st | 7 |
10056
+ * | | ee | 02, 03, ..., 01 | |
10057
+ * | | eee | Mon, Tue, Wed, ..., Sun | |
10058
+ * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
10059
+ * | | eeeee | M, T, W, T, F, S, S | |
10060
+ * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
10061
+ * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
10062
+ * | | co | 2nd, 3rd, ..., 1st | 7 |
10063
+ * | | cc | 02, 03, ..., 01 | |
10064
+ * | | ccc | Mon, Tue, Wed, ..., Sun | |
10065
+ * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
10066
+ * | | ccccc | M, T, W, T, F, S, S | |
10067
+ * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
10068
+ * | AM, PM | a..aa | AM, PM | |
10069
+ * | | aaa | am, pm | |
10070
+ * | | aaaa | a.m., p.m. | 2 |
10071
+ * | | aaaaa | a, p | |
10072
+ * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
10073
+ * | | bbb | am, pm, noon, midnight | |
10074
+ * | | bbbb | a.m., p.m., noon, midnight | 2 |
10075
+ * | | bbbbb | a, p, n, mi | |
10076
+ * | Flexible day period | B..BBB | at night, in the morning, ... | |
10077
+ * | | BBBB | at night, in the morning, ... | 2 |
10078
+ * | | BBBBB | at night, in the morning, ... | |
10079
+ * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
10080
+ * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
10081
+ * | | hh | 01, 02, ..., 11, 12 | |
10082
+ * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
10083
+ * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
10084
+ * | | HH | 00, 01, 02, ..., 23 | |
10085
+ * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
10086
+ * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
10087
+ * | | KK | 01, 02, ..., 11, 00 | |
10088
+ * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
10089
+ * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
10090
+ * | | kk | 24, 01, 02, ..., 23 | |
10091
+ * | Minute | m | 0, 1, ..., 59 | |
10092
+ * | | mo | 0th, 1st, ..., 59th | 7 |
10093
+ * | | mm | 00, 01, ..., 59 | |
10094
+ * | Second | s | 0, 1, ..., 59 | |
10095
+ * | | so | 0th, 1st, ..., 59th | 7 |
10096
+ * | | ss | 00, 01, ..., 59 | |
10097
+ * | Fraction of second | S | 0, 1, ..., 9 | |
10098
+ * | | SS | 00, 01, ..., 99 | |
10099
+ * | | SSS | 000, 001, ..., 999 | |
10100
+ * | | SSSS | ... | 3 |
10101
+ * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
10102
+ * | | XX | -0800, +0530, Z | |
10103
+ * | | XXX | -08:00, +05:30, Z | |
10104
+ * | | XXXX | -0800, +0530, Z, +123456 | 2 |
10105
+ * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
10106
+ * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
10107
+ * | | xx | -0800, +0530, +0000 | |
10108
+ * | | xxx | -08:00, +05:30, +00:00 | 2 |
10109
+ * | | xxxx | -0800, +0530, +0000, +123456 | |
10110
+ * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
10111
+ * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
10112
+ * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
10113
+ * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
10114
+ * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
10115
+ * | Seconds timestamp | t | 512969520 | 7 |
10116
+ * | | tt | ... | 3,7 |
10117
+ * | Milliseconds timestamp | T | 512969520900 | 7 |
10118
+ * | | TT | ... | 3,7 |
10119
+ * | Long localized date | P | 04/29/1453 | 7 |
10120
+ * | | PP | Apr 29, 1453 | 7 |
10121
+ * | | PPP | April 29th, 1453 | 7 |
10122
+ * | | PPPP | Friday, April 29th, 1453 | 2,7 |
10123
+ * | Long localized time | p | 12:00 AM | 7 |
10124
+ * | | pp | 12:00:00 AM | 7 |
10125
+ * | | ppp | 12:00:00 AM GMT+2 | 7 |
10126
+ * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
10127
+ * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
10128
+ * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
10129
+ * | | PPPppp | April 29th, 1453 at ... | 7 |
10130
+ * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
10131
+ * Notes:
10132
+ * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
10133
+ * are the same as "stand-alone" units, but are different in some languages.
10134
+ * "Formatting" units are declined according to the rules of the language
10135
+ * in the context of a date. "Stand-alone" units are always nominative singular:
10136
+ *
10137
+ * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
10138
+ *
10139
+ * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
10140
+ *
10141
+ * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
10142
+ * the single quote characters (see below).
10143
+ * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
10144
+ * the output will be the same as default pattern for this unit, usually
10145
+ * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
10146
+ * are marked with "2" in the last column of the table.
10147
+ *
10148
+ * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
10149
+ *
10150
+ * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
10151
+ *
10152
+ * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
10153
+ *
10154
+ * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
10155
+ *
10156
+ * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
10157
+ *
10158
+ * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
10159
+ * The output will be padded with zeros to match the length of the pattern.
10160
+ *
10161
+ * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
10162
+ *
10163
+ * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
10164
+ * These tokens represent the shortest form of the quarter.
10165
+ *
10166
+ * 5. The main difference between `y` and `u` patterns are B.C. years:
10167
+ *
10168
+ * | Year | `y` | `u` |
10169
+ * |------|-----|-----|
10170
+ * | AC 1 | 1 | 1 |
10171
+ * | BC 1 | 1 | 0 |
10172
+ * | BC 2 | 2 | -1 |
10173
+ *
10174
+ * Also `yy` always returns the last two digits of a year,
10175
+ * while `uu` pads single digit years to 2 characters and returns other years unchanged:
10176
+ *
10177
+ * | Year | `yy` | `uu` |
10178
+ * |------|------|------|
10179
+ * | 1 | 01 | 01 |
10180
+ * | 14 | 14 | 14 |
10181
+ * | 376 | 76 | 376 |
10182
+ * | 1453 | 53 | 1453 |
10183
+ *
10184
+ * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
10185
+ * except local week-numbering years are dependent on `options.weekStartsOn`
10186
+ * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear)
10187
+ * and [getWeekYear](https://date-fns.org/docs/getWeekYear)).
10188
+ *
10189
+ * 6. Specific non-location timezones are currently unavailable in `date-fns`,
10190
+ * so right now these tokens fall back to GMT timezones.
10191
+ *
10192
+ * 7. These patterns are not in the Unicode Technical Standard #35:
10193
+ * - `i`: ISO day of week
10194
+ * - `I`: ISO week of year
10195
+ * - `R`: ISO week-numbering year
10196
+ * - `t`: seconds timestamp
10197
+ * - `T`: milliseconds timestamp
10198
+ * - `o`: ordinal number modifier
10199
+ * - `P`: long localized date
10200
+ * - `p`: long localized time
10201
+ *
10202
+ * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
10203
+ * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10204
+ *
10205
+ * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
10206
+ * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10207
+ *
10208
+ * @param date - The original date
10209
+ * @param format - The string of tokens
10210
+ * @param options - An object with options
10211
+ *
10212
+ * @returns The formatted date string
10213
+ *
10214
+ * @throws `date` must not be Invalid Date
10215
+ * @throws `options.locale` must contain `localize` property
10216
+ * @throws `options.locale` must contain `formatLong` property
10217
+ * @throws use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10218
+ * @throws use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10219
+ * @throws use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10220
+ * @throws use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
10221
+ * @throws format string contains an unescaped latin alphabet character
10222
+ *
10223
+ * @example
10224
+ * // Represent 11 February 2014 in middle-endian format:
10225
+ * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
10226
+ * //=> '02/11/2014'
10227
+ *
10228
+ * @example
10229
+ * // Represent 2 July 2014 in Esperanto:
10230
+ * import { eoLocale } from 'date-fns/locale/eo'
10231
+ * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
10232
+ * locale: eoLocale
10233
+ * })
10234
+ * //=> '2-a de julio 2014'
10235
+ *
10236
+ * @example
10237
+ * // Escape string by single quote characters:
10238
+ * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
10239
+ * //=> "3 o'clock"
10240
+ */
10241
+ function format(date, formatStr, options) {
10242
+ const defaultOptions = getDefaultOptions();
10243
+ const locale = defaultOptions.locale ?? enUS;
10244
+
10245
+ const firstWeekContainsDate =
10246
+ defaultOptions.firstWeekContainsDate ??
10247
+ defaultOptions.locale?.options?.firstWeekContainsDate ??
10248
+ 1;
10249
+
10250
+ const weekStartsOn =
10251
+ defaultOptions.weekStartsOn ??
10252
+ defaultOptions.locale?.options?.weekStartsOn ??
10253
+ 0;
10254
+
10255
+ const originalDate = toDate(date, options?.in);
10256
+
10257
+ if (!isValid(originalDate)) {
10258
+ throw new RangeError("Invalid time value");
10259
+ }
10260
+
10261
+ let parts = formatStr
10262
+ .match(longFormattingTokensRegExp)
10263
+ .map((substring) => {
10264
+ const firstCharacter = substring[0];
10265
+ if (firstCharacter === "p" || firstCharacter === "P") {
10266
+ const longFormatter = longFormatters[firstCharacter];
10267
+ return longFormatter(substring, locale.formatLong);
10268
+ }
10269
+ return substring;
10270
+ })
10271
+ .join("")
10272
+ .match(formattingTokensRegExp)
10273
+ .map((substring) => {
10274
+ // Replace two single quote characters with one single quote character
10275
+ if (substring === "''") {
10276
+ return { isToken: false, value: "'" };
10277
+ }
10278
+
10279
+ const firstCharacter = substring[0];
10280
+ if (firstCharacter === "'") {
10281
+ return { isToken: false, value: cleanEscapedString(substring) };
10282
+ }
10283
+
10284
+ if (formatters[firstCharacter]) {
10285
+ return { isToken: true, value: substring };
10286
+ }
10287
+
10288
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
10289
+ throw new RangeError(
10290
+ "Format string contains an unescaped latin alphabet character `" +
10291
+ firstCharacter +
10292
+ "`",
10293
+ );
10294
+ }
10295
+
10296
+ return { isToken: false, value: substring };
10297
+ });
10298
+
10299
+ // invoke localize preprocessor (only for french locales at the moment)
10300
+ if (locale.localize.preprocessor) {
10301
+ parts = locale.localize.preprocessor(originalDate, parts);
10302
+ }
10303
+
10304
+ const formatterOptions = {
10305
+ firstWeekContainsDate,
10306
+ weekStartsOn,
10307
+ locale,
10308
+ };
10309
+
10310
+ return parts
10311
+ .map((part) => {
10312
+ if (!part.isToken) return part.value;
10313
+
10314
+ const token = part.value;
10315
+
10316
+ if (
10317
+ (isProtectedWeekYearToken(token)) ||
10318
+ (isProtectedDayOfYearToken(token))
10319
+ ) {
10320
+ warnOrThrowProtectedError(token, formatStr, String(date));
10321
+ }
10322
+
10323
+ const formatter = formatters[token[0]];
10324
+ return formatter(originalDate, token, locale.localize, formatterOptions);
10325
+ })
10326
+ .join("");
10327
+ }
10328
+
10329
+ function cleanEscapedString(input) {
10330
+ const matched = input.match(escapedStringRegExp);
10331
+
10332
+ if (!matched) {
10333
+ return input;
10334
+ }
10335
+
10336
+ return matched[1].replace(doubleQuoteRegExp, "'");
10337
+ }
10338
+
10339
+ /**
10340
+ * The {@link isSameWeek} function options.
10341
+ */
10342
+
10343
+ /**
10344
+ * @name isSameWeek
10345
+ * @category Week Helpers
10346
+ * @summary Are the given dates in the same week (and month and year)?
10347
+ *
10348
+ * @description
10349
+ * Are the given dates in the same week (and month and year)?
10350
+ *
10351
+ * @param laterDate - The first date to check
10352
+ * @param earlierDate - The second date to check
10353
+ * @param options - An object with options
10354
+ *
10355
+ * @returns The dates are in the same week (and month and year)
10356
+ *
10357
+ * @example
10358
+ * // Are 31 August 2014 and 4 September 2014 in the same week?
10359
+ * const result = isSameWeek(new Date(2014, 7, 31), new Date(2014, 8, 4))
10360
+ * //=> true
10361
+ *
10362
+ * @example
10363
+ * // If week starts with Monday,
10364
+ * // are 31 August 2014 and 4 September 2014 in the same week?
10365
+ * const result = isSameWeek(new Date(2014, 7, 31), new Date(2014, 8, 4), {
10366
+ * weekStartsOn: 1
10367
+ * })
10368
+ * //=> false
10369
+ *
10370
+ * @example
10371
+ * // Are 1 January 2014 and 1 January 2015 in the same week?
10372
+ * const result = isSameWeek(new Date(2014, 0, 1), new Date(2015, 0, 1))
10373
+ * //=> false
10374
+ */
10375
+ function isSameWeek(laterDate, earlierDate, options) {
10376
+ const [laterDate_, earlierDate_] = normalizeDates(
10377
+ options?.in,
10378
+ laterDate,
10379
+ earlierDate,
10380
+ );
10381
+ return (
10382
+ +startOfWeek(laterDate_, options) === +startOfWeek(earlierDate_, options)
10383
+ );
10384
+ }
10385
+
10386
+ class LocalizationService {
10387
+ defaultFormatStr = 'dd.MM.yyyy';
10388
+ format({ date, formatStr = this.defaultFormatStr, }) {
10389
+ const formatDate = format(date, formatStr);
10390
+ return formatDate;
10391
+ }
10392
+ }
10393
+ const localizationService = new LocalizationService();
10394
+
7565
10395
  /* eslint-disable no-console */
7566
10396
  class LoggerService {
7567
10397
  constructor() { }
@@ -25948,15 +28778,6 @@ const formatDistance = (token, count, options) => {
25948
28778
  return formatDistanceLocale[token](count, options);
25949
28779
  };
25950
28780
 
25951
- function buildFormatLongFn(args) {
25952
- return (options = {}) => {
25953
- // TODO: Remove String()
25954
- const width = options.width ? String(options.width) : args.defaultWidth;
25955
- const format = args.formats[width] || args.formats[args.defaultWidth];
25956
- return format;
25957
- };
25958
- }
25959
-
25960
28781
  const dateFormats = {
25961
28782
  full: "EEEE, d MMMM y 'г.'",
25962
28783
  long: "d MMMM y 'г.'",
@@ -25992,236 +28813,6 @@ const formatLong = {
25992
28813
  }),
25993
28814
  };
25994
28815
 
25995
- /**
25996
- * @module constants
25997
- * @summary Useful constants
25998
- * @description
25999
- * Collection of useful date constants.
26000
- *
26001
- * The constants could be imported from `date-fns/constants`:
26002
- *
26003
- * ```ts
26004
- * import { maxTime, minTime } from "./constants/date-fns/constants";
26005
- *
26006
- * function isAllowedTime(time) {
26007
- * return time <= maxTime && time >= minTime;
26008
- * }
26009
- * ```
26010
- */
26011
-
26012
-
26013
- /**
26014
- * @constant
26015
- * @name constructFromSymbol
26016
- * @summary Symbol enabling Date extensions to inherit properties from the reference date.
26017
- *
26018
- * The symbol is used to enable the `constructFrom` function to construct a date
26019
- * using a reference date and a value. It allows to transfer extra properties
26020
- * from the reference date to the new date. It's useful for extensions like
26021
- * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
26022
- * a constructor argument.
26023
- */
26024
- const constructFromSymbol = Symbol.for("constructDateFrom");
26025
-
26026
- /**
26027
- * @name constructFrom
26028
- * @category Generic Helpers
26029
- * @summary Constructs a date using the reference date and the value
26030
- *
26031
- * @description
26032
- * The function constructs a new date using the constructor from the reference
26033
- * date and the given value. It helps to build generic functions that accept
26034
- * date extensions.
26035
- *
26036
- * It defaults to `Date` if the passed reference date is a number or a string.
26037
- *
26038
- * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
26039
- * enabling to transfer extra properties from the reference date to the new date.
26040
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
26041
- * that accept a time zone as a constructor argument.
26042
- *
26043
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
26044
- *
26045
- * @param date - The reference date to take constructor from
26046
- * @param value - The value to create the date
26047
- *
26048
- * @returns Date initialized using the given date and value
26049
- *
26050
- * @example
26051
- * import { constructFrom } from "./constructFrom/date-fns";
26052
- *
26053
- * // A function that clones a date preserving the original type
26054
- * function cloneDate<DateType extends Date>(date: DateType): DateType {
26055
- * return constructFrom(
26056
- * date, // Use constructor from the given date
26057
- * date.getTime() // Use the date value to create a new date
26058
- * );
26059
- * }
26060
- */
26061
- function constructFrom(date, value) {
26062
- if (typeof date === "function") return date(value);
26063
-
26064
- if (date && typeof date === "object" && constructFromSymbol in date)
26065
- return date[constructFromSymbol](value);
26066
-
26067
- if (date instanceof Date) return new date.constructor(value);
26068
-
26069
- return new Date(value);
26070
- }
26071
-
26072
- function normalizeDates(context, ...dates) {
26073
- const normalize = constructFrom.bind(
26074
- null,
26075
- context || dates.find((date) => typeof date === "object"),
26076
- );
26077
- return dates.map(normalize);
26078
- }
26079
-
26080
- let defaultOptions$2 = {};
26081
-
26082
- function getDefaultOptions() {
26083
- return defaultOptions$2;
26084
- }
26085
-
26086
- /**
26087
- * @name toDate
26088
- * @category Common Helpers
26089
- * @summary Convert the given argument to an instance of Date.
26090
- *
26091
- * @description
26092
- * Convert the given argument to an instance of Date.
26093
- *
26094
- * If the argument is an instance of Date, the function returns its clone.
26095
- *
26096
- * If the argument is a number, it is treated as a timestamp.
26097
- *
26098
- * If the argument is none of the above, the function returns Invalid Date.
26099
- *
26100
- * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
26101
- * enabling to transfer extra properties from the reference date to the new date.
26102
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
26103
- * that accept a time zone as a constructor argument.
26104
- *
26105
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
26106
- *
26107
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
26108
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
26109
- *
26110
- * @param argument - The value to convert
26111
- *
26112
- * @returns The parsed date in the local time zone
26113
- *
26114
- * @example
26115
- * // Clone the date:
26116
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
26117
- * //=> Tue Feb 11 2014 11:30:30
26118
- *
26119
- * @example
26120
- * // Convert the timestamp to date:
26121
- * const result = toDate(1392098430000)
26122
- * //=> Tue Feb 11 2014 11:30:30
26123
- */
26124
- function toDate(argument, context) {
26125
- // [TODO] Get rid of `toDate` or `constructFrom`?
26126
- return constructFrom(context || argument, argument);
26127
- }
26128
-
26129
- /**
26130
- * The {@link startOfWeek} function options.
26131
- */
26132
-
26133
- /**
26134
- * @name startOfWeek
26135
- * @category Week Helpers
26136
- * @summary Return the start of a week for the given date.
26137
- *
26138
- * @description
26139
- * Return the start of a week for the given date.
26140
- * The result will be in the local timezone.
26141
- *
26142
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
26143
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
26144
- *
26145
- * @param date - The original date
26146
- * @param options - An object with options
26147
- *
26148
- * @returns The start of a week
26149
- *
26150
- * @example
26151
- * // The start of a week for 2 September 2014 11:55:00:
26152
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
26153
- * //=> Sun Aug 31 2014 00:00:00
26154
- *
26155
- * @example
26156
- * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
26157
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
26158
- * //=> Mon Sep 01 2014 00:00:00
26159
- */
26160
- function startOfWeek(date, options) {
26161
- const defaultOptions = getDefaultOptions();
26162
- const weekStartsOn =
26163
- options?.weekStartsOn ??
26164
- options?.locale?.options?.weekStartsOn ??
26165
- defaultOptions.weekStartsOn ??
26166
- defaultOptions.locale?.options?.weekStartsOn ??
26167
- 0;
26168
-
26169
- const _date = toDate(date, options?.in);
26170
- const day = _date.getDay();
26171
- const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
26172
-
26173
- _date.setDate(_date.getDate() - diff);
26174
- _date.setHours(0, 0, 0, 0);
26175
- return _date;
26176
- }
26177
-
26178
- /**
26179
- * The {@link isSameWeek} function options.
26180
- */
26181
-
26182
- /**
26183
- * @name isSameWeek
26184
- * @category Week Helpers
26185
- * @summary Are the given dates in the same week (and month and year)?
26186
- *
26187
- * @description
26188
- * Are the given dates in the same week (and month and year)?
26189
- *
26190
- * @param laterDate - The first date to check
26191
- * @param earlierDate - The second date to check
26192
- * @param options - An object with options
26193
- *
26194
- * @returns The dates are in the same week (and month and year)
26195
- *
26196
- * @example
26197
- * // Are 31 August 2014 and 4 September 2014 in the same week?
26198
- * const result = isSameWeek(new Date(2014, 7, 31), new Date(2014, 8, 4))
26199
- * //=> true
26200
- *
26201
- * @example
26202
- * // If week starts with Monday,
26203
- * // are 31 August 2014 and 4 September 2014 in the same week?
26204
- * const result = isSameWeek(new Date(2014, 7, 31), new Date(2014, 8, 4), {
26205
- * weekStartsOn: 1
26206
- * })
26207
- * //=> false
26208
- *
26209
- * @example
26210
- * // Are 1 January 2014 and 1 January 2015 in the same week?
26211
- * const result = isSameWeek(new Date(2014, 0, 1), new Date(2015, 0, 1))
26212
- * //=> false
26213
- */
26214
- function isSameWeek(laterDate, earlierDate, options) {
26215
- const [laterDate_, earlierDate_] = normalizeDates(
26216
- options?.in,
26217
- laterDate,
26218
- earlierDate,
26219
- );
26220
- return (
26221
- +startOfWeek(laterDate_, options) === +startOfWeek(earlierDate_, options)
26222
- );
26223
- }
26224
-
26225
28816
  const accusativeWeekdays = [
26226
28817
  "воскресенье",
26227
28818
  "понедельник",
@@ -26309,69 +28900,6 @@ const formatRelative = (token, date, baseDate, options) => {
26309
28900
  return format;
26310
28901
  };
26311
28902
 
26312
- /**
26313
- * The localize function argument callback which allows to convert raw value to
26314
- * the actual type.
26315
- *
26316
- * @param value - The value to convert
26317
- *
26318
- * @returns The converted value
26319
- */
26320
-
26321
- /**
26322
- * The map of localized values for each width.
26323
- */
26324
-
26325
- /**
26326
- * The index type of the locale unit value. It types conversion of units of
26327
- * values that don't start at 0 (i.e. quarters).
26328
- */
26329
-
26330
- /**
26331
- * Converts the unit value to the tuple of values.
26332
- */
26333
-
26334
- /**
26335
- * The tuple of localized era values. The first element represents BC,
26336
- * the second element represents AD.
26337
- */
26338
-
26339
- /**
26340
- * The tuple of localized quarter values. The first element represents Q1.
26341
- */
26342
-
26343
- /**
26344
- * The tuple of localized day values. The first element represents Sunday.
26345
- */
26346
-
26347
- /**
26348
- * The tuple of localized month values. The first element represents January.
26349
- */
26350
-
26351
- function buildLocalizeFn(args) {
26352
- return (value, options) => {
26353
- const context = options?.context ? String(options.context) : "standalone";
26354
-
26355
- let valuesArray;
26356
- if (context === "formatting" && args.formattingValues) {
26357
- const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
26358
- const width = options?.width ? String(options.width) : defaultWidth;
26359
-
26360
- valuesArray =
26361
- args.formattingValues[width] || args.formattingValues[defaultWidth];
26362
- } else {
26363
- const defaultWidth = args.defaultWidth;
26364
- const width = options?.width ? String(options.width) : args.defaultWidth;
26365
-
26366
- valuesArray = args.values[width] || args.values[defaultWidth];
26367
- }
26368
- const index = args.argumentCallback ? args.argumentCallback(value) : value;
26369
-
26370
- // @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
26371
- return valuesArray[index];
26372
- };
26373
- }
26374
-
26375
28903
  const eraValues = {
26376
28904
  narrow: ["до н.э.", "н.э."],
26377
28905
  abbreviated: ["до н. э.", "н. э."],
@@ -26581,85 +29109,6 @@ const localize = {
26581
29109
  }),
26582
29110
  };
26583
29111
 
26584
- function buildMatchFn(args) {
26585
- return (string, options = {}) => {
26586
- const width = options.width;
26587
-
26588
- const matchPattern =
26589
- (width && args.matchPatterns[width]) ||
26590
- args.matchPatterns[args.defaultMatchWidth];
26591
- const matchResult = string.match(matchPattern);
26592
-
26593
- if (!matchResult) {
26594
- return null;
26595
- }
26596
- const matchedString = matchResult[0];
26597
-
26598
- const parsePatterns =
26599
- (width && args.parsePatterns[width]) ||
26600
- args.parsePatterns[args.defaultParseWidth];
26601
-
26602
- const key = Array.isArray(parsePatterns)
26603
- ? findIndex$1(parsePatterns, (pattern) => pattern.test(matchedString))
26604
- : // [TODO] -- I challenge you to fix the type
26605
- findKey(parsePatterns, (pattern) => pattern.test(matchedString));
26606
-
26607
- let value;
26608
-
26609
- value = args.valueCallback ? args.valueCallback(key) : key;
26610
- value = options.valueCallback
26611
- ? // [TODO] -- I challenge you to fix the type
26612
- options.valueCallback(value)
26613
- : value;
26614
-
26615
- const rest = string.slice(matchedString.length);
26616
-
26617
- return { value, rest };
26618
- };
26619
- }
26620
-
26621
- function findKey(object, predicate) {
26622
- for (const key in object) {
26623
- if (
26624
- Object.prototype.hasOwnProperty.call(object, key) &&
26625
- predicate(object[key])
26626
- ) {
26627
- return key;
26628
- }
26629
- }
26630
- return undefined;
26631
- }
26632
-
26633
- function findIndex$1(array, predicate) {
26634
- for (let key = 0; key < array.length; key++) {
26635
- if (predicate(array[key])) {
26636
- return key;
26637
- }
26638
- }
26639
- return undefined;
26640
- }
26641
-
26642
- function buildMatchPatternFn(args) {
26643
- return (string, options = {}) => {
26644
- const matchResult = string.match(args.matchPattern);
26645
- if (!matchResult) return null;
26646
- const matchedString = matchResult[0];
26647
-
26648
- const parseResult = string.match(args.parsePattern);
26649
- if (!parseResult) return null;
26650
- let value = args.valueCallback
26651
- ? args.valueCallback(parseResult[0])
26652
- : parseResult[0];
26653
-
26654
- // [TODO] I challenge you to fix the type
26655
- value = options.valueCallback ? options.valueCallback(value) : value;
26656
-
26657
- const rest = string.slice(matchedString.length);
26658
-
26659
- return { value, rest };
26660
- };
26661
- }
26662
-
26663
29112
  const matchOrdinalNumberPattern = /^(\d+)(-?(е|я|й|ое|ье|ая|ья|ый|ой|ий|ый))?/i;
26664
29113
  const parseOrdinalNumberPattern = /\d+/i;
26665
29114
 
@@ -32211,12 +34660,15 @@ function useForm(props = {}) {
32211
34660
  return _formControl.current;
32212
34661
  }
32213
34662
 
34663
+ const StyledParagraph$1 = material.styled(material.Typography)(() => {
34664
+ return {
34665
+ color: 'var(--color-white)',
34666
+ cursor: 'default',
34667
+ };
34668
+ });
34669
+
32214
34670
  const Paragraph = ({ sx, ...props }) => {
32215
- return (jsxRuntime.jsx(Typography, { variant: "body1", sx: {
32216
- color: 'var(--color-white)',
32217
- cursor: 'default',
32218
- ...sx,
32219
- }, ...props }));
34671
+ return jsxRuntime.jsx(StyledParagraph$1, { variant: "body1", sx: sx, ...props });
32220
34672
  };
32221
34673
 
32222
34674
  const CheckboxStyled = styles$2.styled(Checkbox)({
@@ -32256,6 +34708,126 @@ function CustomCheckbox({ label, name, ...props }) {
32256
34708
  } }, key));
32257
34709
  }
32258
34710
 
34711
+ function E$1(e) {
34712
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
34713
+ }
34714
+ var C$1, v;
34715
+ function h$1() {
34716
+ return v || (v = 1, C$1 = function() {
34717
+ var e = document.getSelection();
34718
+ if (!e.rangeCount)
34719
+ return function() {
34720
+ };
34721
+ for (var r = document.activeElement, s = [], o = 0; o < e.rangeCount; o++)
34722
+ s.push(e.getRangeAt(o));
34723
+ switch (r.tagName.toUpperCase()) {
34724
+ // .toUpperCase handles XHTML
34725
+ case "INPUT":
34726
+ case "TEXTAREA":
34727
+ r.blur();
34728
+ break;
34729
+ default:
34730
+ r = null;
34731
+ break;
34732
+ }
34733
+ return e.removeAllRanges(), function() {
34734
+ e.type === "Caret" && e.removeAllRanges(), e.rangeCount || s.forEach(function(d) {
34735
+ e.addRange(d);
34736
+ }), r && r.focus();
34737
+ };
34738
+ }), C$1;
34739
+ }
34740
+ var b, w;
34741
+ function R() {
34742
+ if (w) return b;
34743
+ w = 1;
34744
+ var e = h$1(), r = {
34745
+ "text/plain": "Text",
34746
+ "text/html": "Url",
34747
+ default: "Text"
34748
+ }, s = "Copy to clipboard: #{key}, Enter";
34749
+ function o(n) {
34750
+ var t = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
34751
+ return n.replace(/#{\s*key\s*}/g, t);
34752
+ }
34753
+ function d(n, t) {
34754
+ var l, i, f, p, u, a, y = false;
34755
+ t || (t = {}), l = t.debug || false;
34756
+ try {
34757
+ f = e(), p = document.createRange(), u = document.getSelection(), a = document.createElement("span"), a.textContent = n, a.ariaHidden = "true", a.style.all = "unset", a.style.position = "fixed", a.style.top = 0, a.style.clip = "rect(0, 0, 0, 0)", a.style.whiteSpace = "pre", a.style.webkitUserSelect = "text", a.style.MozUserSelect = "text", a.style.msUserSelect = "text", a.style.userSelect = "text", a.addEventListener("copy", function(c) {
34758
+ if (c.stopPropagation(), t.format)
34759
+ if (c.preventDefault(), typeof c.clipboardData > "u") {
34760
+ l && console.warn("unable to use e.clipboardData"), l && console.warn("trying IE specific stuff"), window.clipboardData.clearData();
34761
+ var g = r[t.format] || r.default;
34762
+ window.clipboardData.setData(g, n);
34763
+ } else
34764
+ c.clipboardData.clearData(), c.clipboardData.setData(t.format, n);
34765
+ t.onCopy && (c.preventDefault(), t.onCopy(c.clipboardData));
34766
+ }), document.body.appendChild(a), p.selectNodeContents(a), u.addRange(p);
34767
+ var D = document.execCommand("copy");
34768
+ if (!D)
34769
+ throw new Error("copy command was unsuccessful");
34770
+ y = !0;
34771
+ } catch (c) {
34772
+ l && console.error("unable to copy using execCommand: ", c), l && console.warn("trying IE specific stuff");
34773
+ try {
34774
+ window.clipboardData.setData(t.format || "text", n), t.onCopy && t.onCopy(window.clipboardData), y = !0;
34775
+ } catch (g) {
34776
+ l && console.error("unable to copy using clipboardData: ", g), l && console.error("falling back to prompt"), i = o("message" in t ? t.message : s), window.prompt(i, n);
34777
+ }
34778
+ } finally {
34779
+ u && (typeof u.removeRange == "function" ? u.removeRange(p) : u.removeAllRanges()), a && document.body.removeChild(a), f();
34780
+ }
34781
+ return y;
34782
+ }
34783
+ return b = d, b;
34784
+ }
34785
+ var T$1 = R();
34786
+ const k$1 = /* @__PURE__ */ E$1(T$1), S$2 = ({
34787
+ text: e,
34788
+ onCopy: r,
34789
+ options: s,
34790
+ children: o,
34791
+ ...d
34792
+ }) => {
34793
+ const n = React__namespace.useCallback(
34794
+ (l) => {
34795
+ const i = React__namespace.Children.only(
34796
+ o
34797
+ ), f = k$1(e, s);
34798
+ r && r(e, f), i.props.onClick && typeof i.props.onClick == "function" && i.props.onClick(l);
34799
+ },
34800
+ [e, r, s, o]
34801
+ ), t = React__namespace.Children.only(o);
34802
+ return React__namespace.cloneElement(t, { onClick: n, ...d });
34803
+ };
34804
+
34805
+ const StyledParagraph = material.styled(Paragraph)(() => {
34806
+ return {
34807
+ cursor: 'pointer',
34808
+ };
34809
+ });
34810
+
34811
+ const CopyText = ({ value, label, onCopySuccess, onCopyError, ...props }) => {
34812
+ const text = String(value);
34813
+ return (jsxRuntime.jsx(S$2, { text: text, onCopy: (_, result) => {
34814
+ if (result) {
34815
+ showSnackbar({
34816
+ message: 'Значение успешно скопировано',
34817
+ variant: 'success',
34818
+ });
34819
+ onCopySuccess?.();
34820
+ }
34821
+ else {
34822
+ showSnackbar({
34823
+ message: 'При копировании значения возникла ошибка',
34824
+ variant: 'error',
34825
+ });
34826
+ onCopyError?.();
34827
+ }
34828
+ }, children: jsxRuntime.jsx(StyledParagraph, { ...props, children: label }) }));
34829
+ };
34830
+
32259
34831
  var s$1=function(s){var t=s.as,a=s.errors,m=s.name,o=s.message,i=s.render,l=function(e,r){if(null==e)return {};var n,s,t={},a=Object.keys(e);for(s=0;s<a.length;s++)r.indexOf(n=a[s])>=0||(t[n]=e[n]);return t}(s,["as","errors","name","message","render"]),f=useFormContext$1(),c=get(a||f.formState.errors,m);if(!c)return null;var g=c.message,u=c.types,d=Object.assign({},l,{children:g||o});return React__namespace.isValidElement(t)?React__namespace.cloneElement(t,d):i?i({message:g||o,messages:u}):React__namespace.createElement(t||React__namespace.Fragment,d)};
32260
34832
 
32261
34833
  function FormErrorMessage({ name }) {
@@ -47861,6 +50433,7 @@ exports.Button = Button;
47861
50433
  exports.CSVUploader = CSVUploader;
47862
50434
  exports.Card = CustomCard;
47863
50435
  exports.Checkbox = CustomCheckbox;
50436
+ exports.CopyText = CopyText;
47864
50437
  exports.DartcomAuthProvider = auth;
47865
50438
  exports.DartcomMobxProvider = DartcomMobxProvider;
47866
50439
  exports.DartcomProviders = DartcomProviders;
@@ -47944,6 +50517,7 @@ exports.getValidLayer = getValidLayer;
47944
50517
  exports.getWaterAreaLayers = getWaterAreaLayers;
47945
50518
  exports.getWaterLinkLayers = getWaterLinkLayers;
47946
50519
  exports.localStateService = localStateService;
50520
+ exports.localizationService = localizationService;
47947
50521
  exports.loggerService = loggerService;
47948
50522
  exports.mapService = mapService;
47949
50523
  exports.modalStore = modalStore;