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