@citygross/components 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,14 +4,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var index = require('../../_virtual/index2.js');
6
6
  var React$1 = require('react');
7
+ var require$$1 = require('date-fns');
8
+ var require$$2 = require('date-fns/locale');
7
9
 
8
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
11
 
10
12
  var React__default$1 = /*#__PURE__*/_interopDefaultLegacy(React$1);
13
+ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
14
+ var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
11
15
 
12
16
  Object.defineProperty(index.__exports, '__esModule', { value: true });
13
17
 
14
18
  var React = React__default$1["default"];
19
+ var dateFns = require$$1__default["default"];
20
+ var locale = require$$2__default["default"];
15
21
 
16
22
  function _interopDefaultLegacy$1 (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
23
 
@@ -581,3372 +587,24 @@ var formatPostalCode = function (postalCode, spaceIndex) {
581
587
  });
582
588
  };
583
589
 
584
- /**
585
- * @module constants
586
- * @summary Useful constants
587
- * @description
588
- * Collection of useful date constants.
589
- *
590
- * The constants could be imported from `date-fns/constants`:
591
- *
592
- * ```ts
593
- * import { maxTime, minTime } from "./constants/date-fns/constants";
594
- *
595
- * function isAllowedTime(time) {
596
- * return time <= maxTime && time >= minTime;
597
- * }
598
- * ```
599
- */
600
-
601
- /**
602
- * @constant
603
- * @name millisecondsInWeek
604
- * @summary Milliseconds in 1 week.
605
- */
606
- const millisecondsInWeek = 604800000;
607
-
608
- /**
609
- * @constant
610
- * @name millisecondsInDay
611
- * @summary Milliseconds in 1 day.
612
- */
613
- const millisecondsInDay = 86400000;
614
-
615
- /**
616
- * @constant
617
- * @name constructFromSymbol
618
- * @summary Symbol enabling Date extensions to inherit properties from the reference date.
619
- *
620
- * The symbol is used to enable the `constructFrom` function to construct a date
621
- * using a reference date and a value. It allows to transfer extra properties
622
- * from the reference date to the new date. It's useful for extensions like
623
- * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
624
- * a constructor argument.
625
- */
626
- const constructFromSymbol = Symbol.for("constructDateFrom");
627
-
628
- /**
629
- * @name constructFrom
630
- * @category Generic Helpers
631
- * @summary Constructs a date using the reference date and the value
632
- *
633
- * @description
634
- * The function constructs a new date using the constructor from the reference
635
- * date and the given value. It helps to build generic functions that accept
636
- * date extensions.
637
- *
638
- * It defaults to `Date` if the passed reference date is a number or a string.
639
- *
640
- * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
641
- * enabling to transfer extra properties from the reference date to the new date.
642
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
643
- * that accept a time zone as a constructor argument.
644
- *
645
- * @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).
646
- *
647
- * @param date - The reference date to take constructor from
648
- * @param value - The value to create the date
649
- *
650
- * @returns Date initialized using the given date and value
651
- *
652
- * @example
653
- * import { constructFrom } from "./constructFrom/date-fns";
654
- *
655
- * // A function that clones a date preserving the original type
656
- * function cloneDate<DateType extends Date>(date: DateType): DateType {
657
- * return constructFrom(
658
- * date, // Use constructor from the given date
659
- * date.getTime() // Use the date value to create a new date
660
- * );
661
- * }
662
- */
663
- function constructFrom(date, value) {
664
- if (typeof date === "function") return date(value);
665
-
666
- if (date && typeof date === "object" && constructFromSymbol in date)
667
- return date[constructFromSymbol](value);
668
-
669
- if (date instanceof Date) return new date.constructor(value);
670
-
671
- return new Date(value);
672
- }
673
-
674
- /**
675
- * @name toDate
676
- * @category Common Helpers
677
- * @summary Convert the given argument to an instance of Date.
678
- *
679
- * @description
680
- * Convert the given argument to an instance of Date.
681
- *
682
- * If the argument is an instance of Date, the function returns its clone.
683
- *
684
- * If the argument is a number, it is treated as a timestamp.
685
- *
686
- * If the argument is none of the above, the function returns Invalid Date.
687
- *
688
- * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
689
- * enabling to transfer extra properties from the reference date to the new date.
690
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
691
- * that accept a time zone as a constructor argument.
692
- *
693
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
694
- *
695
- * @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).
696
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
697
- *
698
- * @param argument - The value to convert
699
- *
700
- * @returns The parsed date in the local time zone
701
- *
702
- * @example
703
- * // Clone the date:
704
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
705
- * //=> Tue Feb 11 2014 11:30:30
706
- *
707
- * @example
708
- * // Convert the timestamp to date:
709
- * const result = toDate(1392098430000)
710
- * //=> Tue Feb 11 2014 11:30:30
711
- */
712
- function toDate(argument, context) {
713
- // [TODO] Get rid of `toDate` or `constructFrom`?
714
- return constructFrom(context || argument, argument);
715
- }
716
-
717
- /**
718
- * The {@link addDays} function options.
719
- */
720
-
721
- /**
722
- * @name addDays
723
- * @category Day Helpers
724
- * @summary Add the specified number of days to the given date.
725
- *
726
- * @description
727
- * Add the specified number of days to the given date.
728
- *
729
- * @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).
730
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
731
- *
732
- * @param date - The date to be changed
733
- * @param amount - The amount of days to be added.
734
- * @param options - An object with options
735
- *
736
- * @returns The new date with the days added
737
- *
738
- * @example
739
- * // Add 10 days to 1 September 2014:
740
- * const result = addDays(new Date(2014, 8, 1), 10)
741
- * //=> Thu Sep 11 2014 00:00:00
742
- */
743
- function addDays(date, amount, options) {
744
- const _date = toDate(date, options?.in);
745
- if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
746
-
747
- // If 0 days, no-op to avoid changing times in the hour before end of DST
748
- if (!amount) return _date;
749
-
750
- _date.setDate(_date.getDate() + amount);
751
- return _date;
752
- }
753
-
754
- let defaultOptions = {};
755
-
756
- function getDefaultOptions() {
757
- return defaultOptions;
758
- }
759
-
760
- /**
761
- * The {@link startOfWeek} function options.
762
- */
763
-
764
- /**
765
- * @name startOfWeek
766
- * @category Week Helpers
767
- * @summary Return the start of a week for the given date.
768
- *
769
- * @description
770
- * Return the start of a week for the given date.
771
- * The result will be in the local timezone.
772
- *
773
- * @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).
774
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
775
- *
776
- * @param date - The original date
777
- * @param options - An object with options
778
- *
779
- * @returns The start of a week
780
- *
781
- * @example
782
- * // The start of a week for 2 September 2014 11:55:00:
783
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
784
- * //=> Sun Aug 31 2014 00:00:00
785
- *
786
- * @example
787
- * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
788
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
789
- * //=> Mon Sep 01 2014 00:00:00
790
- */
791
- function startOfWeek(date, options) {
792
- const defaultOptions = getDefaultOptions();
793
- const weekStartsOn =
794
- options?.weekStartsOn ??
795
- options?.locale?.options?.weekStartsOn ??
796
- defaultOptions.weekStartsOn ??
797
- defaultOptions.locale?.options?.weekStartsOn ??
798
- 0;
799
-
800
- const _date = toDate(date, options?.in);
801
- const day = _date.getDay();
802
- const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
803
-
804
- _date.setDate(_date.getDate() - diff);
805
- _date.setHours(0, 0, 0, 0);
806
- return _date;
807
- }
808
-
809
- /**
810
- * The {@link startOfISOWeek} function options.
811
- */
812
-
813
- /**
814
- * @name startOfISOWeek
815
- * @category ISO Week Helpers
816
- * @summary Return the start of an ISO week for the given date.
817
- *
818
- * @description
819
- * Return the start of an ISO week for the given date.
820
- * The result will be in the local timezone.
821
- *
822
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
823
- *
824
- * @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).
825
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
826
- *
827
- * @param date - The original date
828
- * @param options - An object with options
829
- *
830
- * @returns The start of an ISO week
831
- *
832
- * @example
833
- * // The start of an ISO week for 2 September 2014 11:55:00:
834
- * const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0))
835
- * //=> Mon Sep 01 2014 00:00:00
836
- */
837
- function startOfISOWeek(date, options) {
838
- return startOfWeek(date, { ...options, weekStartsOn: 1 });
839
- }
840
-
841
- /**
842
- * The {@link getISOWeekYear} function options.
843
- */
844
-
845
- /**
846
- * @name getISOWeekYear
847
- * @category ISO Week-Numbering Year Helpers
848
- * @summary Get the ISO week-numbering year of the given date.
849
- *
850
- * @description
851
- * Get the ISO week-numbering year of the given date,
852
- * which always starts 3 days before the year's first Thursday.
853
- *
854
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
855
- *
856
- * @param date - The given date
857
- *
858
- * @returns The ISO week-numbering year
859
- *
860
- * @example
861
- * // Which ISO-week numbering year is 2 January 2005?
862
- * const result = getISOWeekYear(new Date(2005, 0, 2))
863
- * //=> 2004
864
- */
865
- function getISOWeekYear(date, options) {
866
- const _date = toDate(date, options?.in);
867
- const year = _date.getFullYear();
868
-
869
- const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
870
- fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
871
- fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
872
- const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
873
-
874
- const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
875
- fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
876
- fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
877
- const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
878
-
879
- if (_date.getTime() >= startOfNextYear.getTime()) {
880
- return year + 1;
881
- } else if (_date.getTime() >= startOfThisYear.getTime()) {
882
- return year;
883
- } else {
884
- return year - 1;
885
- }
886
- }
887
-
888
- /**
889
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
890
- * They usually appear for dates that denote time before the timezones were introduced
891
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
892
- * and GMT+01:00:00 after that date)
893
- *
894
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
895
- * which would lead to incorrect calculations.
896
- *
897
- * This function returns the timezone offset in milliseconds that takes seconds in account.
898
- */
899
- function getTimezoneOffsetInMilliseconds(date) {
900
- const _date = toDate(date);
901
- const utcDate = new Date(
902
- Date.UTC(
903
- _date.getFullYear(),
904
- _date.getMonth(),
905
- _date.getDate(),
906
- _date.getHours(),
907
- _date.getMinutes(),
908
- _date.getSeconds(),
909
- _date.getMilliseconds(),
910
- ),
911
- );
912
- utcDate.setUTCFullYear(_date.getFullYear());
913
- return +date - +utcDate;
914
- }
915
-
916
- function normalizeDates(context, ...dates) {
917
- const normalize = constructFrom.bind(
918
- null,
919
- context || dates.find((date) => typeof date === "object"),
920
- );
921
- return dates.map(normalize);
922
- }
923
-
924
- /**
925
- * The {@link startOfDay} function options.
926
- */
927
-
928
- /**
929
- * @name startOfDay
930
- * @category Day Helpers
931
- * @summary Return the start of a day for the given date.
932
- *
933
- * @description
934
- * Return the start of a day for the given date.
935
- * The result will be in the local timezone.
936
- *
937
- * @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).
938
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
939
- *
940
- * @param date - The original date
941
- * @param options - The options
942
- *
943
- * @returns The start of a day
944
- *
945
- * @example
946
- * // The start of a day for 2 September 2014 11:55:00:
947
- * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
948
- * //=> Tue Sep 02 2014 00:00:00
949
- */
950
- function startOfDay(date, options) {
951
- const _date = toDate(date, options?.in);
952
- _date.setHours(0, 0, 0, 0);
953
- return _date;
954
- }
955
-
956
- /**
957
- * The {@link differenceInCalendarDays} function options.
958
- */
959
-
960
- /**
961
- * @name differenceInCalendarDays
962
- * @category Day Helpers
963
- * @summary Get the number of calendar days between the given dates.
964
- *
965
- * @description
966
- * Get the number of calendar days between the given dates. This means that the times are removed
967
- * from the dates and then the difference in days is calculated.
968
- *
969
- * @param laterDate - The later date
970
- * @param earlierDate - The earlier date
971
- * @param options - The options object
972
- *
973
- * @returns The number of calendar days
974
- *
975
- * @example
976
- * // How many calendar days are between
977
- * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
978
- * const result = differenceInCalendarDays(
979
- * new Date(2012, 6, 2, 0, 0),
980
- * new Date(2011, 6, 2, 23, 0)
981
- * )
982
- * //=> 366
983
- * // How many calendar days are between
984
- * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
985
- * const result = differenceInCalendarDays(
986
- * new Date(2011, 6, 3, 0, 1),
987
- * new Date(2011, 6, 2, 23, 59)
988
- * )
989
- * //=> 1
990
- */
991
- function differenceInCalendarDays(laterDate, earlierDate, options) {
992
- const [laterDate_, earlierDate_] = normalizeDates(
993
- options?.in,
994
- laterDate,
995
- earlierDate,
996
- );
997
-
998
- const laterStartOfDay = startOfDay(laterDate_);
999
- const earlierStartOfDay = startOfDay(earlierDate_);
1000
-
1001
- const laterTimestamp =
1002
- +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
1003
- const earlierTimestamp =
1004
- +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
1005
-
1006
- // Round the number of days to the nearest integer because the number of
1007
- // milliseconds in a day is not constant (e.g. it's different in the week of
1008
- // the daylight saving time clock shift).
1009
- return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
1010
- }
1011
-
1012
- /**
1013
- * The {@link startOfISOWeekYear} function options.
1014
- */
1015
-
1016
- /**
1017
- * @name startOfISOWeekYear
1018
- * @category ISO Week-Numbering Year Helpers
1019
- * @summary Return the start of an ISO week-numbering year for the given date.
1020
- *
1021
- * @description
1022
- * Return the start of an ISO week-numbering year,
1023
- * which always starts 3 days before the year's first Thursday.
1024
- * The result will be in the local timezone.
1025
- *
1026
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
1027
- *
1028
- * @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).
1029
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1030
- *
1031
- * @param date - The original date
1032
- * @param options - An object with options
1033
- *
1034
- * @returns The start of an ISO week-numbering year
1035
- *
1036
- * @example
1037
- * // The start of an ISO week-numbering year for 2 July 2005:
1038
- * const result = startOfISOWeekYear(new Date(2005, 6, 2))
1039
- * //=> Mon Jan 03 2005 00:00:00
1040
- */
1041
- function startOfISOWeekYear(date, options) {
1042
- const year = getISOWeekYear(date, options);
1043
- const fourthOfJanuary = constructFrom(options?.in || date, 0);
1044
- fourthOfJanuary.setFullYear(year, 0, 4);
1045
- fourthOfJanuary.setHours(0, 0, 0, 0);
1046
- return startOfISOWeek(fourthOfJanuary);
1047
- }
1048
-
1049
- /**
1050
- * The {@link isSameDay} function options.
1051
- */
1052
-
1053
- /**
1054
- * @name isSameDay
1055
- * @category Day Helpers
1056
- * @summary Are the given dates in the same day (and year and month)?
1057
- *
1058
- * @description
1059
- * Are the given dates in the same day (and year and month)?
1060
- *
1061
- * @param laterDate - The first date to check
1062
- * @param earlierDate - The second date to check
1063
- * @param options - An object with options
1064
- *
1065
- * @returns The dates are in the same day (and year and month)
1066
- *
1067
- * @example
1068
- * // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
1069
- * const result = isSameDay(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 18, 0))
1070
- * //=> true
1071
- *
1072
- * @example
1073
- * // Are 4 September and 4 October in the same day?
1074
- * const result = isSameDay(new Date(2014, 8, 4), new Date(2014, 9, 4))
1075
- * //=> false
1076
- *
1077
- * @example
1078
- * // Are 4 September, 2014 and 4 September, 2015 in the same day?
1079
- * const result = isSameDay(new Date(2014, 8, 4), new Date(2015, 8, 4))
1080
- * //=> false
1081
- */
1082
- function isSameDay(laterDate, earlierDate, options) {
1083
- const [dateLeft_, dateRight_] = normalizeDates(
1084
- options?.in,
1085
- laterDate,
1086
- earlierDate,
1087
- );
1088
- return +startOfDay(dateLeft_) === +startOfDay(dateRight_);
1089
- }
1090
-
1091
- /**
1092
- * @name isDate
1093
- * @category Common Helpers
1094
- * @summary Is the given value a date?
1095
- *
1096
- * @description
1097
- * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
1098
- *
1099
- * @param value - The value to check
1100
- *
1101
- * @returns True if the given value is a date
1102
- *
1103
- * @example
1104
- * // For a valid date:
1105
- * const result = isDate(new Date())
1106
- * //=> true
1107
- *
1108
- * @example
1109
- * // For an invalid date:
1110
- * const result = isDate(new Date(NaN))
1111
- * //=> true
1112
- *
1113
- * @example
1114
- * // For some value:
1115
- * const result = isDate('2014-02-31')
1116
- * //=> false
1117
- *
1118
- * @example
1119
- * // For an object:
1120
- * const result = isDate({})
1121
- * //=> false
1122
- */
1123
- function isDate(value) {
1124
- return (
1125
- value instanceof Date ||
1126
- (typeof value === "object" &&
1127
- Object.prototype.toString.call(value) === "[object Date]")
1128
- );
1129
- }
1130
-
1131
- /**
1132
- * @name isValid
1133
- * @category Common Helpers
1134
- * @summary Is the given date valid?
1135
- *
1136
- * @description
1137
- * Returns false if argument is Invalid Date and true otherwise.
1138
- * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate)
1139
- * Invalid Date is a Date, whose time value is NaN.
1140
- *
1141
- * Time value of Date: http://es5.github.io/#x15.9.1.1
1142
- *
1143
- * @param date - The date to check
1144
- *
1145
- * @returns The date is valid
1146
- *
1147
- * @example
1148
- * // For the valid date:
1149
- * const result = isValid(new Date(2014, 1, 31))
1150
- * //=> true
1151
- *
1152
- * @example
1153
- * // For the value, convertible into a date:
1154
- * const result = isValid(1393804800000)
1155
- * //=> true
1156
- *
1157
- * @example
1158
- * // For the invalid date:
1159
- * const result = isValid(new Date(''))
1160
- * //=> false
1161
- */
1162
- function isValid(date) {
1163
- return !((!isDate(date) && typeof date !== "number") || isNaN(+toDate(date)));
1164
- }
1165
-
1166
- /**
1167
- * The {@link startOfYear} function options.
1168
- */
1169
-
1170
- /**
1171
- * @name startOfYear
1172
- * @category Year Helpers
1173
- * @summary Return the start of a year for the given date.
1174
- *
1175
- * @description
1176
- * Return the start of a year for the given date.
1177
- * The result will be in the local timezone.
1178
- *
1179
- * @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).
1180
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
1181
- *
1182
- * @param date - The original date
1183
- * @param options - The options
1184
- *
1185
- * @returns The start of a year
1186
- *
1187
- * @example
1188
- * // The start of a year for 2 September 2014 11:55:00:
1189
- * const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00))
1190
- * //=> Wed Jan 01 2014 00:00:00
1191
- */
1192
- function startOfYear(date, options) {
1193
- const date_ = toDate(date, options?.in);
1194
- date_.setFullYear(date_.getFullYear(), 0, 1);
1195
- date_.setHours(0, 0, 0, 0);
1196
- return date_;
1197
- }
1198
-
1199
- const formatDistanceLocale$1 = {
1200
- lessThanXSeconds: {
1201
- one: "less than a second",
1202
- other: "less than {{count}} seconds",
1203
- },
1204
-
1205
- xSeconds: {
1206
- one: "1 second",
1207
- other: "{{count}} seconds",
1208
- },
1209
-
1210
- halfAMinute: "half a minute",
1211
-
1212
- lessThanXMinutes: {
1213
- one: "less than a minute",
1214
- other: "less than {{count}} minutes",
1215
- },
1216
-
1217
- xMinutes: {
1218
- one: "1 minute",
1219
- other: "{{count}} minutes",
1220
- },
1221
-
1222
- aboutXHours: {
1223
- one: "about 1 hour",
1224
- other: "about {{count}} hours",
1225
- },
1226
-
1227
- xHours: {
1228
- one: "1 hour",
1229
- other: "{{count}} hours",
1230
- },
1231
-
1232
- xDays: {
1233
- one: "1 day",
1234
- other: "{{count}} days",
1235
- },
1236
-
1237
- aboutXWeeks: {
1238
- one: "about 1 week",
1239
- other: "about {{count}} weeks",
1240
- },
1241
-
1242
- xWeeks: {
1243
- one: "1 week",
1244
- other: "{{count}} weeks",
1245
- },
1246
-
1247
- aboutXMonths: {
1248
- one: "about 1 month",
1249
- other: "about {{count}} months",
1250
- },
1251
-
1252
- xMonths: {
1253
- one: "1 month",
1254
- other: "{{count}} months",
1255
- },
1256
-
1257
- aboutXYears: {
1258
- one: "about 1 year",
1259
- other: "about {{count}} years",
1260
- },
1261
-
1262
- xYears: {
1263
- one: "1 year",
1264
- other: "{{count}} years",
1265
- },
1266
-
1267
- overXYears: {
1268
- one: "over 1 year",
1269
- other: "over {{count}} years",
1270
- },
1271
-
1272
- almostXYears: {
1273
- one: "almost 1 year",
1274
- other: "almost {{count}} years",
1275
- },
1276
- };
1277
-
1278
- const formatDistance$1 = (token, count, options) => {
1279
- let result;
1280
-
1281
- const tokenValue = formatDistanceLocale$1[token];
1282
- if (typeof tokenValue === "string") {
1283
- result = tokenValue;
1284
- } else if (count === 1) {
1285
- result = tokenValue.one;
1286
- } else {
1287
- result = tokenValue.other.replace("{{count}}", count.toString());
1288
- }
1289
-
1290
- if (options?.addSuffix) {
1291
- if (options.comparison && options.comparison > 0) {
1292
- return "in " + result;
1293
- } else {
1294
- return result + " ago";
1295
- }
1296
- }
1297
-
1298
- return result;
1299
- };
1300
-
1301
- function buildFormatLongFn(args) {
1302
- return (options = {}) => {
1303
- // TODO: Remove String()
1304
- const width = options.width ? String(options.width) : args.defaultWidth;
1305
- const format = args.formats[width] || args.formats[args.defaultWidth];
1306
- return format;
1307
- };
1308
- }
1309
-
1310
- const dateFormats$1 = {
1311
- full: "EEEE, MMMM do, y",
1312
- long: "MMMM do, y",
1313
- medium: "MMM d, y",
1314
- short: "MM/dd/yyyy",
1315
- };
1316
-
1317
- const timeFormats$1 = {
1318
- full: "h:mm:ss a zzzz",
1319
- long: "h:mm:ss a z",
1320
- medium: "h:mm:ss a",
1321
- short: "h:mm a",
1322
- };
1323
-
1324
- const dateTimeFormats$1 = {
1325
- full: "{{date}} 'at' {{time}}",
1326
- long: "{{date}} 'at' {{time}}",
1327
- medium: "{{date}}, {{time}}",
1328
- short: "{{date}}, {{time}}",
1329
- };
1330
-
1331
- const formatLong$1 = {
1332
- date: buildFormatLongFn({
1333
- formats: dateFormats$1,
1334
- defaultWidth: "full",
1335
- }),
1336
-
1337
- time: buildFormatLongFn({
1338
- formats: timeFormats$1,
1339
- defaultWidth: "full",
1340
- }),
1341
-
1342
- dateTime: buildFormatLongFn({
1343
- formats: dateTimeFormats$1,
1344
- defaultWidth: "full",
1345
- }),
1346
- };
1347
-
1348
- const formatRelativeLocale$1 = {
1349
- lastWeek: "'last' eeee 'at' p",
1350
- yesterday: "'yesterday at' p",
1351
- today: "'today at' p",
1352
- tomorrow: "'tomorrow at' p",
1353
- nextWeek: "eeee 'at' p",
1354
- other: "P",
1355
- };
1356
-
1357
- const formatRelative$1 = (token, _date, _baseDate, _options) =>
1358
- formatRelativeLocale$1[token];
1359
-
1360
- /**
1361
- * The localize function argument callback which allows to convert raw value to
1362
- * the actual type.
1363
- *
1364
- * @param value - The value to convert
1365
- *
1366
- * @returns The converted value
1367
- */
1368
-
1369
- /**
1370
- * The map of localized values for each width.
1371
- */
1372
-
1373
- /**
1374
- * The index type of the locale unit value. It types conversion of units of
1375
- * values that don't start at 0 (i.e. quarters).
1376
- */
1377
-
1378
- /**
1379
- * Converts the unit value to the tuple of values.
1380
- */
1381
-
1382
- /**
1383
- * The tuple of localized era values. The first element represents BC,
1384
- * the second element represents AD.
1385
- */
1386
-
1387
- /**
1388
- * The tuple of localized quarter values. The first element represents Q1.
1389
- */
1390
-
1391
- /**
1392
- * The tuple of localized day values. The first element represents Sunday.
1393
- */
1394
-
1395
- /**
1396
- * The tuple of localized month values. The first element represents January.
1397
- */
1398
-
1399
- function buildLocalizeFn(args) {
1400
- return (value, options) => {
1401
- const context = options?.context ? String(options.context) : "standalone";
1402
-
1403
- let valuesArray;
1404
- if (context === "formatting" && args.formattingValues) {
1405
- const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
1406
- const width = options?.width ? String(options.width) : defaultWidth;
1407
-
1408
- valuesArray =
1409
- args.formattingValues[width] || args.formattingValues[defaultWidth];
1410
- } else {
1411
- const defaultWidth = args.defaultWidth;
1412
- const width = options?.width ? String(options.width) : args.defaultWidth;
1413
-
1414
- valuesArray = args.values[width] || args.values[defaultWidth];
1415
- }
1416
- const index = args.argumentCallback ? args.argumentCallback(value) : value;
1417
-
1418
- // @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!
1419
- return valuesArray[index];
1420
- };
1421
- }
1422
-
1423
- const eraValues$1 = {
1424
- narrow: ["B", "A"],
1425
- abbreviated: ["BC", "AD"],
1426
- wide: ["Before Christ", "Anno Domini"],
1427
- };
1428
-
1429
- const quarterValues$1 = {
1430
- narrow: ["1", "2", "3", "4"],
1431
- abbreviated: ["Q1", "Q2", "Q3", "Q4"],
1432
- wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
1433
- };
1434
-
1435
- // Note: in English, the names of days of the week and months are capitalized.
1436
- // If you are making a new locale based on this one, check if the same is true for the language you're working on.
1437
- // Generally, formatted dates should look like they are in the middle of a sentence,
1438
- // e.g. in Spanish language the weekdays and months should be in the lowercase.
1439
- const monthValues$1 = {
1440
- narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
1441
- abbreviated: [
1442
- "Jan",
1443
- "Feb",
1444
- "Mar",
1445
- "Apr",
1446
- "May",
1447
- "Jun",
1448
- "Jul",
1449
- "Aug",
1450
- "Sep",
1451
- "Oct",
1452
- "Nov",
1453
- "Dec",
1454
- ],
1455
-
1456
- wide: [
1457
- "January",
1458
- "February",
1459
- "March",
1460
- "April",
1461
- "May",
1462
- "June",
1463
- "July",
1464
- "August",
1465
- "September",
1466
- "October",
1467
- "November",
1468
- "December",
1469
- ],
1470
- };
1471
-
1472
- const dayValues$1 = {
1473
- narrow: ["S", "M", "T", "W", "T", "F", "S"],
1474
- short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
1475
- abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
1476
- wide: [
1477
- "Sunday",
1478
- "Monday",
1479
- "Tuesday",
1480
- "Wednesday",
1481
- "Thursday",
1482
- "Friday",
1483
- "Saturday",
1484
- ],
1485
- };
1486
-
1487
- const dayPeriodValues$1 = {
1488
- narrow: {
1489
- am: "a",
1490
- pm: "p",
1491
- midnight: "mi",
1492
- noon: "n",
1493
- morning: "morning",
1494
- afternoon: "afternoon",
1495
- evening: "evening",
1496
- night: "night",
1497
- },
1498
- abbreviated: {
1499
- am: "AM",
1500
- pm: "PM",
1501
- midnight: "midnight",
1502
- noon: "noon",
1503
- morning: "morning",
1504
- afternoon: "afternoon",
1505
- evening: "evening",
1506
- night: "night",
1507
- },
1508
- wide: {
1509
- am: "a.m.",
1510
- pm: "p.m.",
1511
- midnight: "midnight",
1512
- noon: "noon",
1513
- morning: "morning",
1514
- afternoon: "afternoon",
1515
- evening: "evening",
1516
- night: "night",
1517
- },
1518
- };
1519
-
1520
- const formattingDayPeriodValues$1 = {
1521
- narrow: {
1522
- am: "a",
1523
- pm: "p",
1524
- midnight: "mi",
1525
- noon: "n",
1526
- morning: "in the morning",
1527
- afternoon: "in the afternoon",
1528
- evening: "in the evening",
1529
- night: "at night",
1530
- },
1531
- abbreviated: {
1532
- am: "AM",
1533
- pm: "PM",
1534
- midnight: "midnight",
1535
- noon: "noon",
1536
- morning: "in the morning",
1537
- afternoon: "in the afternoon",
1538
- evening: "in the evening",
1539
- night: "at night",
1540
- },
1541
- wide: {
1542
- am: "a.m.",
1543
- pm: "p.m.",
1544
- midnight: "midnight",
1545
- noon: "noon",
1546
- morning: "in the morning",
1547
- afternoon: "in the afternoon",
1548
- evening: "in the evening",
1549
- night: "at night",
1550
- },
1551
- };
1552
-
1553
- const ordinalNumber$1 = (dirtyNumber, _options) => {
1554
- const number = Number(dirtyNumber);
1555
-
1556
- // If ordinal numbers depend on context, for example,
1557
- // if they are different for different grammatical genders,
1558
- // use `options.unit`.
1559
- //
1560
- // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
1561
- // 'day', 'hour', 'minute', 'second'.
1562
-
1563
- const rem100 = number % 100;
1564
- if (rem100 > 20 || rem100 < 10) {
1565
- switch (rem100 % 10) {
1566
- case 1:
1567
- return number + "st";
1568
- case 2:
1569
- return number + "nd";
1570
- case 3:
1571
- return number + "rd";
1572
- }
1573
- }
1574
- return number + "th";
1575
- };
1576
-
1577
- const localize$1 = {
1578
- ordinalNumber: ordinalNumber$1,
1579
-
1580
- era: buildLocalizeFn({
1581
- values: eraValues$1,
1582
- defaultWidth: "wide",
1583
- }),
1584
-
1585
- quarter: buildLocalizeFn({
1586
- values: quarterValues$1,
1587
- defaultWidth: "wide",
1588
- argumentCallback: (quarter) => quarter - 1,
1589
- }),
1590
-
1591
- month: buildLocalizeFn({
1592
- values: monthValues$1,
1593
- defaultWidth: "wide",
1594
- }),
1595
-
1596
- day: buildLocalizeFn({
1597
- values: dayValues$1,
1598
- defaultWidth: "wide",
1599
- }),
1600
-
1601
- dayPeriod: buildLocalizeFn({
1602
- values: dayPeriodValues$1,
1603
- defaultWidth: "wide",
1604
- formattingValues: formattingDayPeriodValues$1,
1605
- defaultFormattingWidth: "wide",
1606
- }),
1607
- };
1608
-
1609
- function buildMatchFn(args) {
1610
- return (string, options = {}) => {
1611
- const width = options.width;
1612
-
1613
- const matchPattern =
1614
- (width && args.matchPatterns[width]) ||
1615
- args.matchPatterns[args.defaultMatchWidth];
1616
- const matchResult = string.match(matchPattern);
1617
-
1618
- if (!matchResult) {
1619
- return null;
1620
- }
1621
- const matchedString = matchResult[0];
1622
-
1623
- const parsePatterns =
1624
- (width && args.parsePatterns[width]) ||
1625
- args.parsePatterns[args.defaultParseWidth];
1626
-
1627
- const key = Array.isArray(parsePatterns)
1628
- ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
1629
- : // [TODO] -- I challenge you to fix the type
1630
- findKey(parsePatterns, (pattern) => pattern.test(matchedString));
1631
-
1632
- let value;
1633
-
1634
- value = args.valueCallback ? args.valueCallback(key) : key;
1635
- value = options.valueCallback
1636
- ? // [TODO] -- I challenge you to fix the type
1637
- options.valueCallback(value)
1638
- : value;
1639
-
1640
- const rest = string.slice(matchedString.length);
1641
-
1642
- return { value, rest };
1643
- };
1644
- }
1645
-
1646
- function findKey(object, predicate) {
1647
- for (const key in object) {
1648
- if (
1649
- Object.prototype.hasOwnProperty.call(object, key) &&
1650
- predicate(object[key])
1651
- ) {
1652
- return key;
1653
- }
1654
- }
1655
- return undefined;
1656
- }
1657
-
1658
- function findIndex(array, predicate) {
1659
- for (let key = 0; key < array.length; key++) {
1660
- if (predicate(array[key])) {
1661
- return key;
1662
- }
1663
- }
1664
- return undefined;
1665
- }
1666
-
1667
- function buildMatchPatternFn(args) {
1668
- return (string, options = {}) => {
1669
- const matchResult = string.match(args.matchPattern);
1670
- if (!matchResult) return null;
1671
- const matchedString = matchResult[0];
1672
-
1673
- const parseResult = string.match(args.parsePattern);
1674
- if (!parseResult) return null;
1675
- let value = args.valueCallback
1676
- ? args.valueCallback(parseResult[0])
1677
- : parseResult[0];
1678
-
1679
- // [TODO] I challenge you to fix the type
1680
- value = options.valueCallback ? options.valueCallback(value) : value;
1681
-
1682
- const rest = string.slice(matchedString.length);
1683
-
1684
- return { value, rest };
1685
- };
1686
- }
1687
-
1688
- const matchOrdinalNumberPattern$1 = /^(\d+)(th|st|nd|rd)?/i;
1689
- const parseOrdinalNumberPattern$1 = /\d+/i;
1690
-
1691
- const matchEraPatterns$1 = {
1692
- narrow: /^(b|a)/i,
1693
- abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
1694
- wide: /^(before christ|before common era|anno domini|common era)/i,
1695
- };
1696
- const parseEraPatterns$1 = {
1697
- any: [/^b/i, /^(a|c)/i],
1698
- };
1699
-
1700
- const matchQuarterPatterns$1 = {
1701
- narrow: /^[1234]/i,
1702
- abbreviated: /^q[1234]/i,
1703
- wide: /^[1234](th|st|nd|rd)? quarter/i,
1704
- };
1705
- const parseQuarterPatterns$1 = {
1706
- any: [/1/i, /2/i, /3/i, /4/i],
1707
- };
1708
-
1709
- const matchMonthPatterns$1 = {
1710
- narrow: /^[jfmasond]/i,
1711
- abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
1712
- wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i,
1713
- };
1714
- const parseMonthPatterns$1 = {
1715
- narrow: [
1716
- /^j/i,
1717
- /^f/i,
1718
- /^m/i,
1719
- /^a/i,
1720
- /^m/i,
1721
- /^j/i,
1722
- /^j/i,
1723
- /^a/i,
1724
- /^s/i,
1725
- /^o/i,
1726
- /^n/i,
1727
- /^d/i,
1728
- ],
1729
-
1730
- any: [
1731
- /^ja/i,
1732
- /^f/i,
1733
- /^mar/i,
1734
- /^ap/i,
1735
- /^may/i,
1736
- /^jun/i,
1737
- /^jul/i,
1738
- /^au/i,
1739
- /^s/i,
1740
- /^o/i,
1741
- /^n/i,
1742
- /^d/i,
1743
- ],
1744
- };
1745
-
1746
- const matchDayPatterns$1 = {
1747
- narrow: /^[smtwf]/i,
1748
- short: /^(su|mo|tu|we|th|fr|sa)/i,
1749
- abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
1750
- wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i,
1751
- };
1752
- const parseDayPatterns$1 = {
1753
- narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
1754
- any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i],
1755
- };
1756
-
1757
- const matchDayPeriodPatterns$1 = {
1758
- narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
1759
- any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i,
1760
- };
1761
- const parseDayPeriodPatterns$1 = {
1762
- any: {
1763
- am: /^a/i,
1764
- pm: /^p/i,
1765
- midnight: /^mi/i,
1766
- noon: /^no/i,
1767
- morning: /morning/i,
1768
- afternoon: /afternoon/i,
1769
- evening: /evening/i,
1770
- night: /night/i,
1771
- },
1772
- };
1773
-
1774
- const match$1 = {
1775
- ordinalNumber: buildMatchPatternFn({
1776
- matchPattern: matchOrdinalNumberPattern$1,
1777
- parsePattern: parseOrdinalNumberPattern$1,
1778
- valueCallback: (value) => parseInt(value, 10),
1779
- }),
1780
-
1781
- era: buildMatchFn({
1782
- matchPatterns: matchEraPatterns$1,
1783
- defaultMatchWidth: "wide",
1784
- parsePatterns: parseEraPatterns$1,
1785
- defaultParseWidth: "any",
1786
- }),
1787
-
1788
- quarter: buildMatchFn({
1789
- matchPatterns: matchQuarterPatterns$1,
1790
- defaultMatchWidth: "wide",
1791
- parsePatterns: parseQuarterPatterns$1,
1792
- defaultParseWidth: "any",
1793
- valueCallback: (index) => index + 1,
1794
- }),
1795
-
1796
- month: buildMatchFn({
1797
- matchPatterns: matchMonthPatterns$1,
1798
- defaultMatchWidth: "wide",
1799
- parsePatterns: parseMonthPatterns$1,
1800
- defaultParseWidth: "any",
1801
- }),
1802
-
1803
- day: buildMatchFn({
1804
- matchPatterns: matchDayPatterns$1,
1805
- defaultMatchWidth: "wide",
1806
- parsePatterns: parseDayPatterns$1,
1807
- defaultParseWidth: "any",
1808
- }),
1809
-
1810
- dayPeriod: buildMatchFn({
1811
- matchPatterns: matchDayPeriodPatterns$1,
1812
- defaultMatchWidth: "any",
1813
- parsePatterns: parseDayPeriodPatterns$1,
1814
- defaultParseWidth: "any",
1815
- }),
1816
- };
1817
-
1818
- /**
1819
- * @category Locales
1820
- * @summary English locale (United States).
1821
- * @language English
1822
- * @iso-639-2 eng
1823
- * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp)
1824
- * @author Lesha Koss [@leshakoss](https://github.com/leshakoss)
1825
- */
1826
- const enUS = {
1827
- code: "en-US",
1828
- formatDistance: formatDistance$1,
1829
- formatLong: formatLong$1,
1830
- formatRelative: formatRelative$1,
1831
- localize: localize$1,
1832
- match: match$1,
1833
- options: {
1834
- weekStartsOn: 0 /* Sunday */,
1835
- firstWeekContainsDate: 1,
1836
- },
1837
- };
1838
-
1839
- /**
1840
- * The {@link getDayOfYear} function options.
1841
- */
1842
-
1843
- /**
1844
- * @name getDayOfYear
1845
- * @category Day Helpers
1846
- * @summary Get the day of the year of the given date.
1847
- *
1848
- * @description
1849
- * Get the day of the year of the given date.
1850
- *
1851
- * @param date - The given date
1852
- * @param options - The options
1853
- *
1854
- * @returns The day of year
1855
- *
1856
- * @example
1857
- * // Which day of the year is 2 July 2014?
1858
- * const result = getDayOfYear(new Date(2014, 6, 2))
1859
- * //=> 183
1860
- */
1861
- function getDayOfYear(date, options) {
1862
- const _date = toDate(date, options?.in);
1863
- const diff = differenceInCalendarDays(_date, startOfYear(_date));
1864
- const dayOfYear = diff + 1;
1865
- return dayOfYear;
1866
- }
1867
-
1868
- /**
1869
- * The {@link getISOWeek} function options.
1870
- */
1871
-
1872
- /**
1873
- * @name getISOWeek
1874
- * @category ISO Week Helpers
1875
- * @summary Get the ISO week of the given date.
1876
- *
1877
- * @description
1878
- * Get the ISO week of the given date.
1879
- *
1880
- * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
1881
- *
1882
- * @param date - The given date
1883
- * @param options - The options
1884
- *
1885
- * @returns The ISO week
1886
- *
1887
- * @example
1888
- * // Which week of the ISO-week numbering year is 2 January 2005?
1889
- * const result = getISOWeek(new Date(2005, 0, 2))
1890
- * //=> 53
1891
- */
1892
- function getISOWeek(date, options) {
1893
- const _date = toDate(date, options?.in);
1894
- const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
1895
-
1896
- // Round the number of weeks to the nearest integer because the number of
1897
- // milliseconds in a week is not constant (e.g. it's different in the week of
1898
- // the daylight saving time clock shift).
1899
- return Math.round(diff / millisecondsInWeek) + 1;
1900
- }
1901
-
1902
- /**
1903
- * The {@link getWeekYear} function options.
1904
- */
1905
-
1906
- /**
1907
- * @name getWeekYear
1908
- * @category Week-Numbering Year Helpers
1909
- * @summary Get the local week-numbering year of the given date.
1910
- *
1911
- * @description
1912
- * Get the local week-numbering year of the given date.
1913
- * The exact calculation depends on the values of
1914
- * `options.weekStartsOn` (which is the index of the first day of the week)
1915
- * and `options.firstWeekContainsDate` (which is the day of January, which is always in
1916
- * the first week of the week-numbering year)
1917
- *
1918
- * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
1919
- *
1920
- * @param date - The given date
1921
- * @param options - An object with options.
1922
- *
1923
- * @returns The local week-numbering year
1924
- *
1925
- * @example
1926
- * // Which week numbering year is 26 December 2004 with the default settings?
1927
- * const result = getWeekYear(new Date(2004, 11, 26))
1928
- * //=> 2005
1929
- *
1930
- * @example
1931
- * // Which week numbering year is 26 December 2004 if week starts on Saturday?
1932
- * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
1933
- * //=> 2004
1934
- *
1935
- * @example
1936
- * // Which week numbering year is 26 December 2004 if the first week contains 4 January?
1937
- * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
1938
- * //=> 2004
1939
- */
1940
- function getWeekYear(date, options) {
1941
- const _date = toDate(date, options?.in);
1942
- const year = _date.getFullYear();
1943
-
1944
- const defaultOptions = getDefaultOptions();
1945
- const firstWeekContainsDate =
1946
- options?.firstWeekContainsDate ??
1947
- options?.locale?.options?.firstWeekContainsDate ??
1948
- defaultOptions.firstWeekContainsDate ??
1949
- defaultOptions.locale?.options?.firstWeekContainsDate ??
1950
- 1;
1951
-
1952
- const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
1953
- firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
1954
- firstWeekOfNextYear.setHours(0, 0, 0, 0);
1955
- const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
1956
-
1957
- const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
1958
- firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
1959
- firstWeekOfThisYear.setHours(0, 0, 0, 0);
1960
- const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
1961
-
1962
- if (+_date >= +startOfNextYear) {
1963
- return year + 1;
1964
- } else if (+_date >= +startOfThisYear) {
1965
- return year;
1966
- } else {
1967
- return year - 1;
1968
- }
1969
- }
1970
-
1971
- /**
1972
- * The {@link startOfWeekYear} function options.
1973
- */
1974
-
1975
- /**
1976
- * @name startOfWeekYear
1977
- * @category Week-Numbering Year Helpers
1978
- * @summary Return the start of a local week-numbering year for the given date.
1979
- *
1980
- * @description
1981
- * Return the start of a local week-numbering year.
1982
- * The exact calculation depends on the values of
1983
- * `options.weekStartsOn` (which is the index of the first day of the week)
1984
- * and `options.firstWeekContainsDate` (which is the day of January, which is always in
1985
- * the first week of the week-numbering year)
1986
- *
1987
- * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
1988
- *
1989
- * @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).
1990
- * @typeParam ResultDate - The result `Date` type.
1991
- *
1992
- * @param date - The original date
1993
- * @param options - An object with options
1994
- *
1995
- * @returns The start of a week-numbering year
1996
- *
1997
- * @example
1998
- * // The start of an a week-numbering year for 2 July 2005 with default settings:
1999
- * const result = startOfWeekYear(new Date(2005, 6, 2))
2000
- * //=> Sun Dec 26 2004 00:00:00
2001
- *
2002
- * @example
2003
- * // The start of a week-numbering year for 2 July 2005
2004
- * // if Monday is the first day of week
2005
- * // and 4 January is always in the first week of the year:
2006
- * const result = startOfWeekYear(new Date(2005, 6, 2), {
2007
- * weekStartsOn: 1,
2008
- * firstWeekContainsDate: 4
2009
- * })
2010
- * //=> Mon Jan 03 2005 00:00:00
2011
- */
2012
- function startOfWeekYear(date, options) {
2013
- const defaultOptions = getDefaultOptions();
2014
- const firstWeekContainsDate =
2015
- options?.firstWeekContainsDate ??
2016
- options?.locale?.options?.firstWeekContainsDate ??
2017
- defaultOptions.firstWeekContainsDate ??
2018
- defaultOptions.locale?.options?.firstWeekContainsDate ??
2019
- 1;
2020
-
2021
- const year = getWeekYear(date, options);
2022
- const firstWeek = constructFrom(options?.in || date, 0);
2023
- firstWeek.setFullYear(year, 0, firstWeekContainsDate);
2024
- firstWeek.setHours(0, 0, 0, 0);
2025
- const _date = startOfWeek(firstWeek, options);
2026
- return _date;
2027
- }
2028
-
2029
- /**
2030
- * The {@link getWeek} function options.
2031
- */
2032
-
2033
- /**
2034
- * @name getWeek
2035
- * @category Week Helpers
2036
- * @summary Get the local week index of the given date.
2037
- *
2038
- * @description
2039
- * Get the local week index of the given date.
2040
- * The exact calculation depends on the values of
2041
- * `options.weekStartsOn` (which is the index of the first day of the week)
2042
- * and `options.firstWeekContainsDate` (which is the day of January, which is always in
2043
- * the first week of the week-numbering year)
2044
- *
2045
- * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
2046
- *
2047
- * @param date - The given date
2048
- * @param options - An object with options
2049
- *
2050
- * @returns The week
2051
- *
2052
- * @example
2053
- * // Which week of the local week numbering year is 2 January 2005 with default options?
2054
- * const result = getWeek(new Date(2005, 0, 2))
2055
- * //=> 2
2056
- *
2057
- * @example
2058
- * // Which week of the local week numbering year is 2 January 2005,
2059
- * // if Monday is the first day of the week,
2060
- * // and the first week of the year always contains 4 January?
2061
- * const result = getWeek(new Date(2005, 0, 2), {
2062
- * weekStartsOn: 1,
2063
- * firstWeekContainsDate: 4
2064
- * })
2065
- * //=> 53
2066
- */
2067
- function getWeek(date, options) {
2068
- const _date = toDate(date, options?.in);
2069
- const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
2070
-
2071
- // Round the number of weeks to the nearest integer because the number of
2072
- // milliseconds in a week is not constant (e.g. it's different in the week of
2073
- // the daylight saving time clock shift).
2074
- return Math.round(diff / millisecondsInWeek) + 1;
2075
- }
2076
-
2077
- function addLeadingZeros(number, targetLength) {
2078
- const sign = number < 0 ? "-" : "";
2079
- const output = Math.abs(number).toString().padStart(targetLength, "0");
2080
- return sign + output;
2081
- }
2082
-
2083
- /*
2084
- * | | Unit | | Unit |
2085
- * |-----|--------------------------------|-----|--------------------------------|
2086
- * | a | AM, PM | A* | |
2087
- * | d | Day of month | D | |
2088
- * | h | Hour [1-12] | H | Hour [0-23] |
2089
- * | m | Minute | M | Month |
2090
- * | s | Second | S | Fraction of second |
2091
- * | y | Year (abs) | Y | |
2092
- *
2093
- * Letters marked by * are not implemented but reserved by Unicode standard.
2094
- */
2095
-
2096
- const lightFormatters = {
2097
- // Year
2098
- y(date, token) {
2099
- // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
2100
- // | Year | y | yy | yyy | yyyy | yyyyy |
2101
- // |----------|-------|----|-------|-------|-------|
2102
- // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
2103
- // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
2104
- // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
2105
- // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
2106
- // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
2107
-
2108
- const signedYear = date.getFullYear();
2109
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
2110
- const year = signedYear > 0 ? signedYear : 1 - signedYear;
2111
- return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
2112
- },
2113
-
2114
- // Month
2115
- M(date, token) {
2116
- const month = date.getMonth();
2117
- return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
2118
- },
2119
-
2120
- // Day of the month
2121
- d(date, token) {
2122
- return addLeadingZeros(date.getDate(), token.length);
2123
- },
2124
-
2125
- // AM or PM
2126
- a(date, token) {
2127
- const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
2128
-
2129
- switch (token) {
2130
- case "a":
2131
- case "aa":
2132
- return dayPeriodEnumValue.toUpperCase();
2133
- case "aaa":
2134
- return dayPeriodEnumValue;
2135
- case "aaaaa":
2136
- return dayPeriodEnumValue[0];
2137
- case "aaaa":
2138
- default:
2139
- return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
2140
- }
2141
- },
2142
-
2143
- // Hour [1-12]
2144
- h(date, token) {
2145
- return addLeadingZeros(date.getHours() % 12 || 12, token.length);
2146
- },
2147
-
2148
- // Hour [0-23]
2149
- H(date, token) {
2150
- return addLeadingZeros(date.getHours(), token.length);
2151
- },
2152
-
2153
- // Minute
2154
- m(date, token) {
2155
- return addLeadingZeros(date.getMinutes(), token.length);
2156
- },
2157
-
2158
- // Second
2159
- s(date, token) {
2160
- return addLeadingZeros(date.getSeconds(), token.length);
2161
- },
2162
-
2163
- // Fraction of second
2164
- S(date, token) {
2165
- const numberOfDigits = token.length;
2166
- const milliseconds = date.getMilliseconds();
2167
- const fractionalSeconds = Math.trunc(
2168
- milliseconds * Math.pow(10, numberOfDigits - 3),
2169
- );
2170
- return addLeadingZeros(fractionalSeconds, token.length);
2171
- },
2172
- };
2173
-
2174
- const dayPeriodEnum = {
2175
- am: "am",
2176
- pm: "pm",
2177
- midnight: "midnight",
2178
- noon: "noon",
2179
- morning: "morning",
2180
- afternoon: "afternoon",
2181
- evening: "evening",
2182
- night: "night",
2183
- };
2184
-
2185
- /*
2186
- * | | Unit | | Unit |
2187
- * |-----|--------------------------------|-----|--------------------------------|
2188
- * | a | AM, PM | A* | Milliseconds in day |
2189
- * | b | AM, PM, noon, midnight | B | Flexible day period |
2190
- * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
2191
- * | d | Day of month | D | Day of year |
2192
- * | e | Local day of week | E | Day of week |
2193
- * | f | | F* | Day of week in month |
2194
- * | g* | Modified Julian day | G | Era |
2195
- * | h | Hour [1-12] | H | Hour [0-23] |
2196
- * | i! | ISO day of week | I! | ISO week of year |
2197
- * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
2198
- * | k | Hour [1-24] | K | Hour [0-11] |
2199
- * | l* | (deprecated) | L | Stand-alone month |
2200
- * | m | Minute | M | Month |
2201
- * | n | | N | |
2202
- * | o! | Ordinal number modifier | O | Timezone (GMT) |
2203
- * | p! | Long localized time | P! | Long localized date |
2204
- * | q | Stand-alone quarter | Q | Quarter |
2205
- * | r* | Related Gregorian year | R! | ISO week-numbering year |
2206
- * | s | Second | S | Fraction of second |
2207
- * | t! | Seconds timestamp | T! | Milliseconds timestamp |
2208
- * | u | Extended year | U* | Cyclic year |
2209
- * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
2210
- * | w | Local week of year | W* | Week of month |
2211
- * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
2212
- * | y | Year (abs) | Y | Local week-numbering year |
2213
- * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
2214
- *
2215
- * Letters marked by * are not implemented but reserved by Unicode standard.
2216
- *
2217
- * Letters marked by ! are non-standard, but implemented by date-fns:
2218
- * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
2219
- * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
2220
- * i.e. 7 for Sunday, 1 for Monday, etc.
2221
- * - `I` is ISO week of year, as opposed to `w` which is local week of year.
2222
- * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
2223
- * `R` is supposed to be used in conjunction with `I` and `i`
2224
- * for universal ISO week-numbering date, whereas
2225
- * `Y` is supposed to be used in conjunction with `w` and `e`
2226
- * for week-numbering date specific to the locale.
2227
- * - `P` is long localized date format
2228
- * - `p` is long localized time format
2229
- */
2230
-
2231
- const formatters = {
2232
- // Era
2233
- G: function (date, token, localize) {
2234
- const era = date.getFullYear() > 0 ? 1 : 0;
2235
- switch (token) {
2236
- // AD, BC
2237
- case "G":
2238
- case "GG":
2239
- case "GGG":
2240
- return localize.era(era, { width: "abbreviated" });
2241
- // A, B
2242
- case "GGGGG":
2243
- return localize.era(era, { width: "narrow" });
2244
- // Anno Domini, Before Christ
2245
- case "GGGG":
2246
- default:
2247
- return localize.era(era, { width: "wide" });
2248
- }
2249
- },
2250
-
2251
- // Year
2252
- y: function (date, token, localize) {
2253
- // Ordinal number
2254
- if (token === "yo") {
2255
- const signedYear = date.getFullYear();
2256
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
2257
- const year = signedYear > 0 ? signedYear : 1 - signedYear;
2258
- return localize.ordinalNumber(year, { unit: "year" });
2259
- }
2260
-
2261
- return lightFormatters.y(date, token);
2262
- },
2263
-
2264
- // Local week-numbering year
2265
- Y: function (date, token, localize, options) {
2266
- const signedWeekYear = getWeekYear(date, options);
2267
- // Returns 1 for 1 BC (which is year 0 in JavaScript)
2268
- const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
2269
-
2270
- // Two digit year
2271
- if (token === "YY") {
2272
- const twoDigitYear = weekYear % 100;
2273
- return addLeadingZeros(twoDigitYear, 2);
2274
- }
2275
-
2276
- // Ordinal number
2277
- if (token === "Yo") {
2278
- return localize.ordinalNumber(weekYear, { unit: "year" });
2279
- }
2280
-
2281
- // Padding
2282
- return addLeadingZeros(weekYear, token.length);
2283
- },
2284
-
2285
- // ISO week-numbering year
2286
- R: function (date, token) {
2287
- const isoWeekYear = getISOWeekYear(date);
2288
-
2289
- // Padding
2290
- return addLeadingZeros(isoWeekYear, token.length);
2291
- },
2292
-
2293
- // Extended year. This is a single number designating the year of this calendar system.
2294
- // The main difference between `y` and `u` localizers are B.C. years:
2295
- // | Year | `y` | `u` |
2296
- // |------|-----|-----|
2297
- // | AC 1 | 1 | 1 |
2298
- // | BC 1 | 1 | 0 |
2299
- // | BC 2 | 2 | -1 |
2300
- // Also `yy` always returns the last two digits of a year,
2301
- // while `uu` pads single digit years to 2 characters and returns other years unchanged.
2302
- u: function (date, token) {
2303
- const year = date.getFullYear();
2304
- return addLeadingZeros(year, token.length);
2305
- },
2306
-
2307
- // Quarter
2308
- Q: function (date, token, localize) {
2309
- const quarter = Math.ceil((date.getMonth() + 1) / 3);
2310
- switch (token) {
2311
- // 1, 2, 3, 4
2312
- case "Q":
2313
- return String(quarter);
2314
- // 01, 02, 03, 04
2315
- case "QQ":
2316
- return addLeadingZeros(quarter, 2);
2317
- // 1st, 2nd, 3rd, 4th
2318
- case "Qo":
2319
- return localize.ordinalNumber(quarter, { unit: "quarter" });
2320
- // Q1, Q2, Q3, Q4
2321
- case "QQQ":
2322
- return localize.quarter(quarter, {
2323
- width: "abbreviated",
2324
- context: "formatting",
2325
- });
2326
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2327
- case "QQQQQ":
2328
- return localize.quarter(quarter, {
2329
- width: "narrow",
2330
- context: "formatting",
2331
- });
2332
- // 1st quarter, 2nd quarter, ...
2333
- case "QQQQ":
2334
- default:
2335
- return localize.quarter(quarter, {
2336
- width: "wide",
2337
- context: "formatting",
2338
- });
2339
- }
2340
- },
2341
-
2342
- // Stand-alone quarter
2343
- q: function (date, token, localize) {
2344
- const quarter = Math.ceil((date.getMonth() + 1) / 3);
2345
- switch (token) {
2346
- // 1, 2, 3, 4
2347
- case "q":
2348
- return String(quarter);
2349
- // 01, 02, 03, 04
2350
- case "qq":
2351
- return addLeadingZeros(quarter, 2);
2352
- // 1st, 2nd, 3rd, 4th
2353
- case "qo":
2354
- return localize.ordinalNumber(quarter, { unit: "quarter" });
2355
- // Q1, Q2, Q3, Q4
2356
- case "qqq":
2357
- return localize.quarter(quarter, {
2358
- width: "abbreviated",
2359
- context: "standalone",
2360
- });
2361
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2362
- case "qqqqq":
2363
- return localize.quarter(quarter, {
2364
- width: "narrow",
2365
- context: "standalone",
2366
- });
2367
- // 1st quarter, 2nd quarter, ...
2368
- case "qqqq":
2369
- default:
2370
- return localize.quarter(quarter, {
2371
- width: "wide",
2372
- context: "standalone",
2373
- });
2374
- }
2375
- },
2376
-
2377
- // Month
2378
- M: function (date, token, localize) {
2379
- const month = date.getMonth();
2380
- switch (token) {
2381
- case "M":
2382
- case "MM":
2383
- return lightFormatters.M(date, token);
2384
- // 1st, 2nd, ..., 12th
2385
- case "Mo":
2386
- return localize.ordinalNumber(month + 1, { unit: "month" });
2387
- // Jan, Feb, ..., Dec
2388
- case "MMM":
2389
- return localize.month(month, {
2390
- width: "abbreviated",
2391
- context: "formatting",
2392
- });
2393
- // J, F, ..., D
2394
- case "MMMMM":
2395
- return localize.month(month, {
2396
- width: "narrow",
2397
- context: "formatting",
2398
- });
2399
- // January, February, ..., December
2400
- case "MMMM":
2401
- default:
2402
- return localize.month(month, { width: "wide", context: "formatting" });
2403
- }
2404
- },
2405
-
2406
- // Stand-alone month
2407
- L: function (date, token, localize) {
2408
- const month = date.getMonth();
2409
- switch (token) {
2410
- // 1, 2, ..., 12
2411
- case "L":
2412
- return String(month + 1);
2413
- // 01, 02, ..., 12
2414
- case "LL":
2415
- return addLeadingZeros(month + 1, 2);
2416
- // 1st, 2nd, ..., 12th
2417
- case "Lo":
2418
- return localize.ordinalNumber(month + 1, { unit: "month" });
2419
- // Jan, Feb, ..., Dec
2420
- case "LLL":
2421
- return localize.month(month, {
2422
- width: "abbreviated",
2423
- context: "standalone",
2424
- });
2425
- // J, F, ..., D
2426
- case "LLLLL":
2427
- return localize.month(month, {
2428
- width: "narrow",
2429
- context: "standalone",
2430
- });
2431
- // January, February, ..., December
2432
- case "LLLL":
2433
- default:
2434
- return localize.month(month, { width: "wide", context: "standalone" });
2435
- }
2436
- },
2437
-
2438
- // Local week of year
2439
- w: function (date, token, localize, options) {
2440
- const week = getWeek(date, options);
2441
-
2442
- if (token === "wo") {
2443
- return localize.ordinalNumber(week, { unit: "week" });
2444
- }
2445
-
2446
- return addLeadingZeros(week, token.length);
2447
- },
2448
-
2449
- // ISO week of year
2450
- I: function (date, token, localize) {
2451
- const isoWeek = getISOWeek(date);
2452
-
2453
- if (token === "Io") {
2454
- return localize.ordinalNumber(isoWeek, { unit: "week" });
2455
- }
2456
-
2457
- return addLeadingZeros(isoWeek, token.length);
2458
- },
2459
-
2460
- // Day of the month
2461
- d: function (date, token, localize) {
2462
- if (token === "do") {
2463
- return localize.ordinalNumber(date.getDate(), { unit: "date" });
2464
- }
2465
-
2466
- return lightFormatters.d(date, token);
2467
- },
2468
-
2469
- // Day of year
2470
- D: function (date, token, localize) {
2471
- const dayOfYear = getDayOfYear(date);
2472
-
2473
- if (token === "Do") {
2474
- return localize.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
2475
- }
2476
-
2477
- return addLeadingZeros(dayOfYear, token.length);
2478
- },
2479
-
2480
- // Day of week
2481
- E: function (date, token, localize) {
2482
- const dayOfWeek = date.getDay();
2483
- switch (token) {
2484
- // Tue
2485
- case "E":
2486
- case "EE":
2487
- case "EEE":
2488
- return localize.day(dayOfWeek, {
2489
- width: "abbreviated",
2490
- context: "formatting",
2491
- });
2492
- // T
2493
- case "EEEEE":
2494
- return localize.day(dayOfWeek, {
2495
- width: "narrow",
2496
- context: "formatting",
2497
- });
2498
- // Tu
2499
- case "EEEEEE":
2500
- return localize.day(dayOfWeek, {
2501
- width: "short",
2502
- context: "formatting",
2503
- });
2504
- // Tuesday
2505
- case "EEEE":
2506
- default:
2507
- return localize.day(dayOfWeek, {
2508
- width: "wide",
2509
- context: "formatting",
2510
- });
2511
- }
2512
- },
2513
-
2514
- // Local day of week
2515
- e: function (date, token, localize, options) {
2516
- const dayOfWeek = date.getDay();
2517
- const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
2518
- switch (token) {
2519
- // Numerical value (Nth day of week with current locale or weekStartsOn)
2520
- case "e":
2521
- return String(localDayOfWeek);
2522
- // Padded numerical value
2523
- case "ee":
2524
- return addLeadingZeros(localDayOfWeek, 2);
2525
- // 1st, 2nd, ..., 7th
2526
- case "eo":
2527
- return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
2528
- case "eee":
2529
- return localize.day(dayOfWeek, {
2530
- width: "abbreviated",
2531
- context: "formatting",
2532
- });
2533
- // T
2534
- case "eeeee":
2535
- return localize.day(dayOfWeek, {
2536
- width: "narrow",
2537
- context: "formatting",
2538
- });
2539
- // Tu
2540
- case "eeeeee":
2541
- return localize.day(dayOfWeek, {
2542
- width: "short",
2543
- context: "formatting",
2544
- });
2545
- // Tuesday
2546
- case "eeee":
2547
- default:
2548
- return localize.day(dayOfWeek, {
2549
- width: "wide",
2550
- context: "formatting",
2551
- });
2552
- }
2553
- },
2554
-
2555
- // Stand-alone local day of week
2556
- c: function (date, token, localize, options) {
2557
- const dayOfWeek = date.getDay();
2558
- const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
2559
- switch (token) {
2560
- // Numerical value (same as in `e`)
2561
- case "c":
2562
- return String(localDayOfWeek);
2563
- // Padded numerical value
2564
- case "cc":
2565
- return addLeadingZeros(localDayOfWeek, token.length);
2566
- // 1st, 2nd, ..., 7th
2567
- case "co":
2568
- return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
2569
- case "ccc":
2570
- return localize.day(dayOfWeek, {
2571
- width: "abbreviated",
2572
- context: "standalone",
2573
- });
2574
- // T
2575
- case "ccccc":
2576
- return localize.day(dayOfWeek, {
2577
- width: "narrow",
2578
- context: "standalone",
2579
- });
2580
- // Tu
2581
- case "cccccc":
2582
- return localize.day(dayOfWeek, {
2583
- width: "short",
2584
- context: "standalone",
2585
- });
2586
- // Tuesday
2587
- case "cccc":
2588
- default:
2589
- return localize.day(dayOfWeek, {
2590
- width: "wide",
2591
- context: "standalone",
2592
- });
2593
- }
2594
- },
2595
-
2596
- // ISO day of week
2597
- i: function (date, token, localize) {
2598
- const dayOfWeek = date.getDay();
2599
- const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
2600
- switch (token) {
2601
- // 2
2602
- case "i":
2603
- return String(isoDayOfWeek);
2604
- // 02
2605
- case "ii":
2606
- return addLeadingZeros(isoDayOfWeek, token.length);
2607
- // 2nd
2608
- case "io":
2609
- return localize.ordinalNumber(isoDayOfWeek, { unit: "day" });
2610
- // Tue
2611
- case "iii":
2612
- return localize.day(dayOfWeek, {
2613
- width: "abbreviated",
2614
- context: "formatting",
2615
- });
2616
- // T
2617
- case "iiiii":
2618
- return localize.day(dayOfWeek, {
2619
- width: "narrow",
2620
- context: "formatting",
2621
- });
2622
- // Tu
2623
- case "iiiiii":
2624
- return localize.day(dayOfWeek, {
2625
- width: "short",
2626
- context: "formatting",
2627
- });
2628
- // Tuesday
2629
- case "iiii":
2630
- default:
2631
- return localize.day(dayOfWeek, {
2632
- width: "wide",
2633
- context: "formatting",
2634
- });
2635
- }
2636
- },
2637
-
2638
- // AM or PM
2639
- a: function (date, token, localize) {
2640
- const hours = date.getHours();
2641
- const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
2642
-
2643
- switch (token) {
2644
- case "a":
2645
- case "aa":
2646
- return localize.dayPeriod(dayPeriodEnumValue, {
2647
- width: "abbreviated",
2648
- context: "formatting",
2649
- });
2650
- case "aaa":
2651
- return localize
2652
- .dayPeriod(dayPeriodEnumValue, {
2653
- width: "abbreviated",
2654
- context: "formatting",
2655
- })
2656
- .toLowerCase();
2657
- case "aaaaa":
2658
- return localize.dayPeriod(dayPeriodEnumValue, {
2659
- width: "narrow",
2660
- context: "formatting",
2661
- });
2662
- case "aaaa":
2663
- default:
2664
- return localize.dayPeriod(dayPeriodEnumValue, {
2665
- width: "wide",
2666
- context: "formatting",
2667
- });
2668
- }
2669
- },
2670
-
2671
- // AM, PM, midnight, noon
2672
- b: function (date, token, localize) {
2673
- const hours = date.getHours();
2674
- let dayPeriodEnumValue;
2675
- if (hours === 12) {
2676
- dayPeriodEnumValue = dayPeriodEnum.noon;
2677
- } else if (hours === 0) {
2678
- dayPeriodEnumValue = dayPeriodEnum.midnight;
2679
- } else {
2680
- dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
2681
- }
2682
-
2683
- switch (token) {
2684
- case "b":
2685
- case "bb":
2686
- return localize.dayPeriod(dayPeriodEnumValue, {
2687
- width: "abbreviated",
2688
- context: "formatting",
2689
- });
2690
- case "bbb":
2691
- return localize
2692
- .dayPeriod(dayPeriodEnumValue, {
2693
- width: "abbreviated",
2694
- context: "formatting",
2695
- })
2696
- .toLowerCase();
2697
- case "bbbbb":
2698
- return localize.dayPeriod(dayPeriodEnumValue, {
2699
- width: "narrow",
2700
- context: "formatting",
2701
- });
2702
- case "bbbb":
2703
- default:
2704
- return localize.dayPeriod(dayPeriodEnumValue, {
2705
- width: "wide",
2706
- context: "formatting",
2707
- });
2708
- }
2709
- },
2710
-
2711
- // in the morning, in the afternoon, in the evening, at night
2712
- B: function (date, token, localize) {
2713
- const hours = date.getHours();
2714
- let dayPeriodEnumValue;
2715
- if (hours >= 17) {
2716
- dayPeriodEnumValue = dayPeriodEnum.evening;
2717
- } else if (hours >= 12) {
2718
- dayPeriodEnumValue = dayPeriodEnum.afternoon;
2719
- } else if (hours >= 4) {
2720
- dayPeriodEnumValue = dayPeriodEnum.morning;
2721
- } else {
2722
- dayPeriodEnumValue = dayPeriodEnum.night;
2723
- }
2724
-
2725
- switch (token) {
2726
- case "B":
2727
- case "BB":
2728
- case "BBB":
2729
- return localize.dayPeriod(dayPeriodEnumValue, {
2730
- width: "abbreviated",
2731
- context: "formatting",
2732
- });
2733
- case "BBBBB":
2734
- return localize.dayPeriod(dayPeriodEnumValue, {
2735
- width: "narrow",
2736
- context: "formatting",
2737
- });
2738
- case "BBBB":
2739
- default:
2740
- return localize.dayPeriod(dayPeriodEnumValue, {
2741
- width: "wide",
2742
- context: "formatting",
2743
- });
2744
- }
2745
- },
2746
-
2747
- // Hour [1-12]
2748
- h: function (date, token, localize) {
2749
- if (token === "ho") {
2750
- let hours = date.getHours() % 12;
2751
- if (hours === 0) hours = 12;
2752
- return localize.ordinalNumber(hours, { unit: "hour" });
2753
- }
2754
-
2755
- return lightFormatters.h(date, token);
2756
- },
2757
-
2758
- // Hour [0-23]
2759
- H: function (date, token, localize) {
2760
- if (token === "Ho") {
2761
- return localize.ordinalNumber(date.getHours(), { unit: "hour" });
2762
- }
2763
-
2764
- return lightFormatters.H(date, token);
2765
- },
2766
-
2767
- // Hour [0-11]
2768
- K: function (date, token, localize) {
2769
- const hours = date.getHours() % 12;
2770
-
2771
- if (token === "Ko") {
2772
- return localize.ordinalNumber(hours, { unit: "hour" });
2773
- }
2774
-
2775
- return addLeadingZeros(hours, token.length);
2776
- },
2777
-
2778
- // Hour [1-24]
2779
- k: function (date, token, localize) {
2780
- let hours = date.getHours();
2781
- if (hours === 0) hours = 24;
2782
-
2783
- if (token === "ko") {
2784
- return localize.ordinalNumber(hours, { unit: "hour" });
2785
- }
2786
-
2787
- return addLeadingZeros(hours, token.length);
2788
- },
2789
-
2790
- // Minute
2791
- m: function (date, token, localize) {
2792
- if (token === "mo") {
2793
- return localize.ordinalNumber(date.getMinutes(), { unit: "minute" });
2794
- }
2795
-
2796
- return lightFormatters.m(date, token);
2797
- },
2798
-
2799
- // Second
2800
- s: function (date, token, localize) {
2801
- if (token === "so") {
2802
- return localize.ordinalNumber(date.getSeconds(), { unit: "second" });
2803
- }
2804
-
2805
- return lightFormatters.s(date, token);
2806
- },
2807
-
2808
- // Fraction of second
2809
- S: function (date, token) {
2810
- return lightFormatters.S(date, token);
2811
- },
2812
-
2813
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
2814
- X: function (date, token, _localize) {
2815
- const timezoneOffset = date.getTimezoneOffset();
2816
-
2817
- if (timezoneOffset === 0) {
2818
- return "Z";
2819
- }
2820
-
2821
- switch (token) {
2822
- // Hours and optional minutes
2823
- case "X":
2824
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
2825
-
2826
- // Hours, minutes and optional seconds without `:` delimiter
2827
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2828
- // so this token always has the same output as `XX`
2829
- case "XXXX":
2830
- case "XX": // Hours and minutes without `:` delimiter
2831
- return formatTimezone(timezoneOffset);
2832
-
2833
- // Hours, minutes and optional seconds with `:` delimiter
2834
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2835
- // so this token always has the same output as `XXX`
2836
- case "XXXXX":
2837
- case "XXX": // Hours and minutes with `:` delimiter
2838
- default:
2839
- return formatTimezone(timezoneOffset, ":");
2840
- }
2841
- },
2842
-
2843
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
2844
- x: function (date, token, _localize) {
2845
- const timezoneOffset = date.getTimezoneOffset();
2846
-
2847
- switch (token) {
2848
- // Hours and optional minutes
2849
- case "x":
2850
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
2851
-
2852
- // Hours, minutes and optional seconds without `:` delimiter
2853
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2854
- // so this token always has the same output as `xx`
2855
- case "xxxx":
2856
- case "xx": // Hours and minutes without `:` delimiter
2857
- return formatTimezone(timezoneOffset);
2858
-
2859
- // Hours, minutes and optional seconds with `:` delimiter
2860
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
2861
- // so this token always has the same output as `xxx`
2862
- case "xxxxx":
2863
- case "xxx": // Hours and minutes with `:` delimiter
2864
- default:
2865
- return formatTimezone(timezoneOffset, ":");
2866
- }
2867
- },
2868
-
2869
- // Timezone (GMT)
2870
- O: function (date, token, _localize) {
2871
- const timezoneOffset = date.getTimezoneOffset();
2872
-
2873
- switch (token) {
2874
- // Short
2875
- case "O":
2876
- case "OO":
2877
- case "OOO":
2878
- return "GMT" + formatTimezoneShort(timezoneOffset, ":");
2879
- // Long
2880
- case "OOOO":
2881
- default:
2882
- return "GMT" + formatTimezone(timezoneOffset, ":");
2883
- }
2884
- },
2885
-
2886
- // Timezone (specific non-location)
2887
- z: function (date, token, _localize) {
2888
- const timezoneOffset = date.getTimezoneOffset();
2889
-
2890
- switch (token) {
2891
- // Short
2892
- case "z":
2893
- case "zz":
2894
- case "zzz":
2895
- return "GMT" + formatTimezoneShort(timezoneOffset, ":");
2896
- // Long
2897
- case "zzzz":
2898
- default:
2899
- return "GMT" + formatTimezone(timezoneOffset, ":");
2900
- }
2901
- },
2902
-
2903
- // Seconds timestamp
2904
- t: function (date, token, _localize) {
2905
- const timestamp = Math.trunc(+date / 1000);
2906
- return addLeadingZeros(timestamp, token.length);
2907
- },
2908
-
2909
- // Milliseconds timestamp
2910
- T: function (date, token, _localize) {
2911
- return addLeadingZeros(+date, token.length);
2912
- },
2913
- };
2914
-
2915
- function formatTimezoneShort(offset, delimiter = "") {
2916
- const sign = offset > 0 ? "-" : "+";
2917
- const absOffset = Math.abs(offset);
2918
- const hours = Math.trunc(absOffset / 60);
2919
- const minutes = absOffset % 60;
2920
- if (minutes === 0) {
2921
- return sign + String(hours);
2922
- }
2923
- return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
2924
- }
2925
-
2926
- function formatTimezoneWithOptionalMinutes(offset, delimiter) {
2927
- if (offset % 60 === 0) {
2928
- const sign = offset > 0 ? "-" : "+";
2929
- return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
2930
- }
2931
- return formatTimezone(offset, delimiter);
2932
- }
2933
-
2934
- function formatTimezone(offset, delimiter = "") {
2935
- const sign = offset > 0 ? "-" : "+";
2936
- const absOffset = Math.abs(offset);
2937
- const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
2938
- const minutes = addLeadingZeros(absOffset % 60, 2);
2939
- return sign + hours + delimiter + minutes;
2940
- }
2941
-
2942
- const dateLongFormatter = (pattern, formatLong) => {
2943
- switch (pattern) {
2944
- case "P":
2945
- return formatLong.date({ width: "short" });
2946
- case "PP":
2947
- return formatLong.date({ width: "medium" });
2948
- case "PPP":
2949
- return formatLong.date({ width: "long" });
2950
- case "PPPP":
2951
- default:
2952
- return formatLong.date({ width: "full" });
2953
- }
2954
- };
2955
-
2956
- const timeLongFormatter = (pattern, formatLong) => {
2957
- switch (pattern) {
2958
- case "p":
2959
- return formatLong.time({ width: "short" });
2960
- case "pp":
2961
- return formatLong.time({ width: "medium" });
2962
- case "ppp":
2963
- return formatLong.time({ width: "long" });
2964
- case "pppp":
2965
- default:
2966
- return formatLong.time({ width: "full" });
2967
- }
2968
- };
2969
-
2970
- const dateTimeLongFormatter = (pattern, formatLong) => {
2971
- const matchResult = pattern.match(/(P+)(p+)?/) || [];
2972
- const datePattern = matchResult[1];
2973
- const timePattern = matchResult[2];
2974
-
2975
- if (!timePattern) {
2976
- return dateLongFormatter(pattern, formatLong);
2977
- }
2978
-
2979
- let dateTimeFormat;
2980
-
2981
- switch (datePattern) {
2982
- case "P":
2983
- dateTimeFormat = formatLong.dateTime({ width: "short" });
2984
- break;
2985
- case "PP":
2986
- dateTimeFormat = formatLong.dateTime({ width: "medium" });
2987
- break;
2988
- case "PPP":
2989
- dateTimeFormat = formatLong.dateTime({ width: "long" });
2990
- break;
2991
- case "PPPP":
2992
- default:
2993
- dateTimeFormat = formatLong.dateTime({ width: "full" });
2994
- break;
2995
- }
2996
-
2997
- return dateTimeFormat
2998
- .replace("{{date}}", dateLongFormatter(datePattern, formatLong))
2999
- .replace("{{time}}", timeLongFormatter(timePattern, formatLong));
3000
- };
3001
-
3002
- const longFormatters = {
3003
- p: timeLongFormatter,
3004
- P: dateTimeLongFormatter,
3005
- };
3006
-
3007
- const dayOfYearTokenRE = /^D+$/;
3008
- const weekYearTokenRE = /^Y+$/;
3009
-
3010
- const throwTokens = ["D", "DD", "YY", "YYYY"];
3011
-
3012
- function isProtectedDayOfYearToken(token) {
3013
- return dayOfYearTokenRE.test(token);
3014
- }
3015
-
3016
- function isProtectedWeekYearToken(token) {
3017
- return weekYearTokenRE.test(token);
3018
- }
3019
-
3020
- function warnOrThrowProtectedError(token, format, input) {
3021
- const _message = message(token, format, input);
3022
- console.warn(_message);
3023
- if (throwTokens.includes(token)) throw new RangeError(_message);
3024
- }
3025
-
3026
- function message(token, format, input) {
3027
- const subject = token[0] === "Y" ? "years" : "days of the month";
3028
- 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`;
3029
- }
3030
-
3031
- // This RegExp consists of three parts separated by `|`:
3032
- // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
3033
- // (one of the certain letters followed by `o`)
3034
- // - (\w)\1* matches any sequences of the same letter
3035
- // - '' matches two quote characters in a row
3036
- // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
3037
- // except a single quote symbol, which ends the sequence.
3038
- // Two quote characters do not end the sequence.
3039
- // If there is no matching single quote
3040
- // then the sequence will continue until the end of the string.
3041
- // - . matches any single character unmatched by previous parts of the RegExps
3042
- const formattingTokensRegExp =
3043
- /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
3044
-
3045
- // This RegExp catches symbols escaped by quotes, and also
3046
- // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
3047
- const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
3048
-
3049
- const escapedStringRegExp = /^'([^]*?)'?$/;
3050
- const doubleQuoteRegExp = /''/g;
3051
- const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
3052
-
3053
- /**
3054
- * The {@link format} function options.
3055
- */
3056
-
3057
- /**
3058
- * @name format
3059
- * @alias formatDate
3060
- * @category Common Helpers
3061
- * @summary Format the date.
3062
- *
3063
- * @description
3064
- * Return the formatted date string in the given format. The result may vary by locale.
3065
- *
3066
- * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
3067
- * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3068
- *
3069
- * The characters wrapped between two single quotes characters (') are escaped.
3070
- * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
3071
- * (see the last example)
3072
- *
3073
- * Format of the string is based on Unicode Technical Standard #35:
3074
- * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
3075
- * with a few additions (see note 7 below the table).
3076
- *
3077
- * Accepted patterns:
3078
- * | Unit | Pattern | Result examples | Notes |
3079
- * |---------------------------------|---------|-----------------------------------|-------|
3080
- * | Era | G..GGG | AD, BC | |
3081
- * | | GGGG | Anno Domini, Before Christ | 2 |
3082
- * | | GGGGG | A, B | |
3083
- * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
3084
- * | | yo | 44th, 1st, 0th, 17th | 5,7 |
3085
- * | | yy | 44, 01, 00, 17 | 5 |
3086
- * | | yyy | 044, 001, 1900, 2017 | 5 |
3087
- * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
3088
- * | | yyyyy | ... | 3,5 |
3089
- * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
3090
- * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
3091
- * | | YY | 44, 01, 00, 17 | 5,8 |
3092
- * | | YYY | 044, 001, 1900, 2017 | 5 |
3093
- * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
3094
- * | | YYYYY | ... | 3,5 |
3095
- * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
3096
- * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
3097
- * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
3098
- * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
3099
- * | | RRRRR | ... | 3,5,7 |
3100
- * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
3101
- * | | uu | -43, 01, 1900, 2017 | 5 |
3102
- * | | uuu | -043, 001, 1900, 2017 | 5 |
3103
- * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
3104
- * | | uuuuu | ... | 3,5 |
3105
- * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
3106
- * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
3107
- * | | QQ | 01, 02, 03, 04 | |
3108
- * | | QQQ | Q1, Q2, Q3, Q4 | |
3109
- * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
3110
- * | | QQQQQ | 1, 2, 3, 4 | 4 |
3111
- * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
3112
- * | | qo | 1st, 2nd, 3rd, 4th | 7 |
3113
- * | | qq | 01, 02, 03, 04 | |
3114
- * | | qqq | Q1, Q2, Q3, Q4 | |
3115
- * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
3116
- * | | qqqqq | 1, 2, 3, 4 | 4 |
3117
- * | Month (formatting) | M | 1, 2, ..., 12 | |
3118
- * | | Mo | 1st, 2nd, ..., 12th | 7 |
3119
- * | | MM | 01, 02, ..., 12 | |
3120
- * | | MMM | Jan, Feb, ..., Dec | |
3121
- * | | MMMM | January, February, ..., December | 2 |
3122
- * | | MMMMM | J, F, ..., D | |
3123
- * | Month (stand-alone) | L | 1, 2, ..., 12 | |
3124
- * | | Lo | 1st, 2nd, ..., 12th | 7 |
3125
- * | | LL | 01, 02, ..., 12 | |
3126
- * | | LLL | Jan, Feb, ..., Dec | |
3127
- * | | LLLL | January, February, ..., December | 2 |
3128
- * | | LLLLL | J, F, ..., D | |
3129
- * | Local week of year | w | 1, 2, ..., 53 | |
3130
- * | | wo | 1st, 2nd, ..., 53th | 7 |
3131
- * | | ww | 01, 02, ..., 53 | |
3132
- * | ISO week of year | I | 1, 2, ..., 53 | 7 |
3133
- * | | Io | 1st, 2nd, ..., 53th | 7 |
3134
- * | | II | 01, 02, ..., 53 | 7 |
3135
- * | Day of month | d | 1, 2, ..., 31 | |
3136
- * | | do | 1st, 2nd, ..., 31st | 7 |
3137
- * | | dd | 01, 02, ..., 31 | |
3138
- * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
3139
- * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
3140
- * | | DD | 01, 02, ..., 365, 366 | 9 |
3141
- * | | DDD | 001, 002, ..., 365, 366 | |
3142
- * | | DDDD | ... | 3 |
3143
- * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
3144
- * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
3145
- * | | EEEEE | M, T, W, T, F, S, S | |
3146
- * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
3147
- * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
3148
- * | | io | 1st, 2nd, ..., 7th | 7 |
3149
- * | | ii | 01, 02, ..., 07 | 7 |
3150
- * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
3151
- * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
3152
- * | | iiiii | M, T, W, T, F, S, S | 7 |
3153
- * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
3154
- * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
3155
- * | | eo | 2nd, 3rd, ..., 1st | 7 |
3156
- * | | ee | 02, 03, ..., 01 | |
3157
- * | | eee | Mon, Tue, Wed, ..., Sun | |
3158
- * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
3159
- * | | eeeee | M, T, W, T, F, S, S | |
3160
- * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
3161
- * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
3162
- * | | co | 2nd, 3rd, ..., 1st | 7 |
3163
- * | | cc | 02, 03, ..., 01 | |
3164
- * | | ccc | Mon, Tue, Wed, ..., Sun | |
3165
- * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
3166
- * | | ccccc | M, T, W, T, F, S, S | |
3167
- * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
3168
- * | AM, PM | a..aa | AM, PM | |
3169
- * | | aaa | am, pm | |
3170
- * | | aaaa | a.m., p.m. | 2 |
3171
- * | | aaaaa | a, p | |
3172
- * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
3173
- * | | bbb | am, pm, noon, midnight | |
3174
- * | | bbbb | a.m., p.m., noon, midnight | 2 |
3175
- * | | bbbbb | a, p, n, mi | |
3176
- * | Flexible day period | B..BBB | at night, in the morning, ... | |
3177
- * | | BBBB | at night, in the morning, ... | 2 |
3178
- * | | BBBBB | at night, in the morning, ... | |
3179
- * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
3180
- * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
3181
- * | | hh | 01, 02, ..., 11, 12 | |
3182
- * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
3183
- * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
3184
- * | | HH | 00, 01, 02, ..., 23 | |
3185
- * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
3186
- * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
3187
- * | | KK | 01, 02, ..., 11, 00 | |
3188
- * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
3189
- * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
3190
- * | | kk | 24, 01, 02, ..., 23 | |
3191
- * | Minute | m | 0, 1, ..., 59 | |
3192
- * | | mo | 0th, 1st, ..., 59th | 7 |
3193
- * | | mm | 00, 01, ..., 59 | |
3194
- * | Second | s | 0, 1, ..., 59 | |
3195
- * | | so | 0th, 1st, ..., 59th | 7 |
3196
- * | | ss | 00, 01, ..., 59 | |
3197
- * | Fraction of second | S | 0, 1, ..., 9 | |
3198
- * | | SS | 00, 01, ..., 99 | |
3199
- * | | SSS | 000, 001, ..., 999 | |
3200
- * | | SSSS | ... | 3 |
3201
- * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
3202
- * | | XX | -0800, +0530, Z | |
3203
- * | | XXX | -08:00, +05:30, Z | |
3204
- * | | XXXX | -0800, +0530, Z, +123456 | 2 |
3205
- * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
3206
- * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
3207
- * | | xx | -0800, +0530, +0000 | |
3208
- * | | xxx | -08:00, +05:30, +00:00 | 2 |
3209
- * | | xxxx | -0800, +0530, +0000, +123456 | |
3210
- * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
3211
- * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
3212
- * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
3213
- * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
3214
- * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
3215
- * | Seconds timestamp | t | 512969520 | 7 |
3216
- * | | tt | ... | 3,7 |
3217
- * | Milliseconds timestamp | T | 512969520900 | 7 |
3218
- * | | TT | ... | 3,7 |
3219
- * | Long localized date | P | 04/29/1453 | 7 |
3220
- * | | PP | Apr 29, 1453 | 7 |
3221
- * | | PPP | April 29th, 1453 | 7 |
3222
- * | | PPPP | Friday, April 29th, 1453 | 2,7 |
3223
- * | Long localized time | p | 12:00 AM | 7 |
3224
- * | | pp | 12:00:00 AM | 7 |
3225
- * | | ppp | 12:00:00 AM GMT+2 | 7 |
3226
- * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
3227
- * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
3228
- * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
3229
- * | | PPPppp | April 29th, 1453 at ... | 7 |
3230
- * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
3231
- * Notes:
3232
- * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
3233
- * are the same as "stand-alone" units, but are different in some languages.
3234
- * "Formatting" units are declined according to the rules of the language
3235
- * in the context of a date. "Stand-alone" units are always nominative singular:
3236
- *
3237
- * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
3238
- *
3239
- * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
3240
- *
3241
- * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
3242
- * the single quote characters (see below).
3243
- * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
3244
- * the output will be the same as default pattern for this unit, usually
3245
- * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
3246
- * are marked with "2" in the last column of the table.
3247
- *
3248
- * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
3249
- *
3250
- * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
3251
- *
3252
- * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
3253
- *
3254
- * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
3255
- *
3256
- * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
3257
- *
3258
- * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
3259
- * The output will be padded with zeros to match the length of the pattern.
3260
- *
3261
- * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
3262
- *
3263
- * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
3264
- * These tokens represent the shortest form of the quarter.
3265
- *
3266
- * 5. The main difference between `y` and `u` patterns are B.C. years:
3267
- *
3268
- * | Year | `y` | `u` |
3269
- * |------|-----|-----|
3270
- * | AC 1 | 1 | 1 |
3271
- * | BC 1 | 1 | 0 |
3272
- * | BC 2 | 2 | -1 |
3273
- *
3274
- * Also `yy` always returns the last two digits of a year,
3275
- * while `uu` pads single digit years to 2 characters and returns other years unchanged:
3276
- *
3277
- * | Year | `yy` | `uu` |
3278
- * |------|------|------|
3279
- * | 1 | 01 | 01 |
3280
- * | 14 | 14 | 14 |
3281
- * | 376 | 76 | 376 |
3282
- * | 1453 | 53 | 1453 |
3283
- *
3284
- * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
3285
- * except local week-numbering years are dependent on `options.weekStartsOn`
3286
- * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear)
3287
- * and [getWeekYear](https://date-fns.org/docs/getWeekYear)).
3288
- *
3289
- * 6. Specific non-location timezones are currently unavailable in `date-fns`,
3290
- * so right now these tokens fall back to GMT timezones.
3291
- *
3292
- * 7. These patterns are not in the Unicode Technical Standard #35:
3293
- * - `i`: ISO day of week
3294
- * - `I`: ISO week of year
3295
- * - `R`: ISO week-numbering year
3296
- * - `t`: seconds timestamp
3297
- * - `T`: milliseconds timestamp
3298
- * - `o`: ordinal number modifier
3299
- * - `P`: long localized date
3300
- * - `p`: long localized time
3301
- *
3302
- * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
3303
- * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3304
- *
3305
- * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
3306
- * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
3307
- *
3308
- * @param date - The original date
3309
- * @param format - The string of tokens
3310
- * @param options - An object with options
3311
- *
3312
- * @returns The formatted date string
3313
- *
3314
- * @throws `date` must not be Invalid Date
3315
- * @throws `options.locale` must contain `localize` property
3316
- * @throws `options.locale` must contain `formatLong` property
3317
- * @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
3318
- * @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
3319
- * @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
3320
- * @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
3321
- * @throws format string contains an unescaped latin alphabet character
3322
- *
3323
- * @example
3324
- * // Represent 11 February 2014 in middle-endian format:
3325
- * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
3326
- * //=> '02/11/2014'
3327
- *
3328
- * @example
3329
- * // Represent 2 July 2014 in Esperanto:
3330
- * import { eoLocale } from 'date-fns/locale/eo'
3331
- * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
3332
- * locale: eoLocale
3333
- * })
3334
- * //=> '2-a de julio 2014'
3335
- *
3336
- * @example
3337
- * // Escape string by single quote characters:
3338
- * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
3339
- * //=> "3 o'clock"
3340
- */
3341
- function format(date, formatStr, options) {
3342
- const defaultOptions = getDefaultOptions();
3343
- const locale = options?.locale ?? defaultOptions.locale ?? enUS;
3344
-
3345
- const firstWeekContainsDate =
3346
- options?.firstWeekContainsDate ??
3347
- options?.locale?.options?.firstWeekContainsDate ??
3348
- defaultOptions.firstWeekContainsDate ??
3349
- defaultOptions.locale?.options?.firstWeekContainsDate ??
3350
- 1;
3351
-
3352
- const weekStartsOn =
3353
- options?.weekStartsOn ??
3354
- options?.locale?.options?.weekStartsOn ??
3355
- defaultOptions.weekStartsOn ??
3356
- defaultOptions.locale?.options?.weekStartsOn ??
3357
- 0;
3358
-
3359
- const originalDate = toDate(date, options?.in);
3360
-
3361
- if (!isValid(originalDate)) {
3362
- throw new RangeError("Invalid time value");
3363
- }
3364
-
3365
- let parts = formatStr
3366
- .match(longFormattingTokensRegExp)
3367
- .map((substring) => {
3368
- const firstCharacter = substring[0];
3369
- if (firstCharacter === "p" || firstCharacter === "P") {
3370
- const longFormatter = longFormatters[firstCharacter];
3371
- return longFormatter(substring, locale.formatLong);
3372
- }
3373
- return substring;
3374
- })
3375
- .join("")
3376
- .match(formattingTokensRegExp)
3377
- .map((substring) => {
3378
- // Replace two single quote characters with one single quote character
3379
- if (substring === "''") {
3380
- return { isToken: false, value: "'" };
3381
- }
3382
-
3383
- const firstCharacter = substring[0];
3384
- if (firstCharacter === "'") {
3385
- return { isToken: false, value: cleanEscapedString(substring) };
3386
- }
3387
-
3388
- if (formatters[firstCharacter]) {
3389
- return { isToken: true, value: substring };
3390
- }
3391
-
3392
- if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
3393
- throw new RangeError(
3394
- "Format string contains an unescaped latin alphabet character `" +
3395
- firstCharacter +
3396
- "`",
3397
- );
3398
- }
3399
-
3400
- return { isToken: false, value: substring };
3401
- });
3402
-
3403
- // invoke localize preprocessor (only for french locales at the moment)
3404
- if (locale.localize.preprocessor) {
3405
- parts = locale.localize.preprocessor(originalDate, parts);
3406
- }
3407
-
3408
- const formatterOptions = {
3409
- firstWeekContainsDate,
3410
- weekStartsOn,
3411
- locale,
3412
- };
3413
-
3414
- return parts
3415
- .map((part) => {
3416
- if (!part.isToken) return part.value;
3417
-
3418
- const token = part.value;
3419
-
3420
- if (
3421
- (!options?.useAdditionalWeekYearTokens &&
3422
- isProtectedWeekYearToken(token)) ||
3423
- (!options?.useAdditionalDayOfYearTokens &&
3424
- isProtectedDayOfYearToken(token))
3425
- ) {
3426
- warnOrThrowProtectedError(token, formatStr, String(date));
3427
- }
3428
-
3429
- const formatter = formatters[token[0]];
3430
- return formatter(originalDate, token, locale.localize, formatterOptions);
3431
- })
3432
- .join("");
3433
- }
3434
-
3435
- function cleanEscapedString(input) {
3436
- const matched = input.match(escapedStringRegExp);
3437
-
3438
- if (!matched) {
3439
- return input;
3440
- }
3441
-
3442
- return matched[1].replace(doubleQuoteRegExp, "'");
3443
- }
3444
-
3445
- const formatDistanceLocale = {
3446
- lessThanXSeconds: {
3447
- one: "mindre än en sekund",
3448
- other: "mindre än {{count}} sekunder",
3449
- },
3450
-
3451
- xSeconds: {
3452
- one: "en sekund",
3453
- other: "{{count}} sekunder",
3454
- },
3455
-
3456
- halfAMinute: "en halv minut",
3457
-
3458
- lessThanXMinutes: {
3459
- one: "mindre än en minut",
3460
- other: "mindre än {{count}} minuter",
3461
- },
3462
-
3463
- xMinutes: {
3464
- one: "en minut",
3465
- other: "{{count}} minuter",
3466
- },
3467
-
3468
- aboutXHours: {
3469
- one: "ungefär en timme",
3470
- other: "ungefär {{count}} timmar",
3471
- },
3472
-
3473
- xHours: {
3474
- one: "en timme",
3475
- other: "{{count}} timmar",
3476
- },
3477
-
3478
- xDays: {
3479
- one: "en dag",
3480
- other: "{{count}} dagar",
3481
- },
3482
-
3483
- aboutXWeeks: {
3484
- one: "ungefär en vecka",
3485
- other: "ungefär {{count}} veckor",
3486
- },
3487
-
3488
- xWeeks: {
3489
- one: "en vecka",
3490
- other: "{{count}} veckor",
3491
- },
3492
-
3493
- aboutXMonths: {
3494
- one: "ungefär en månad",
3495
- other: "ungefär {{count}} månader",
3496
- },
3497
-
3498
- xMonths: {
3499
- one: "en månad",
3500
- other: "{{count}} månader",
3501
- },
3502
-
3503
- aboutXYears: {
3504
- one: "ungefär ett år",
3505
- other: "ungefär {{count}} år",
3506
- },
3507
-
3508
- xYears: {
3509
- one: "ett år",
3510
- other: "{{count}} år",
3511
- },
3512
-
3513
- overXYears: {
3514
- one: "över ett år",
3515
- other: "över {{count}} år",
3516
- },
3517
-
3518
- almostXYears: {
3519
- one: "nästan ett år",
3520
- other: "nästan {{count}} år",
3521
- },
3522
- };
3523
-
3524
- const wordMapping = [
3525
- "noll",
3526
- "en",
3527
- "två",
3528
- "tre",
3529
- "fyra",
3530
- "fem",
3531
- "sex",
3532
- "sju",
3533
- "åtta",
3534
- "nio",
3535
- "tio",
3536
- "elva",
3537
- "tolv",
3538
- ];
3539
-
3540
- const formatDistance = (token, count, options) => {
3541
- let result;
3542
-
3543
- const tokenValue = formatDistanceLocale[token];
3544
- if (typeof tokenValue === "string") {
3545
- result = tokenValue;
3546
- } else if (count === 1) {
3547
- result = tokenValue.one;
3548
- } else {
3549
- result = tokenValue.other.replace(
3550
- "{{count}}",
3551
- count < 13 ? wordMapping[count] : String(count),
3552
- );
3553
- }
3554
-
3555
- if (options?.addSuffix) {
3556
- if (options.comparison && options.comparison > 0) {
3557
- return "om " + result;
3558
- } else {
3559
- return result + " sedan";
3560
- }
3561
- }
3562
-
3563
- return result;
3564
- };
3565
-
3566
- const dateFormats = {
3567
- full: "EEEE d MMMM y",
3568
- long: "d MMMM y",
3569
- medium: "d MMM y",
3570
- short: "y-MM-dd",
3571
- };
3572
-
3573
- const timeFormats = {
3574
- full: "'kl'. HH:mm:ss zzzz",
3575
- long: "HH:mm:ss z",
3576
- medium: "HH:mm:ss",
3577
- short: "HH:mm",
3578
- };
3579
-
3580
- const dateTimeFormats = {
3581
- full: "{{date}} 'kl.' {{time}}",
3582
- long: "{{date}} 'kl.' {{time}}",
3583
- medium: "{{date}} {{time}}",
3584
- short: "{{date}} {{time}}",
3585
- };
3586
-
3587
- const formatLong = {
3588
- date: buildFormatLongFn({
3589
- formats: dateFormats,
3590
- defaultWidth: "full",
3591
- }),
3592
-
3593
- time: buildFormatLongFn({
3594
- formats: timeFormats,
3595
- defaultWidth: "full",
3596
- }),
3597
-
3598
- dateTime: buildFormatLongFn({
3599
- formats: dateTimeFormats,
3600
- defaultWidth: "full",
3601
- }),
3602
- };
3603
-
3604
- const formatRelativeLocale = {
3605
- lastWeek: "'i' EEEE's kl.' p",
3606
- yesterday: "'igår kl.' p",
3607
- today: "'idag kl.' p",
3608
- tomorrow: "'imorgon kl.' p",
3609
- nextWeek: "EEEE 'kl.' p",
3610
- other: "P",
3611
- };
3612
-
3613
- const formatRelative = (token, _date, _baseDate, _options) =>
3614
- formatRelativeLocale[token];
3615
-
3616
- const eraValues = {
3617
- narrow: ["f.Kr.", "e.Kr."],
3618
- abbreviated: ["f.Kr.", "e.Kr."],
3619
- wide: ["före Kristus", "efter Kristus"],
3620
- };
3621
-
3622
- const quarterValues = {
3623
- narrow: ["1", "2", "3", "4"],
3624
- abbreviated: ["Q1", "Q2", "Q3", "Q4"],
3625
- wide: ["1:a kvartalet", "2:a kvartalet", "3:e kvartalet", "4:e kvartalet"],
3626
- };
3627
-
3628
- const monthValues = {
3629
- narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
3630
- abbreviated: [
3631
- "jan.",
3632
- "feb.",
3633
- "mars",
3634
- "apr.",
3635
- "maj",
3636
- "juni",
3637
- "juli",
3638
- "aug.",
3639
- "sep.",
3640
- "okt.",
3641
- "nov.",
3642
- "dec.",
3643
- ],
3644
-
3645
- wide: [
3646
- "januari",
3647
- "februari",
3648
- "mars",
3649
- "april",
3650
- "maj",
3651
- "juni",
3652
- "juli",
3653
- "augusti",
3654
- "september",
3655
- "oktober",
3656
- "november",
3657
- "december",
3658
- ],
3659
- };
3660
-
3661
- const dayValues = {
3662
- narrow: ["S", "M", "T", "O", "T", "F", "L"],
3663
- short: ["sö", "må", "ti", "on", "to", "fr", "lö"],
3664
- abbreviated: ["sön", "mån", "tis", "ons", "tors", "fre", "lör"],
3665
- wide: ["söndag", "måndag", "tisdag", "onsdag", "torsdag", "fredag", "lördag"],
3666
- };
3667
-
3668
- // https://www.unicode.org/cldr/charts/32/summary/sv.html#1888
3669
- const dayPeriodValues = {
3670
- narrow: {
3671
- am: "fm",
3672
- pm: "em",
3673
- midnight: "midnatt",
3674
- noon: "middag",
3675
- morning: "morg.",
3676
- afternoon: "efterm.",
3677
- evening: "kväll",
3678
- night: "natt",
3679
- },
3680
- abbreviated: {
3681
- am: "f.m.",
3682
- pm: "e.m.",
3683
- midnight: "midnatt",
3684
- noon: "middag",
3685
- morning: "morgon",
3686
- afternoon: "efterm.",
3687
- evening: "kväll",
3688
- night: "natt",
3689
- },
3690
- wide: {
3691
- am: "förmiddag",
3692
- pm: "eftermiddag",
3693
- midnight: "midnatt",
3694
- noon: "middag",
3695
- morning: "morgon",
3696
- afternoon: "eftermiddag",
3697
- evening: "kväll",
3698
- night: "natt",
3699
- },
3700
- };
3701
-
3702
- const formattingDayPeriodValues = {
3703
- narrow: {
3704
- am: "fm",
3705
- pm: "em",
3706
- midnight: "midnatt",
3707
- noon: "middag",
3708
- morning: "på morg.",
3709
- afternoon: "på efterm.",
3710
- evening: "på kvällen",
3711
- night: "på natten",
3712
- },
3713
- abbreviated: {
3714
- am: "fm",
3715
- pm: "em",
3716
- midnight: "midnatt",
3717
- noon: "middag",
3718
- morning: "på morg.",
3719
- afternoon: "på efterm.",
3720
- evening: "på kvällen",
3721
- night: "på natten",
3722
- },
3723
- wide: {
3724
- am: "fm",
3725
- pm: "em",
3726
- midnight: "midnatt",
3727
- noon: "middag",
3728
- morning: "på morgonen",
3729
- afternoon: "på eftermiddagen",
3730
- evening: "på kvällen",
3731
- night: "på natten",
3732
- },
3733
- };
3734
-
3735
- const ordinalNumber = (dirtyNumber, _options) => {
3736
- const number = Number(dirtyNumber);
3737
-
3738
- const rem100 = number % 100;
3739
- if (rem100 > 20 || rem100 < 10) {
3740
- switch (rem100 % 10) {
3741
- case 1:
3742
- case 2:
3743
- return number + ":a";
3744
- }
3745
- }
3746
- return number + ":e";
3747
- };
3748
-
3749
- const localize = {
3750
- ordinalNumber,
3751
-
3752
- era: buildLocalizeFn({
3753
- values: eraValues,
3754
- defaultWidth: "wide",
3755
- }),
3756
-
3757
- quarter: buildLocalizeFn({
3758
- values: quarterValues,
3759
- defaultWidth: "wide",
3760
- argumentCallback: (quarter) => quarter - 1,
3761
- }),
3762
-
3763
- month: buildLocalizeFn({
3764
- values: monthValues,
3765
- defaultWidth: "wide",
3766
- }),
3767
-
3768
- day: buildLocalizeFn({
3769
- values: dayValues,
3770
- defaultWidth: "wide",
3771
- }),
3772
-
3773
- dayPeriod: buildLocalizeFn({
3774
- values: dayPeriodValues,
3775
- defaultWidth: "wide",
3776
- formattingValues: formattingDayPeriodValues,
3777
- defaultFormattingWidth: "wide",
3778
- }),
3779
- };
3780
-
3781
- const matchOrdinalNumberPattern = /^(\d+)(:a|:e)?/i;
3782
- const parseOrdinalNumberPattern = /\d+/i;
3783
-
3784
- const matchEraPatterns = {
3785
- narrow: /^(f\.? ?Kr\.?|f\.? ?v\.? ?t\.?|e\.? ?Kr\.?|v\.? ?t\.?)/i,
3786
- abbreviated: /^(f\.? ?Kr\.?|f\.? ?v\.? ?t\.?|e\.? ?Kr\.?|v\.? ?t\.?)/i,
3787
- wide: /^(före Kristus|före vår tid|efter Kristus|vår tid)/i,
3788
- };
3789
- const parseEraPatterns = {
3790
- any: [/^f/i, /^[ev]/i],
3791
- };
3792
-
3793
- const matchQuarterPatterns = {
3794
- narrow: /^[1234]/i,
3795
- abbreviated: /^q[1234]/i,
3796
- wide: /^[1234](:a|:e)? kvartalet/i,
3797
- };
3798
- const parseQuarterPatterns = {
3799
- any: [/1/i, /2/i, /3/i, /4/i],
3800
- };
3801
-
3802
- const matchMonthPatterns = {
3803
- narrow: /^[jfmasond]/i,
3804
- abbreviated:
3805
- /^(jan|feb|mar[s]?|apr|maj|jun[i]?|jul[i]?|aug|sep|okt|nov|dec)\.?/i,
3806
- wide: /^(januari|februari|mars|april|maj|juni|juli|augusti|september|oktober|november|december)/i,
3807
- };
3808
- const parseMonthPatterns = {
3809
- narrow: [
3810
- /^j/i,
3811
- /^f/i,
3812
- /^m/i,
3813
- /^a/i,
3814
- /^m/i,
3815
- /^j/i,
3816
- /^j/i,
3817
- /^a/i,
3818
- /^s/i,
3819
- /^o/i,
3820
- /^n/i,
3821
- /^d/i,
3822
- ],
3823
-
3824
- any: [
3825
- /^ja/i,
3826
- /^f/i,
3827
- /^mar/i,
3828
- /^ap/i,
3829
- /^maj/i,
3830
- /^jun/i,
3831
- /^jul/i,
3832
- /^au/i,
3833
- /^s/i,
3834
- /^o/i,
3835
- /^n/i,
3836
- /^d/i,
3837
- ],
3838
- };
3839
-
3840
- const matchDayPatterns = {
3841
- narrow: /^[smtofl]/i,
3842
- short: /^(sö|må|ti|on|to|fr|lö)/i,
3843
- abbreviated: /^(sön|mån|tis|ons|tors|fre|lör)/i,
3844
- wide: /^(söndag|måndag|tisdag|onsdag|torsdag|fredag|lördag)/i,
3845
- };
3846
- const parseDayPatterns = {
3847
- any: [/^s/i, /^m/i, /^ti/i, /^o/i, /^to/i, /^f/i, /^l/i],
3848
- };
3849
-
3850
- const matchDayPeriodPatterns = {
3851
- any: /^([fe]\.?\s?m\.?|midn(att)?|midd(ag)?|(på) (morgonen|eftermiddagen|kvällen|natten))/i,
3852
- };
3853
- const parseDayPeriodPatterns = {
3854
- any: {
3855
- am: /^f/i,
3856
- pm: /^e/i,
3857
- midnight: /^midn/i,
3858
- noon: /^midd/i,
3859
- morning: /morgon/i,
3860
- afternoon: /eftermiddag/i,
3861
- evening: /kväll/i,
3862
- night: /natt/i,
3863
- },
3864
- };
3865
-
3866
- const match = {
3867
- ordinalNumber: buildMatchPatternFn({
3868
- matchPattern: matchOrdinalNumberPattern,
3869
- parsePattern: parseOrdinalNumberPattern,
3870
- valueCallback: (value) => parseInt(value, 10),
3871
- }),
3872
-
3873
- era: buildMatchFn({
3874
- matchPatterns: matchEraPatterns,
3875
- defaultMatchWidth: "wide",
3876
- parsePatterns: parseEraPatterns,
3877
- defaultParseWidth: "any",
3878
- }),
3879
-
3880
- quarter: buildMatchFn({
3881
- matchPatterns: matchQuarterPatterns,
3882
- defaultMatchWidth: "wide",
3883
- parsePatterns: parseQuarterPatterns,
3884
- defaultParseWidth: "any",
3885
- valueCallback: (index) => index + 1,
3886
- }),
3887
-
3888
- month: buildMatchFn({
3889
- matchPatterns: matchMonthPatterns,
3890
- defaultMatchWidth: "wide",
3891
- parsePatterns: parseMonthPatterns,
3892
- defaultParseWidth: "any",
3893
- }),
3894
-
3895
- day: buildMatchFn({
3896
- matchPatterns: matchDayPatterns,
3897
- defaultMatchWidth: "wide",
3898
- parsePatterns: parseDayPatterns,
3899
- defaultParseWidth: "any",
3900
- }),
3901
-
3902
- dayPeriod: buildMatchFn({
3903
- matchPatterns: matchDayPeriodPatterns,
3904
- defaultMatchWidth: "any",
3905
- parsePatterns: parseDayPeriodPatterns,
3906
- defaultParseWidth: "any",
3907
- }),
3908
- };
3909
-
3910
- /**
3911
- * @category Locales
3912
- * @summary Swedish locale.
3913
- * @language Swedish
3914
- * @iso-639-2 swe
3915
- * @author Johannes Ulén [@ejulen](https://github.com/ejulen)
3916
- * @author Alexander Nanberg [@alexandernanberg](https://github.com/alexandernanberg)
3917
- * @author Henrik Andersson [@limelights](https://github.com/limelights)
3918
- */
3919
- const sv = {
3920
- code: "sv",
3921
- formatDistance: formatDistance,
3922
- formatLong: formatLong,
3923
- formatRelative: formatRelative,
3924
- localize: localize,
3925
- match: match,
3926
- options: {
3927
- weekStartsOn: 1 /* Monday */,
3928
- firstWeekContainsDate: 4,
3929
- },
3930
- };
3931
-
3932
590
  var formatDateToLocale = function (date, withYear, withDay) {
3933
591
  var _a;
3934
- return (_a = format(new Date(date), "".concat(withDay ? 'EEEE ' : '', "d MMMM ").concat(withYear ? 'yyyy' : ''), { locale: sv })) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
592
+ return (_a = dateFns.format(new Date(date), "".concat(withDay ? 'EEEE ' : '', "d MMMM ").concat(withYear ? 'yyyy' : ''), { locale: locale.sv })) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
3935
593
  };
3936
594
 
3937
595
  function getDateInfo(dateStr) {
3938
596
  var date = new Date(dateStr);
3939
597
  return {
3940
598
  day: {
3941
- name: format(date, 'EEEE', { locale: sv }),
3942
- number: format(date, 'd')
599
+ name: dateFns.format(date, 'EEEE', { locale: locale.sv }),
600
+ number: dateFns.format(date, 'd')
3943
601
  },
3944
- isTomorrow: isSameDay(date, addDays(new Date(), 1)),
602
+ isTomorrow: dateFns.isSameDay(date, dateFns.addDays(new Date(), 1)),
3945
603
  month: {
3946
- name: format(date, 'MMMM', { locale: sv }),
3947
- number: format(date, 'M')
604
+ name: dateFns.format(date, 'MMMM', { locale: locale.sv }),
605
+ number: dateFns.format(date, 'M')
3948
606
  },
3949
- year: format(date, 'yyyy')
607
+ year: dateFns.format(date, 'yyyy')
3950
608
  };
3951
609
  }
3952
610