@xibosignage/xibo-layout-renderer 1.0.8 → 1.0.9

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.
@@ -68190,7 +68190,7 @@ class PlaybackWatcher extends videojs.EventTarget {
68190
68190
  return null;
68191
68191
  }
68192
68192
  }
68193
- const defaultOptions = {
68193
+ const defaultOptions$1 = {
68194
68194
  errorInterval: 30,
68195
68195
  getSource(next) {
68196
68196
  const tech = this.tech({
@@ -68211,7 +68211,7 @@ const defaultOptions = {
68211
68211
  const initPlugin = function (player, options) {
68212
68212
  let lastCalled = 0;
68213
68213
  let seekTo = 0;
68214
- const localOptions = merge(defaultOptions, options);
68214
+ const localOptions = merge(defaultOptions$1, options);
68215
68215
  player.ready(() => {
68216
68216
  player.trigger({
68217
68217
  type: 'usage',
@@ -69794,6 +69794,2803 @@ var flyTransitionKeyframes = function flyTransitionKeyframes(params) {
69794
69794
  return keyframes;
69795
69795
  };
69796
69796
 
69797
+ /**
69798
+ * @module constants
69799
+ * @summary Useful constants
69800
+ * @description
69801
+ * Collection of useful date constants.
69802
+ *
69803
+ * The constants could be imported from `date-fns/constants`:
69804
+ *
69805
+ * ```ts
69806
+ * import { maxTime, minTime } from "./constants/date-fns/constants";
69807
+ *
69808
+ * function isAllowedTime(time) {
69809
+ * return time <= maxTime && time >= minTime;
69810
+ * }
69811
+ * ```
69812
+ */
69813
+
69814
+
69815
+ /**
69816
+ * @constant
69817
+ * @name millisecondsInWeek
69818
+ * @summary Milliseconds in 1 week.
69819
+ */
69820
+ const millisecondsInWeek = 604800000;
69821
+
69822
+ /**
69823
+ * @constant
69824
+ * @name millisecondsInDay
69825
+ * @summary Milliseconds in 1 day.
69826
+ */
69827
+ const millisecondsInDay = 86400000;
69828
+
69829
+ /**
69830
+ * @constant
69831
+ * @name constructFromSymbol
69832
+ * @summary Symbol enabling Date extensions to inherit properties from the reference date.
69833
+ *
69834
+ * The symbol is used to enable the `constructFrom` function to construct a date
69835
+ * using a reference date and a value. It allows to transfer extra properties
69836
+ * from the reference date to the new date. It's useful for extensions like
69837
+ * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
69838
+ * a constructor argument.
69839
+ */
69840
+ const constructFromSymbol = Symbol.for("constructDateFrom");
69841
+
69842
+ /**
69843
+ * @name constructFrom
69844
+ * @category Generic Helpers
69845
+ * @summary Constructs a date using the reference date and the value
69846
+ *
69847
+ * @description
69848
+ * The function constructs a new date using the constructor from the reference
69849
+ * date and the given value. It helps to build generic functions that accept
69850
+ * date extensions.
69851
+ *
69852
+ * It defaults to `Date` if the passed reference date is a number or a string.
69853
+ *
69854
+ * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
69855
+ * enabling to transfer extra properties from the reference date to the new date.
69856
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
69857
+ * that accept a time zone as a constructor argument.
69858
+ *
69859
+ * @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).
69860
+ *
69861
+ * @param date - The reference date to take constructor from
69862
+ * @param value - The value to create the date
69863
+ *
69864
+ * @returns Date initialized using the given date and value
69865
+ *
69866
+ * @example
69867
+ * import { constructFrom } from "./constructFrom/date-fns";
69868
+ *
69869
+ * // A function that clones a date preserving the original type
69870
+ * function cloneDate<DateType extends Date>(date: DateType): DateType {
69871
+ * return constructFrom(
69872
+ * date, // Use constructor from the given date
69873
+ * date.getTime() // Use the date value to create a new date
69874
+ * );
69875
+ * }
69876
+ */
69877
+ function constructFrom(date, value) {
69878
+ if (typeof date === "function") return date(value);
69879
+
69880
+ if (date && typeof date === "object" && constructFromSymbol in date)
69881
+ return date[constructFromSymbol](value);
69882
+
69883
+ if (date instanceof Date) return new date.constructor(value);
69884
+
69885
+ return new Date(value);
69886
+ }
69887
+
69888
+ /**
69889
+ * @name toDate
69890
+ * @category Common Helpers
69891
+ * @summary Convert the given argument to an instance of Date.
69892
+ *
69893
+ * @description
69894
+ * Convert the given argument to an instance of Date.
69895
+ *
69896
+ * If the argument is an instance of Date, the function returns its clone.
69897
+ *
69898
+ * If the argument is a number, it is treated as a timestamp.
69899
+ *
69900
+ * If the argument is none of the above, the function returns Invalid Date.
69901
+ *
69902
+ * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
69903
+ * enabling to transfer extra properties from the reference date to the new date.
69904
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
69905
+ * that accept a time zone as a constructor argument.
69906
+ *
69907
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
69908
+ *
69909
+ * @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).
69910
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
69911
+ *
69912
+ * @param argument - The value to convert
69913
+ *
69914
+ * @returns The parsed date in the local time zone
69915
+ *
69916
+ * @example
69917
+ * // Clone the date:
69918
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
69919
+ * //=> Tue Feb 11 2014 11:30:30
69920
+ *
69921
+ * @example
69922
+ * // Convert the timestamp to date:
69923
+ * const result = toDate(1392098430000)
69924
+ * //=> Tue Feb 11 2014 11:30:30
69925
+ */
69926
+ function toDate(argument, context) {
69927
+ // [TODO] Get rid of `toDate` or `constructFrom`?
69928
+ return constructFrom(context || argument, argument);
69929
+ }
69930
+
69931
+ let defaultOptions = {};
69932
+
69933
+ function getDefaultOptions() {
69934
+ return defaultOptions;
69935
+ }
69936
+
69937
+ /**
69938
+ * The {@link startOfWeek} function options.
69939
+ */
69940
+
69941
+ /**
69942
+ * @name startOfWeek
69943
+ * @category Week Helpers
69944
+ * @summary Return the start of a week for the given date.
69945
+ *
69946
+ * @description
69947
+ * Return the start of a week for the given date.
69948
+ * The result will be in the local timezone.
69949
+ *
69950
+ * @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).
69951
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
69952
+ *
69953
+ * @param date - The original date
69954
+ * @param options - An object with options
69955
+ *
69956
+ * @returns The start of a week
69957
+ *
69958
+ * @example
69959
+ * // The start of a week for 2 September 2014 11:55:00:
69960
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
69961
+ * //=> Sun Aug 31 2014 00:00:00
69962
+ *
69963
+ * @example
69964
+ * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
69965
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
69966
+ * //=> Mon Sep 01 2014 00:00:00
69967
+ */
69968
+ function startOfWeek(date, options) {
69969
+ const defaultOptions = getDefaultOptions();
69970
+ const weekStartsOn =
69971
+ options?.weekStartsOn ??
69972
+ options?.locale?.options?.weekStartsOn ??
69973
+ defaultOptions.weekStartsOn ??
69974
+ defaultOptions.locale?.options?.weekStartsOn ??
69975
+ 0;
69976
+
69977
+ const _date = toDate(date, options?.in);
69978
+ const day = _date.getDay();
69979
+ const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
69980
+
69981
+ _date.setDate(_date.getDate() - diff);
69982
+ _date.setHours(0, 0, 0, 0);
69983
+ return _date;
69984
+ }
69985
+
69986
+ /**
69987
+ * The {@link startOfISOWeek} function options.
69988
+ */
69989
+
69990
+ /**
69991
+ * @name startOfISOWeek
69992
+ * @category ISO Week Helpers
69993
+ * @summary Return the start of an ISO week for the given date.
69994
+ *
69995
+ * @description
69996
+ * Return the start of an ISO week for the given date.
69997
+ * The result will be in the local timezone.
69998
+ *
69999
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
70000
+ *
70001
+ * @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).
70002
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
70003
+ *
70004
+ * @param date - The original date
70005
+ * @param options - An object with options
70006
+ *
70007
+ * @returns The start of an ISO week
70008
+ *
70009
+ * @example
70010
+ * // The start of an ISO week for 2 September 2014 11:55:00:
70011
+ * const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0))
70012
+ * //=> Mon Sep 01 2014 00:00:00
70013
+ */
70014
+ function startOfISOWeek(date, options) {
70015
+ return startOfWeek(date, { ...options, weekStartsOn: 1 });
70016
+ }
70017
+
70018
+ /**
70019
+ * The {@link getISOWeekYear} function options.
70020
+ */
70021
+
70022
+ /**
70023
+ * @name getISOWeekYear
70024
+ * @category ISO Week-Numbering Year Helpers
70025
+ * @summary Get the ISO week-numbering year of the given date.
70026
+ *
70027
+ * @description
70028
+ * Get the ISO week-numbering year of the given date,
70029
+ * which always starts 3 days before the year's first Thursday.
70030
+ *
70031
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
70032
+ *
70033
+ * @param date - The given date
70034
+ *
70035
+ * @returns The ISO week-numbering year
70036
+ *
70037
+ * @example
70038
+ * // Which ISO-week numbering year is 2 January 2005?
70039
+ * const result = getISOWeekYear(new Date(2005, 0, 2))
70040
+ * //=> 2004
70041
+ */
70042
+ function getISOWeekYear(date, options) {
70043
+ const _date = toDate(date, options?.in);
70044
+ const year = _date.getFullYear();
70045
+
70046
+ const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
70047
+ fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
70048
+ fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
70049
+ const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
70050
+
70051
+ const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
70052
+ fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
70053
+ fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
70054
+ const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
70055
+
70056
+ if (_date.getTime() >= startOfNextYear.getTime()) {
70057
+ return year + 1;
70058
+ } else if (_date.getTime() >= startOfThisYear.getTime()) {
70059
+ return year;
70060
+ } else {
70061
+ return year - 1;
70062
+ }
70063
+ }
70064
+
70065
+ /**
70066
+ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
70067
+ * They usually appear for dates that denote time before the timezones were introduced
70068
+ * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
70069
+ * and GMT+01:00:00 after that date)
70070
+ *
70071
+ * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
70072
+ * which would lead to incorrect calculations.
70073
+ *
70074
+ * This function returns the timezone offset in milliseconds that takes seconds in account.
70075
+ */
70076
+ function getTimezoneOffsetInMilliseconds(date) {
70077
+ const _date = toDate(date);
70078
+ const utcDate = new Date(
70079
+ Date.UTC(
70080
+ _date.getFullYear(),
70081
+ _date.getMonth(),
70082
+ _date.getDate(),
70083
+ _date.getHours(),
70084
+ _date.getMinutes(),
70085
+ _date.getSeconds(),
70086
+ _date.getMilliseconds(),
70087
+ ),
70088
+ );
70089
+ utcDate.setUTCFullYear(_date.getFullYear());
70090
+ return +date - +utcDate;
70091
+ }
70092
+
70093
+ function normalizeDates(context, ...dates) {
70094
+ const normalize = constructFrom.bind(
70095
+ null,
70096
+ dates.find((date) => typeof date === "object"),
70097
+ );
70098
+ return dates.map(normalize);
70099
+ }
70100
+
70101
+ /**
70102
+ * The {@link startOfDay} function options.
70103
+ */
70104
+
70105
+ /**
70106
+ * @name startOfDay
70107
+ * @category Day Helpers
70108
+ * @summary Return the start of a day for the given date.
70109
+ *
70110
+ * @description
70111
+ * Return the start of a day for the given date.
70112
+ * The result will be in the local timezone.
70113
+ *
70114
+ * @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).
70115
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
70116
+ *
70117
+ * @param date - The original date
70118
+ * @param options - The options
70119
+ *
70120
+ * @returns The start of a day
70121
+ *
70122
+ * @example
70123
+ * // The start of a day for 2 September 2014 11:55:00:
70124
+ * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
70125
+ * //=> Tue Sep 02 2014 00:00:00
70126
+ */
70127
+ function startOfDay(date, options) {
70128
+ const _date = toDate(date, options?.in);
70129
+ _date.setHours(0, 0, 0, 0);
70130
+ return _date;
70131
+ }
70132
+
70133
+ /**
70134
+ * The {@link differenceInCalendarDays} function options.
70135
+ */
70136
+
70137
+ /**
70138
+ * @name differenceInCalendarDays
70139
+ * @category Day Helpers
70140
+ * @summary Get the number of calendar days between the given dates.
70141
+ *
70142
+ * @description
70143
+ * Get the number of calendar days between the given dates. This means that the times are removed
70144
+ * from the dates and then the difference in days is calculated.
70145
+ *
70146
+ * @param laterDate - The later date
70147
+ * @param earlierDate - The earlier date
70148
+ * @param options - The options object
70149
+ *
70150
+ * @returns The number of calendar days
70151
+ *
70152
+ * @example
70153
+ * // How many calendar days are between
70154
+ * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
70155
+ * const result = differenceInCalendarDays(
70156
+ * new Date(2012, 6, 2, 0, 0),
70157
+ * new Date(2011, 6, 2, 23, 0)
70158
+ * )
70159
+ * //=> 366
70160
+ * // How many calendar days are between
70161
+ * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
70162
+ * const result = differenceInCalendarDays(
70163
+ * new Date(2011, 6, 3, 0, 1),
70164
+ * new Date(2011, 6, 2, 23, 59)
70165
+ * )
70166
+ * //=> 1
70167
+ */
70168
+ function differenceInCalendarDays(laterDate, earlierDate, options) {
70169
+ const [laterDate_, earlierDate_] = normalizeDates(
70170
+ options?.in,
70171
+ laterDate,
70172
+ earlierDate,
70173
+ );
70174
+
70175
+ const laterStartOfDay = startOfDay(laterDate_);
70176
+ const earlierStartOfDay = startOfDay(earlierDate_);
70177
+
70178
+ const laterTimestamp =
70179
+ +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
70180
+ const earlierTimestamp =
70181
+ +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
70182
+
70183
+ // Round the number of days to the nearest integer because the number of
70184
+ // milliseconds in a day is not constant (e.g. it's different in the week of
70185
+ // the daylight saving time clock shift).
70186
+ return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
70187
+ }
70188
+
70189
+ /**
70190
+ * The {@link startOfISOWeekYear} function options.
70191
+ */
70192
+
70193
+ /**
70194
+ * @name startOfISOWeekYear
70195
+ * @category ISO Week-Numbering Year Helpers
70196
+ * @summary Return the start of an ISO week-numbering year for the given date.
70197
+ *
70198
+ * @description
70199
+ * Return the start of an ISO week-numbering year,
70200
+ * which always starts 3 days before the year's first Thursday.
70201
+ * The result will be in the local timezone.
70202
+ *
70203
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
70204
+ *
70205
+ * @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).
70206
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
70207
+ *
70208
+ * @param date - The original date
70209
+ * @param options - An object with options
70210
+ *
70211
+ * @returns The start of an ISO week-numbering year
70212
+ *
70213
+ * @example
70214
+ * // The start of an ISO week-numbering year for 2 July 2005:
70215
+ * const result = startOfISOWeekYear(new Date(2005, 6, 2))
70216
+ * //=> Mon Jan 03 2005 00:00:00
70217
+ */
70218
+ function startOfISOWeekYear(date, options) {
70219
+ const year = getISOWeekYear(date, options);
70220
+ const fourthOfJanuary = constructFrom(date, 0);
70221
+ fourthOfJanuary.setFullYear(year, 0, 4);
70222
+ fourthOfJanuary.setHours(0, 0, 0, 0);
70223
+ return startOfISOWeek(fourthOfJanuary);
70224
+ }
70225
+
70226
+ /**
70227
+ * @name isDate
70228
+ * @category Common Helpers
70229
+ * @summary Is the given value a date?
70230
+ *
70231
+ * @description
70232
+ * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
70233
+ *
70234
+ * @param value - The value to check
70235
+ *
70236
+ * @returns True if the given value is a date
70237
+ *
70238
+ * @example
70239
+ * // For a valid date:
70240
+ * const result = isDate(new Date())
70241
+ * //=> true
70242
+ *
70243
+ * @example
70244
+ * // For an invalid date:
70245
+ * const result = isDate(new Date(NaN))
70246
+ * //=> true
70247
+ *
70248
+ * @example
70249
+ * // For some value:
70250
+ * const result = isDate('2014-02-31')
70251
+ * //=> false
70252
+ *
70253
+ * @example
70254
+ * // For an object:
70255
+ * const result = isDate({})
70256
+ * //=> false
70257
+ */
70258
+ function isDate(value) {
70259
+ return (
70260
+ value instanceof Date ||
70261
+ (typeof value === "object" &&
70262
+ Object.prototype.toString.call(value) === "[object Date]")
70263
+ );
70264
+ }
70265
+
70266
+ /**
70267
+ * @name isValid
70268
+ * @category Common Helpers
70269
+ * @summary Is the given date valid?
70270
+ *
70271
+ * @description
70272
+ * Returns false if argument is Invalid Date and true otherwise.
70273
+ * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate)
70274
+ * Invalid Date is a Date, whose time value is NaN.
70275
+ *
70276
+ * Time value of Date: http://es5.github.io/#x15.9.1.1
70277
+ *
70278
+ * @param date - The date to check
70279
+ *
70280
+ * @returns The date is valid
70281
+ *
70282
+ * @example
70283
+ * // For the valid date:
70284
+ * const result = isValid(new Date(2014, 1, 31))
70285
+ * //=> true
70286
+ *
70287
+ * @example
70288
+ * // For the value, convertible into a date:
70289
+ * const result = isValid(1393804800000)
70290
+ * //=> true
70291
+ *
70292
+ * @example
70293
+ * // For the invalid date:
70294
+ * const result = isValid(new Date(''))
70295
+ * //=> false
70296
+ */
70297
+ function isValid(date) {
70298
+ return !((!isDate(date) && typeof date !== "number") || isNaN(+toDate(date)));
70299
+ }
70300
+
70301
+ /**
70302
+ * The {@link startOfYear} function options.
70303
+ */
70304
+
70305
+ /**
70306
+ * @name startOfYear
70307
+ * @category Year Helpers
70308
+ * @summary Return the start of a year for the given date.
70309
+ *
70310
+ * @description
70311
+ * Return the start of a year for the given date.
70312
+ * The result will be in the local timezone.
70313
+ *
70314
+ * @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).
70315
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
70316
+ *
70317
+ * @param date - The original date
70318
+ * @param options - The options
70319
+ *
70320
+ * @returns The start of a year
70321
+ *
70322
+ * @example
70323
+ * // The start of a year for 2 September 2014 11:55:00:
70324
+ * const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00))
70325
+ * //=> Wed Jan 01 2014 00:00:00
70326
+ */
70327
+ function startOfYear(date, options) {
70328
+ const date_ = toDate(date, options?.in);
70329
+ date_.setFullYear(date_.getFullYear(), 0, 1);
70330
+ date_.setHours(0, 0, 0, 0);
70331
+ return date_;
70332
+ }
70333
+
70334
+ const formatDistanceLocale = {
70335
+ lessThanXSeconds: {
70336
+ one: "less than a second",
70337
+ other: "less than {{count}} seconds",
70338
+ },
70339
+
70340
+ xSeconds: {
70341
+ one: "1 second",
70342
+ other: "{{count}} seconds",
70343
+ },
70344
+
70345
+ halfAMinute: "half a minute",
70346
+
70347
+ lessThanXMinutes: {
70348
+ one: "less than a minute",
70349
+ other: "less than {{count}} minutes",
70350
+ },
70351
+
70352
+ xMinutes: {
70353
+ one: "1 minute",
70354
+ other: "{{count}} minutes",
70355
+ },
70356
+
70357
+ aboutXHours: {
70358
+ one: "about 1 hour",
70359
+ other: "about {{count}} hours",
70360
+ },
70361
+
70362
+ xHours: {
70363
+ one: "1 hour",
70364
+ other: "{{count}} hours",
70365
+ },
70366
+
70367
+ xDays: {
70368
+ one: "1 day",
70369
+ other: "{{count}} days",
70370
+ },
70371
+
70372
+ aboutXWeeks: {
70373
+ one: "about 1 week",
70374
+ other: "about {{count}} weeks",
70375
+ },
70376
+
70377
+ xWeeks: {
70378
+ one: "1 week",
70379
+ other: "{{count}} weeks",
70380
+ },
70381
+
70382
+ aboutXMonths: {
70383
+ one: "about 1 month",
70384
+ other: "about {{count}} months",
70385
+ },
70386
+
70387
+ xMonths: {
70388
+ one: "1 month",
70389
+ other: "{{count}} months",
70390
+ },
70391
+
70392
+ aboutXYears: {
70393
+ one: "about 1 year",
70394
+ other: "about {{count}} years",
70395
+ },
70396
+
70397
+ xYears: {
70398
+ one: "1 year",
70399
+ other: "{{count}} years",
70400
+ },
70401
+
70402
+ overXYears: {
70403
+ one: "over 1 year",
70404
+ other: "over {{count}} years",
70405
+ },
70406
+
70407
+ almostXYears: {
70408
+ one: "almost 1 year",
70409
+ other: "almost {{count}} years",
70410
+ },
70411
+ };
70412
+
70413
+ const formatDistance = (token, count, options) => {
70414
+ let result;
70415
+
70416
+ const tokenValue = formatDistanceLocale[token];
70417
+ if (typeof tokenValue === "string") {
70418
+ result = tokenValue;
70419
+ } else if (count === 1) {
70420
+ result = tokenValue.one;
70421
+ } else {
70422
+ result = tokenValue.other.replace("{{count}}", count.toString());
70423
+ }
70424
+
70425
+ if (options?.addSuffix) {
70426
+ if (options.comparison && options.comparison > 0) {
70427
+ return "in " + result;
70428
+ } else {
70429
+ return result + " ago";
70430
+ }
70431
+ }
70432
+
70433
+ return result;
70434
+ };
70435
+
70436
+ function buildFormatLongFn(args) {
70437
+ return (options = {}) => {
70438
+ // TODO: Remove String()
70439
+ const width = options.width ? String(options.width) : args.defaultWidth;
70440
+ const format = args.formats[width] || args.formats[args.defaultWidth];
70441
+ return format;
70442
+ };
70443
+ }
70444
+
70445
+ const dateFormats = {
70446
+ full: "EEEE, MMMM do, y",
70447
+ long: "MMMM do, y",
70448
+ medium: "MMM d, y",
70449
+ short: "MM/dd/yyyy",
70450
+ };
70451
+
70452
+ const timeFormats = {
70453
+ full: "h:mm:ss a zzzz",
70454
+ long: "h:mm:ss a z",
70455
+ medium: "h:mm:ss a",
70456
+ short: "h:mm a",
70457
+ };
70458
+
70459
+ const dateTimeFormats = {
70460
+ full: "{{date}} 'at' {{time}}",
70461
+ long: "{{date}} 'at' {{time}}",
70462
+ medium: "{{date}}, {{time}}",
70463
+ short: "{{date}}, {{time}}",
70464
+ };
70465
+
70466
+ const formatLong = {
70467
+ date: buildFormatLongFn({
70468
+ formats: dateFormats,
70469
+ defaultWidth: "full",
70470
+ }),
70471
+
70472
+ time: buildFormatLongFn({
70473
+ formats: timeFormats,
70474
+ defaultWidth: "full",
70475
+ }),
70476
+
70477
+ dateTime: buildFormatLongFn({
70478
+ formats: dateTimeFormats,
70479
+ defaultWidth: "full",
70480
+ }),
70481
+ };
70482
+
70483
+ const formatRelativeLocale = {
70484
+ lastWeek: "'last' eeee 'at' p",
70485
+ yesterday: "'yesterday at' p",
70486
+ today: "'today at' p",
70487
+ tomorrow: "'tomorrow at' p",
70488
+ nextWeek: "eeee 'at' p",
70489
+ other: "P",
70490
+ };
70491
+
70492
+ const formatRelative = (token, _date, _baseDate, _options) =>
70493
+ formatRelativeLocale[token];
70494
+
70495
+ /**
70496
+ * The localize function argument callback which allows to convert raw value to
70497
+ * the actual type.
70498
+ *
70499
+ * @param value - The value to convert
70500
+ *
70501
+ * @returns The converted value
70502
+ */
70503
+
70504
+ /**
70505
+ * The map of localized values for each width.
70506
+ */
70507
+
70508
+ /**
70509
+ * The index type of the locale unit value. It types conversion of units of
70510
+ * values that don't start at 0 (i.e. quarters).
70511
+ */
70512
+
70513
+ /**
70514
+ * Converts the unit value to the tuple of values.
70515
+ */
70516
+
70517
+ /**
70518
+ * The tuple of localized era values. The first element represents BC,
70519
+ * the second element represents AD.
70520
+ */
70521
+
70522
+ /**
70523
+ * The tuple of localized quarter values. The first element represents Q1.
70524
+ */
70525
+
70526
+ /**
70527
+ * The tuple of localized day values. The first element represents Sunday.
70528
+ */
70529
+
70530
+ /**
70531
+ * The tuple of localized month values. The first element represents January.
70532
+ */
70533
+
70534
+ function buildLocalizeFn(args) {
70535
+ return (value, options) => {
70536
+ const context = options?.context ? String(options.context) : "standalone";
70537
+
70538
+ let valuesArray;
70539
+ if (context === "formatting" && args.formattingValues) {
70540
+ const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
70541
+ const width = options?.width ? String(options.width) : defaultWidth;
70542
+
70543
+ valuesArray =
70544
+ args.formattingValues[width] || args.formattingValues[defaultWidth];
70545
+ } else {
70546
+ const defaultWidth = args.defaultWidth;
70547
+ const width = options?.width ? String(options.width) : args.defaultWidth;
70548
+
70549
+ valuesArray = args.values[width] || args.values[defaultWidth];
70550
+ }
70551
+ const index = args.argumentCallback ? args.argumentCallback(value) : value;
70552
+
70553
+ // @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!
70554
+ return valuesArray[index];
70555
+ };
70556
+ }
70557
+
70558
+ const eraValues = {
70559
+ narrow: ["B", "A"],
70560
+ abbreviated: ["BC", "AD"],
70561
+ wide: ["Before Christ", "Anno Domini"],
70562
+ };
70563
+
70564
+ const quarterValues = {
70565
+ narrow: ["1", "2", "3", "4"],
70566
+ abbreviated: ["Q1", "Q2", "Q3", "Q4"],
70567
+ wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
70568
+ };
70569
+
70570
+ // Note: in English, the names of days of the week and months are capitalized.
70571
+ // If you are making a new locale based on this one, check if the same is true for the language you're working on.
70572
+ // Generally, formatted dates should look like they are in the middle of a sentence,
70573
+ // e.g. in Spanish language the weekdays and months should be in the lowercase.
70574
+ const monthValues = {
70575
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
70576
+ abbreviated: [
70577
+ "Jan",
70578
+ "Feb",
70579
+ "Mar",
70580
+ "Apr",
70581
+ "May",
70582
+ "Jun",
70583
+ "Jul",
70584
+ "Aug",
70585
+ "Sep",
70586
+ "Oct",
70587
+ "Nov",
70588
+ "Dec",
70589
+ ],
70590
+
70591
+ wide: [
70592
+ "January",
70593
+ "February",
70594
+ "March",
70595
+ "April",
70596
+ "May",
70597
+ "June",
70598
+ "July",
70599
+ "August",
70600
+ "September",
70601
+ "October",
70602
+ "November",
70603
+ "December",
70604
+ ],
70605
+ };
70606
+
70607
+ const dayValues = {
70608
+ narrow: ["S", "M", "T", "W", "T", "F", "S"],
70609
+ short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
70610
+ abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
70611
+ wide: [
70612
+ "Sunday",
70613
+ "Monday",
70614
+ "Tuesday",
70615
+ "Wednesday",
70616
+ "Thursday",
70617
+ "Friday",
70618
+ "Saturday",
70619
+ ],
70620
+ };
70621
+
70622
+ const dayPeriodValues = {
70623
+ narrow: {
70624
+ am: "a",
70625
+ pm: "p",
70626
+ midnight: "mi",
70627
+ noon: "n",
70628
+ morning: "morning",
70629
+ afternoon: "afternoon",
70630
+ evening: "evening",
70631
+ night: "night",
70632
+ },
70633
+ abbreviated: {
70634
+ am: "AM",
70635
+ pm: "PM",
70636
+ midnight: "midnight",
70637
+ noon: "noon",
70638
+ morning: "morning",
70639
+ afternoon: "afternoon",
70640
+ evening: "evening",
70641
+ night: "night",
70642
+ },
70643
+ wide: {
70644
+ am: "a.m.",
70645
+ pm: "p.m.",
70646
+ midnight: "midnight",
70647
+ noon: "noon",
70648
+ morning: "morning",
70649
+ afternoon: "afternoon",
70650
+ evening: "evening",
70651
+ night: "night",
70652
+ },
70653
+ };
70654
+
70655
+ const formattingDayPeriodValues = {
70656
+ narrow: {
70657
+ am: "a",
70658
+ pm: "p",
70659
+ midnight: "mi",
70660
+ noon: "n",
70661
+ morning: "in the morning",
70662
+ afternoon: "in the afternoon",
70663
+ evening: "in the evening",
70664
+ night: "at night",
70665
+ },
70666
+ abbreviated: {
70667
+ am: "AM",
70668
+ pm: "PM",
70669
+ midnight: "midnight",
70670
+ noon: "noon",
70671
+ morning: "in the morning",
70672
+ afternoon: "in the afternoon",
70673
+ evening: "in the evening",
70674
+ night: "at night",
70675
+ },
70676
+ wide: {
70677
+ am: "a.m.",
70678
+ pm: "p.m.",
70679
+ midnight: "midnight",
70680
+ noon: "noon",
70681
+ morning: "in the morning",
70682
+ afternoon: "in the afternoon",
70683
+ evening: "in the evening",
70684
+ night: "at night",
70685
+ },
70686
+ };
70687
+
70688
+ const ordinalNumber = (dirtyNumber, _options) => {
70689
+ const number = Number(dirtyNumber);
70690
+
70691
+ // If ordinal numbers depend on context, for example,
70692
+ // if they are different for different grammatical genders,
70693
+ // use `options.unit`.
70694
+ //
70695
+ // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
70696
+ // 'day', 'hour', 'minute', 'second'.
70697
+
70698
+ const rem100 = number % 100;
70699
+ if (rem100 > 20 || rem100 < 10) {
70700
+ switch (rem100 % 10) {
70701
+ case 1:
70702
+ return number + "st";
70703
+ case 2:
70704
+ return number + "nd";
70705
+ case 3:
70706
+ return number + "rd";
70707
+ }
70708
+ }
70709
+ return number + "th";
70710
+ };
70711
+
70712
+ const localize = {
70713
+ ordinalNumber,
70714
+
70715
+ era: buildLocalizeFn({
70716
+ values: eraValues,
70717
+ defaultWidth: "wide",
70718
+ }),
70719
+
70720
+ quarter: buildLocalizeFn({
70721
+ values: quarterValues,
70722
+ defaultWidth: "wide",
70723
+ argumentCallback: (quarter) => quarter - 1,
70724
+ }),
70725
+
70726
+ month: buildLocalizeFn({
70727
+ values: monthValues,
70728
+ defaultWidth: "wide",
70729
+ }),
70730
+
70731
+ day: buildLocalizeFn({
70732
+ values: dayValues,
70733
+ defaultWidth: "wide",
70734
+ }),
70735
+
70736
+ dayPeriod: buildLocalizeFn({
70737
+ values: dayPeriodValues,
70738
+ defaultWidth: "wide",
70739
+ formattingValues: formattingDayPeriodValues,
70740
+ defaultFormattingWidth: "wide",
70741
+ }),
70742
+ };
70743
+
70744
+ function buildMatchFn(args) {
70745
+ return (string, options = {}) => {
70746
+ const width = options.width;
70747
+
70748
+ const matchPattern =
70749
+ (width && args.matchPatterns[width]) ||
70750
+ args.matchPatterns[args.defaultMatchWidth];
70751
+ const matchResult = string.match(matchPattern);
70752
+
70753
+ if (!matchResult) {
70754
+ return null;
70755
+ }
70756
+ const matchedString = matchResult[0];
70757
+
70758
+ const parsePatterns =
70759
+ (width && args.parsePatterns[width]) ||
70760
+ args.parsePatterns[args.defaultParseWidth];
70761
+
70762
+ const key = Array.isArray(parsePatterns)
70763
+ ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
70764
+ : // [TODO] -- I challenge you to fix the type
70765
+ findKey(parsePatterns, (pattern) => pattern.test(matchedString));
70766
+
70767
+ let value;
70768
+
70769
+ value = args.valueCallback ? args.valueCallback(key) : key;
70770
+ value = options.valueCallback
70771
+ ? // [TODO] -- I challenge you to fix the type
70772
+ options.valueCallback(value)
70773
+ : value;
70774
+
70775
+ const rest = string.slice(matchedString.length);
70776
+
70777
+ return { value, rest };
70778
+ };
70779
+ }
70780
+
70781
+ function findKey(object, predicate) {
70782
+ for (const key in object) {
70783
+ if (
70784
+ Object.prototype.hasOwnProperty.call(object, key) &&
70785
+ predicate(object[key])
70786
+ ) {
70787
+ return key;
70788
+ }
70789
+ }
70790
+ return undefined;
70791
+ }
70792
+
70793
+ function findIndex(array, predicate) {
70794
+ for (let key = 0; key < array.length; key++) {
70795
+ if (predicate(array[key])) {
70796
+ return key;
70797
+ }
70798
+ }
70799
+ return undefined;
70800
+ }
70801
+
70802
+ function buildMatchPatternFn(args) {
70803
+ return (string, options = {}) => {
70804
+ const matchResult = string.match(args.matchPattern);
70805
+ if (!matchResult) return null;
70806
+ const matchedString = matchResult[0];
70807
+
70808
+ const parseResult = string.match(args.parsePattern);
70809
+ if (!parseResult) return null;
70810
+ let value = args.valueCallback
70811
+ ? args.valueCallback(parseResult[0])
70812
+ : parseResult[0];
70813
+
70814
+ // [TODO] I challenge you to fix the type
70815
+ value = options.valueCallback ? options.valueCallback(value) : value;
70816
+
70817
+ const rest = string.slice(matchedString.length);
70818
+
70819
+ return { value, rest };
70820
+ };
70821
+ }
70822
+
70823
+ const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
70824
+ const parseOrdinalNumberPattern = /\d+/i;
70825
+
70826
+ const matchEraPatterns = {
70827
+ narrow: /^(b|a)/i,
70828
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
70829
+ wide: /^(before christ|before common era|anno domini|common era)/i,
70830
+ };
70831
+ const parseEraPatterns = {
70832
+ any: [/^b/i, /^(a|c)/i],
70833
+ };
70834
+
70835
+ const matchQuarterPatterns = {
70836
+ narrow: /^[1234]/i,
70837
+ abbreviated: /^q[1234]/i,
70838
+ wide: /^[1234](th|st|nd|rd)? quarter/i,
70839
+ };
70840
+ const parseQuarterPatterns = {
70841
+ any: [/1/i, /2/i, /3/i, /4/i],
70842
+ };
70843
+
70844
+ const matchMonthPatterns = {
70845
+ narrow: /^[jfmasond]/i,
70846
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
70847
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i,
70848
+ };
70849
+ const parseMonthPatterns = {
70850
+ narrow: [
70851
+ /^j/i,
70852
+ /^f/i,
70853
+ /^m/i,
70854
+ /^a/i,
70855
+ /^m/i,
70856
+ /^j/i,
70857
+ /^j/i,
70858
+ /^a/i,
70859
+ /^s/i,
70860
+ /^o/i,
70861
+ /^n/i,
70862
+ /^d/i,
70863
+ ],
70864
+
70865
+ any: [
70866
+ /^ja/i,
70867
+ /^f/i,
70868
+ /^mar/i,
70869
+ /^ap/i,
70870
+ /^may/i,
70871
+ /^jun/i,
70872
+ /^jul/i,
70873
+ /^au/i,
70874
+ /^s/i,
70875
+ /^o/i,
70876
+ /^n/i,
70877
+ /^d/i,
70878
+ ],
70879
+ };
70880
+
70881
+ const matchDayPatterns = {
70882
+ narrow: /^[smtwf]/i,
70883
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
70884
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
70885
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i,
70886
+ };
70887
+ const parseDayPatterns = {
70888
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
70889
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i],
70890
+ };
70891
+
70892
+ const matchDayPeriodPatterns = {
70893
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
70894
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i,
70895
+ };
70896
+ const parseDayPeriodPatterns = {
70897
+ any: {
70898
+ am: /^a/i,
70899
+ pm: /^p/i,
70900
+ midnight: /^mi/i,
70901
+ noon: /^no/i,
70902
+ morning: /morning/i,
70903
+ afternoon: /afternoon/i,
70904
+ evening: /evening/i,
70905
+ night: /night/i,
70906
+ },
70907
+ };
70908
+
70909
+ const match = {
70910
+ ordinalNumber: buildMatchPatternFn({
70911
+ matchPattern: matchOrdinalNumberPattern,
70912
+ parsePattern: parseOrdinalNumberPattern,
70913
+ valueCallback: (value) => parseInt(value, 10),
70914
+ }),
70915
+
70916
+ era: buildMatchFn({
70917
+ matchPatterns: matchEraPatterns,
70918
+ defaultMatchWidth: "wide",
70919
+ parsePatterns: parseEraPatterns,
70920
+ defaultParseWidth: "any",
70921
+ }),
70922
+
70923
+ quarter: buildMatchFn({
70924
+ matchPatterns: matchQuarterPatterns,
70925
+ defaultMatchWidth: "wide",
70926
+ parsePatterns: parseQuarterPatterns,
70927
+ defaultParseWidth: "any",
70928
+ valueCallback: (index) => index + 1,
70929
+ }),
70930
+
70931
+ month: buildMatchFn({
70932
+ matchPatterns: matchMonthPatterns,
70933
+ defaultMatchWidth: "wide",
70934
+ parsePatterns: parseMonthPatterns,
70935
+ defaultParseWidth: "any",
70936
+ }),
70937
+
70938
+ day: buildMatchFn({
70939
+ matchPatterns: matchDayPatterns,
70940
+ defaultMatchWidth: "wide",
70941
+ parsePatterns: parseDayPatterns,
70942
+ defaultParseWidth: "any",
70943
+ }),
70944
+
70945
+ dayPeriod: buildMatchFn({
70946
+ matchPatterns: matchDayPeriodPatterns,
70947
+ defaultMatchWidth: "any",
70948
+ parsePatterns: parseDayPeriodPatterns,
70949
+ defaultParseWidth: "any",
70950
+ }),
70951
+ };
70952
+
70953
+ /**
70954
+ * @category Locales
70955
+ * @summary English locale (United States).
70956
+ * @language English
70957
+ * @iso-639-2 eng
70958
+ * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp)
70959
+ * @author Lesha Koss [@leshakoss](https://github.com/leshakoss)
70960
+ */
70961
+ const enUS = {
70962
+ code: "en-US",
70963
+ formatDistance: formatDistance,
70964
+ formatLong: formatLong,
70965
+ formatRelative: formatRelative,
70966
+ localize: localize,
70967
+ match: match,
70968
+ options: {
70969
+ weekStartsOn: 0 /* Sunday */,
70970
+ firstWeekContainsDate: 1,
70971
+ },
70972
+ };
70973
+
70974
+ /**
70975
+ * The {@link getDayOfYear} function options.
70976
+ */
70977
+
70978
+ /**
70979
+ * @name getDayOfYear
70980
+ * @category Day Helpers
70981
+ * @summary Get the day of the year of the given date.
70982
+ *
70983
+ * @description
70984
+ * Get the day of the year of the given date.
70985
+ *
70986
+ * @param date - The given date
70987
+ * @param options - The options
70988
+ *
70989
+ * @returns The day of year
70990
+ *
70991
+ * @example
70992
+ * // Which day of the year is 2 July 2014?
70993
+ * const result = getDayOfYear(new Date(2014, 6, 2))
70994
+ * //=> 183
70995
+ */
70996
+ function getDayOfYear(date, options) {
70997
+ const _date = toDate(date, options?.in);
70998
+ const diff = differenceInCalendarDays(_date, startOfYear(_date));
70999
+ const dayOfYear = diff + 1;
71000
+ return dayOfYear;
71001
+ }
71002
+
71003
+ /**
71004
+ * The {@link getISOWeek} function options.
71005
+ */
71006
+
71007
+ /**
71008
+ * @name getISOWeek
71009
+ * @category ISO Week Helpers
71010
+ * @summary Get the ISO week of the given date.
71011
+ *
71012
+ * @description
71013
+ * Get the ISO week of the given date.
71014
+ *
71015
+ * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
71016
+ *
71017
+ * @param date - The given date
71018
+ * @param options - The options
71019
+ *
71020
+ * @returns The ISO week
71021
+ *
71022
+ * @example
71023
+ * // Which week of the ISO-week numbering year is 2 January 2005?
71024
+ * const result = getISOWeek(new Date(2005, 0, 2))
71025
+ * //=> 53
71026
+ */
71027
+ function getISOWeek(date, options) {
71028
+ const _date = toDate(date, options?.in);
71029
+ const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
71030
+
71031
+ // Round the number of weeks to the nearest integer because the number of
71032
+ // milliseconds in a week is not constant (e.g. it's different in the week of
71033
+ // the daylight saving time clock shift).
71034
+ return Math.round(diff / millisecondsInWeek) + 1;
71035
+ }
71036
+
71037
+ /**
71038
+ * The {@link getWeekYear} function options.
71039
+ */
71040
+
71041
+ /**
71042
+ * @name getWeekYear
71043
+ * @category Week-Numbering Year Helpers
71044
+ * @summary Get the local week-numbering year of the given date.
71045
+ *
71046
+ * @description
71047
+ * Get the local week-numbering year of the given date.
71048
+ * The exact calculation depends on the values of
71049
+ * `options.weekStartsOn` (which is the index of the first day of the week)
71050
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
71051
+ * the first week of the week-numbering year)
71052
+ *
71053
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
71054
+ *
71055
+ * @param date - The given date
71056
+ * @param options - An object with options.
71057
+ *
71058
+ * @returns The local week-numbering year
71059
+ *
71060
+ * @example
71061
+ * // Which week numbering year is 26 December 2004 with the default settings?
71062
+ * const result = getWeekYear(new Date(2004, 11, 26))
71063
+ * //=> 2005
71064
+ *
71065
+ * @example
71066
+ * // Which week numbering year is 26 December 2004 if week starts on Saturday?
71067
+ * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
71068
+ * //=> 2004
71069
+ *
71070
+ * @example
71071
+ * // Which week numbering year is 26 December 2004 if the first week contains 4 January?
71072
+ * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
71073
+ * //=> 2004
71074
+ */
71075
+ function getWeekYear(date, options) {
71076
+ const _date = toDate(date, options?.in);
71077
+ const year = _date.getFullYear();
71078
+
71079
+ const defaultOptions = getDefaultOptions();
71080
+ const firstWeekContainsDate =
71081
+ options?.firstWeekContainsDate ??
71082
+ options?.locale?.options?.firstWeekContainsDate ??
71083
+ defaultOptions.firstWeekContainsDate ??
71084
+ defaultOptions.locale?.options?.firstWeekContainsDate ??
71085
+ 1;
71086
+
71087
+ const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
71088
+ firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
71089
+ firstWeekOfNextYear.setHours(0, 0, 0, 0);
71090
+ const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
71091
+
71092
+ const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
71093
+ firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
71094
+ firstWeekOfThisYear.setHours(0, 0, 0, 0);
71095
+ const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
71096
+
71097
+ if (+_date >= +startOfNextYear) {
71098
+ return year + 1;
71099
+ } else if (+_date >= +startOfThisYear) {
71100
+ return year;
71101
+ } else {
71102
+ return year - 1;
71103
+ }
71104
+ }
71105
+
71106
+ /**
71107
+ * The {@link startOfWeekYear} function options.
71108
+ */
71109
+
71110
+ /**
71111
+ * @name startOfWeekYear
71112
+ * @category Week-Numbering Year Helpers
71113
+ * @summary Return the start of a local week-numbering year for the given date.
71114
+ *
71115
+ * @description
71116
+ * Return the start of a local week-numbering year.
71117
+ * The exact calculation depends on the values of
71118
+ * `options.weekStartsOn` (which is the index of the first day of the week)
71119
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
71120
+ * the first week of the week-numbering year)
71121
+ *
71122
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
71123
+ *
71124
+ * @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).
71125
+ * @typeParam ResultDate - The result `Date` type.
71126
+ *
71127
+ * @param date - The original date
71128
+ * @param options - An object with options
71129
+ *
71130
+ * @returns The start of a week-numbering year
71131
+ *
71132
+ * @example
71133
+ * // The start of an a week-numbering year for 2 July 2005 with default settings:
71134
+ * const result = startOfWeekYear(new Date(2005, 6, 2))
71135
+ * //=> Sun Dec 26 2004 00:00:00
71136
+ *
71137
+ * @example
71138
+ * // The start of a week-numbering year for 2 July 2005
71139
+ * // if Monday is the first day of week
71140
+ * // and 4 January is always in the first week of the year:
71141
+ * const result = startOfWeekYear(new Date(2005, 6, 2), {
71142
+ * weekStartsOn: 1,
71143
+ * firstWeekContainsDate: 4
71144
+ * })
71145
+ * //=> Mon Jan 03 2005 00:00:00
71146
+ */
71147
+ function startOfWeekYear(date, options) {
71148
+ const defaultOptions = getDefaultOptions();
71149
+ const firstWeekContainsDate =
71150
+ options?.firstWeekContainsDate ??
71151
+ options?.locale?.options?.firstWeekContainsDate ??
71152
+ defaultOptions.firstWeekContainsDate ??
71153
+ defaultOptions.locale?.options?.firstWeekContainsDate ??
71154
+ 1;
71155
+
71156
+ const year = getWeekYear(date, options);
71157
+ const firstWeek = constructFrom(options?.in || date, 0);
71158
+ firstWeek.setFullYear(year, 0, firstWeekContainsDate);
71159
+ firstWeek.setHours(0, 0, 0, 0);
71160
+ const _date = startOfWeek(firstWeek, options);
71161
+ return _date;
71162
+ }
71163
+
71164
+ /**
71165
+ * The {@link getWeek} function options.
71166
+ */
71167
+
71168
+ /**
71169
+ * @name getWeek
71170
+ * @category Week Helpers
71171
+ * @summary Get the local week index of the given date.
71172
+ *
71173
+ * @description
71174
+ * Get the local week index of the given date.
71175
+ * The exact calculation depends on the values of
71176
+ * `options.weekStartsOn` (which is the index of the first day of the week)
71177
+ * and `options.firstWeekContainsDate` (which is the day of January, which is always in
71178
+ * the first week of the week-numbering year)
71179
+ *
71180
+ * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
71181
+ *
71182
+ * @param date - The given date
71183
+ * @param options - An object with options
71184
+ *
71185
+ * @returns The week
71186
+ *
71187
+ * @example
71188
+ * // Which week of the local week numbering year is 2 January 2005 with default options?
71189
+ * const result = getWeek(new Date(2005, 0, 2))
71190
+ * //=> 2
71191
+ *
71192
+ * @example
71193
+ * // Which week of the local week numbering year is 2 January 2005,
71194
+ * // if Monday is the first day of the week,
71195
+ * // and the first week of the year always contains 4 January?
71196
+ * const result = getWeek(new Date(2005, 0, 2), {
71197
+ * weekStartsOn: 1,
71198
+ * firstWeekContainsDate: 4
71199
+ * })
71200
+ * //=> 53
71201
+ */
71202
+ function getWeek(date, options) {
71203
+ const _date = toDate(date, options?.in);
71204
+ const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
71205
+
71206
+ // Round the number of weeks to the nearest integer because the number of
71207
+ // milliseconds in a week is not constant (e.g. it's different in the week of
71208
+ // the daylight saving time clock shift).
71209
+ return Math.round(diff / millisecondsInWeek) + 1;
71210
+ }
71211
+
71212
+ function addLeadingZeros(number, targetLength) {
71213
+ const sign = number < 0 ? "-" : "";
71214
+ const output = Math.abs(number).toString().padStart(targetLength, "0");
71215
+ return sign + output;
71216
+ }
71217
+
71218
+ /*
71219
+ * | | Unit | | Unit |
71220
+ * |-----|--------------------------------|-----|--------------------------------|
71221
+ * | a | AM, PM | A* | |
71222
+ * | d | Day of month | D | |
71223
+ * | h | Hour [1-12] | H | Hour [0-23] |
71224
+ * | m | Minute | M | Month |
71225
+ * | s | Second | S | Fraction of second |
71226
+ * | y | Year (abs) | Y | |
71227
+ *
71228
+ * Letters marked by * are not implemented but reserved by Unicode standard.
71229
+ */
71230
+
71231
+ const lightFormatters = {
71232
+ // Year
71233
+ y(date, token) {
71234
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
71235
+ // | Year | y | yy | yyy | yyyy | yyyyy |
71236
+ // |----------|-------|----|-------|-------|-------|
71237
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
71238
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
71239
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
71240
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
71241
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
71242
+
71243
+ const signedYear = date.getFullYear();
71244
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
71245
+ const year = signedYear > 0 ? signedYear : 1 - signedYear;
71246
+ return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
71247
+ },
71248
+
71249
+ // Month
71250
+ M(date, token) {
71251
+ const month = date.getMonth();
71252
+ return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
71253
+ },
71254
+
71255
+ // Day of the month
71256
+ d(date, token) {
71257
+ return addLeadingZeros(date.getDate(), token.length);
71258
+ },
71259
+
71260
+ // AM or PM
71261
+ a(date, token) {
71262
+ const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
71263
+
71264
+ switch (token) {
71265
+ case "a":
71266
+ case "aa":
71267
+ return dayPeriodEnumValue.toUpperCase();
71268
+ case "aaa":
71269
+ return dayPeriodEnumValue;
71270
+ case "aaaaa":
71271
+ return dayPeriodEnumValue[0];
71272
+ case "aaaa":
71273
+ default:
71274
+ return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
71275
+ }
71276
+ },
71277
+
71278
+ // Hour [1-12]
71279
+ h(date, token) {
71280
+ return addLeadingZeros(date.getHours() % 12 || 12, token.length);
71281
+ },
71282
+
71283
+ // Hour [0-23]
71284
+ H(date, token) {
71285
+ return addLeadingZeros(date.getHours(), token.length);
71286
+ },
71287
+
71288
+ // Minute
71289
+ m(date, token) {
71290
+ return addLeadingZeros(date.getMinutes(), token.length);
71291
+ },
71292
+
71293
+ // Second
71294
+ s(date, token) {
71295
+ return addLeadingZeros(date.getSeconds(), token.length);
71296
+ },
71297
+
71298
+ // Fraction of second
71299
+ S(date, token) {
71300
+ const numberOfDigits = token.length;
71301
+ const milliseconds = date.getMilliseconds();
71302
+ const fractionalSeconds = Math.trunc(
71303
+ milliseconds * Math.pow(10, numberOfDigits - 3),
71304
+ );
71305
+ return addLeadingZeros(fractionalSeconds, token.length);
71306
+ },
71307
+ };
71308
+
71309
+ const dayPeriodEnum = {
71310
+ am: "am",
71311
+ pm: "pm",
71312
+ midnight: "midnight",
71313
+ noon: "noon",
71314
+ morning: "morning",
71315
+ afternoon: "afternoon",
71316
+ evening: "evening",
71317
+ night: "night",
71318
+ };
71319
+
71320
+ /*
71321
+ * | | Unit | | Unit |
71322
+ * |-----|--------------------------------|-----|--------------------------------|
71323
+ * | a | AM, PM | A* | Milliseconds in day |
71324
+ * | b | AM, PM, noon, midnight | B | Flexible day period |
71325
+ * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
71326
+ * | d | Day of month | D | Day of year |
71327
+ * | e | Local day of week | E | Day of week |
71328
+ * | f | | F* | Day of week in month |
71329
+ * | g* | Modified Julian day | G | Era |
71330
+ * | h | Hour [1-12] | H | Hour [0-23] |
71331
+ * | i! | ISO day of week | I! | ISO week of year |
71332
+ * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
71333
+ * | k | Hour [1-24] | K | Hour [0-11] |
71334
+ * | l* | (deprecated) | L | Stand-alone month |
71335
+ * | m | Minute | M | Month |
71336
+ * | n | | N | |
71337
+ * | o! | Ordinal number modifier | O | Timezone (GMT) |
71338
+ * | p! | Long localized time | P! | Long localized date |
71339
+ * | q | Stand-alone quarter | Q | Quarter |
71340
+ * | r* | Related Gregorian year | R! | ISO week-numbering year |
71341
+ * | s | Second | S | Fraction of second |
71342
+ * | t! | Seconds timestamp | T! | Milliseconds timestamp |
71343
+ * | u | Extended year | U* | Cyclic year |
71344
+ * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
71345
+ * | w | Local week of year | W* | Week of month |
71346
+ * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
71347
+ * | y | Year (abs) | Y | Local week-numbering year |
71348
+ * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
71349
+ *
71350
+ * Letters marked by * are not implemented but reserved by Unicode standard.
71351
+ *
71352
+ * Letters marked by ! are non-standard, but implemented by date-fns:
71353
+ * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
71354
+ * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
71355
+ * i.e. 7 for Sunday, 1 for Monday, etc.
71356
+ * - `I` is ISO week of year, as opposed to `w` which is local week of year.
71357
+ * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
71358
+ * `R` is supposed to be used in conjunction with `I` and `i`
71359
+ * for universal ISO week-numbering date, whereas
71360
+ * `Y` is supposed to be used in conjunction with `w` and `e`
71361
+ * for week-numbering date specific to the locale.
71362
+ * - `P` is long localized date format
71363
+ * - `p` is long localized time format
71364
+ */
71365
+
71366
+ const formatters = {
71367
+ // Era
71368
+ G: function (date, token, localize) {
71369
+ const era = date.getFullYear() > 0 ? 1 : 0;
71370
+ switch (token) {
71371
+ // AD, BC
71372
+ case "G":
71373
+ case "GG":
71374
+ case "GGG":
71375
+ return localize.era(era, { width: "abbreviated" });
71376
+ // A, B
71377
+ case "GGGGG":
71378
+ return localize.era(era, { width: "narrow" });
71379
+ // Anno Domini, Before Christ
71380
+ case "GGGG":
71381
+ default:
71382
+ return localize.era(era, { width: "wide" });
71383
+ }
71384
+ },
71385
+
71386
+ // Year
71387
+ y: function (date, token, localize) {
71388
+ // Ordinal number
71389
+ if (token === "yo") {
71390
+ const signedYear = date.getFullYear();
71391
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
71392
+ const year = signedYear > 0 ? signedYear : 1 - signedYear;
71393
+ return localize.ordinalNumber(year, { unit: "year" });
71394
+ }
71395
+
71396
+ return lightFormatters.y(date, token);
71397
+ },
71398
+
71399
+ // Local week-numbering year
71400
+ Y: function (date, token, localize, options) {
71401
+ const signedWeekYear = getWeekYear(date, options);
71402
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
71403
+ const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
71404
+
71405
+ // Two digit year
71406
+ if (token === "YY") {
71407
+ const twoDigitYear = weekYear % 100;
71408
+ return addLeadingZeros(twoDigitYear, 2);
71409
+ }
71410
+
71411
+ // Ordinal number
71412
+ if (token === "Yo") {
71413
+ return localize.ordinalNumber(weekYear, { unit: "year" });
71414
+ }
71415
+
71416
+ // Padding
71417
+ return addLeadingZeros(weekYear, token.length);
71418
+ },
71419
+
71420
+ // ISO week-numbering year
71421
+ R: function (date, token) {
71422
+ const isoWeekYear = getISOWeekYear(date);
71423
+
71424
+ // Padding
71425
+ return addLeadingZeros(isoWeekYear, token.length);
71426
+ },
71427
+
71428
+ // Extended year. This is a single number designating the year of this calendar system.
71429
+ // The main difference between `y` and `u` localizers are B.C. years:
71430
+ // | Year | `y` | `u` |
71431
+ // |------|-----|-----|
71432
+ // | AC 1 | 1 | 1 |
71433
+ // | BC 1 | 1 | 0 |
71434
+ // | BC 2 | 2 | -1 |
71435
+ // Also `yy` always returns the last two digits of a year,
71436
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
71437
+ u: function (date, token) {
71438
+ const year = date.getFullYear();
71439
+ return addLeadingZeros(year, token.length);
71440
+ },
71441
+
71442
+ // Quarter
71443
+ Q: function (date, token, localize) {
71444
+ const quarter = Math.ceil((date.getMonth() + 1) / 3);
71445
+ switch (token) {
71446
+ // 1, 2, 3, 4
71447
+ case "Q":
71448
+ return String(quarter);
71449
+ // 01, 02, 03, 04
71450
+ case "QQ":
71451
+ return addLeadingZeros(quarter, 2);
71452
+ // 1st, 2nd, 3rd, 4th
71453
+ case "Qo":
71454
+ return localize.ordinalNumber(quarter, { unit: "quarter" });
71455
+ // Q1, Q2, Q3, Q4
71456
+ case "QQQ":
71457
+ return localize.quarter(quarter, {
71458
+ width: "abbreviated",
71459
+ context: "formatting",
71460
+ });
71461
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
71462
+ case "QQQQQ":
71463
+ return localize.quarter(quarter, {
71464
+ width: "narrow",
71465
+ context: "formatting",
71466
+ });
71467
+ // 1st quarter, 2nd quarter, ...
71468
+ case "QQQQ":
71469
+ default:
71470
+ return localize.quarter(quarter, {
71471
+ width: "wide",
71472
+ context: "formatting",
71473
+ });
71474
+ }
71475
+ },
71476
+
71477
+ // Stand-alone quarter
71478
+ q: function (date, token, localize) {
71479
+ const quarter = Math.ceil((date.getMonth() + 1) / 3);
71480
+ switch (token) {
71481
+ // 1, 2, 3, 4
71482
+ case "q":
71483
+ return String(quarter);
71484
+ // 01, 02, 03, 04
71485
+ case "qq":
71486
+ return addLeadingZeros(quarter, 2);
71487
+ // 1st, 2nd, 3rd, 4th
71488
+ case "qo":
71489
+ return localize.ordinalNumber(quarter, { unit: "quarter" });
71490
+ // Q1, Q2, Q3, Q4
71491
+ case "qqq":
71492
+ return localize.quarter(quarter, {
71493
+ width: "abbreviated",
71494
+ context: "standalone",
71495
+ });
71496
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
71497
+ case "qqqqq":
71498
+ return localize.quarter(quarter, {
71499
+ width: "narrow",
71500
+ context: "standalone",
71501
+ });
71502
+ // 1st quarter, 2nd quarter, ...
71503
+ case "qqqq":
71504
+ default:
71505
+ return localize.quarter(quarter, {
71506
+ width: "wide",
71507
+ context: "standalone",
71508
+ });
71509
+ }
71510
+ },
71511
+
71512
+ // Month
71513
+ M: function (date, token, localize) {
71514
+ const month = date.getMonth();
71515
+ switch (token) {
71516
+ case "M":
71517
+ case "MM":
71518
+ return lightFormatters.M(date, token);
71519
+ // 1st, 2nd, ..., 12th
71520
+ case "Mo":
71521
+ return localize.ordinalNumber(month + 1, { unit: "month" });
71522
+ // Jan, Feb, ..., Dec
71523
+ case "MMM":
71524
+ return localize.month(month, {
71525
+ width: "abbreviated",
71526
+ context: "formatting",
71527
+ });
71528
+ // J, F, ..., D
71529
+ case "MMMMM":
71530
+ return localize.month(month, {
71531
+ width: "narrow",
71532
+ context: "formatting",
71533
+ });
71534
+ // January, February, ..., December
71535
+ case "MMMM":
71536
+ default:
71537
+ return localize.month(month, { width: "wide", context: "formatting" });
71538
+ }
71539
+ },
71540
+
71541
+ // Stand-alone month
71542
+ L: function (date, token, localize) {
71543
+ const month = date.getMonth();
71544
+ switch (token) {
71545
+ // 1, 2, ..., 12
71546
+ case "L":
71547
+ return String(month + 1);
71548
+ // 01, 02, ..., 12
71549
+ case "LL":
71550
+ return addLeadingZeros(month + 1, 2);
71551
+ // 1st, 2nd, ..., 12th
71552
+ case "Lo":
71553
+ return localize.ordinalNumber(month + 1, { unit: "month" });
71554
+ // Jan, Feb, ..., Dec
71555
+ case "LLL":
71556
+ return localize.month(month, {
71557
+ width: "abbreviated",
71558
+ context: "standalone",
71559
+ });
71560
+ // J, F, ..., D
71561
+ case "LLLLL":
71562
+ return localize.month(month, {
71563
+ width: "narrow",
71564
+ context: "standalone",
71565
+ });
71566
+ // January, February, ..., December
71567
+ case "LLLL":
71568
+ default:
71569
+ return localize.month(month, { width: "wide", context: "standalone" });
71570
+ }
71571
+ },
71572
+
71573
+ // Local week of year
71574
+ w: function (date, token, localize, options) {
71575
+ const week = getWeek(date, options);
71576
+
71577
+ if (token === "wo") {
71578
+ return localize.ordinalNumber(week, { unit: "week" });
71579
+ }
71580
+
71581
+ return addLeadingZeros(week, token.length);
71582
+ },
71583
+
71584
+ // ISO week of year
71585
+ I: function (date, token, localize) {
71586
+ const isoWeek = getISOWeek(date);
71587
+
71588
+ if (token === "Io") {
71589
+ return localize.ordinalNumber(isoWeek, { unit: "week" });
71590
+ }
71591
+
71592
+ return addLeadingZeros(isoWeek, token.length);
71593
+ },
71594
+
71595
+ // Day of the month
71596
+ d: function (date, token, localize) {
71597
+ if (token === "do") {
71598
+ return localize.ordinalNumber(date.getDate(), { unit: "date" });
71599
+ }
71600
+
71601
+ return lightFormatters.d(date, token);
71602
+ },
71603
+
71604
+ // Day of year
71605
+ D: function (date, token, localize) {
71606
+ const dayOfYear = getDayOfYear(date);
71607
+
71608
+ if (token === "Do") {
71609
+ return localize.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
71610
+ }
71611
+
71612
+ return addLeadingZeros(dayOfYear, token.length);
71613
+ },
71614
+
71615
+ // Day of week
71616
+ E: function (date, token, localize) {
71617
+ const dayOfWeek = date.getDay();
71618
+ switch (token) {
71619
+ // Tue
71620
+ case "E":
71621
+ case "EE":
71622
+ case "EEE":
71623
+ return localize.day(dayOfWeek, {
71624
+ width: "abbreviated",
71625
+ context: "formatting",
71626
+ });
71627
+ // T
71628
+ case "EEEEE":
71629
+ return localize.day(dayOfWeek, {
71630
+ width: "narrow",
71631
+ context: "formatting",
71632
+ });
71633
+ // Tu
71634
+ case "EEEEEE":
71635
+ return localize.day(dayOfWeek, {
71636
+ width: "short",
71637
+ context: "formatting",
71638
+ });
71639
+ // Tuesday
71640
+ case "EEEE":
71641
+ default:
71642
+ return localize.day(dayOfWeek, {
71643
+ width: "wide",
71644
+ context: "formatting",
71645
+ });
71646
+ }
71647
+ },
71648
+
71649
+ // Local day of week
71650
+ e: function (date, token, localize, options) {
71651
+ const dayOfWeek = date.getDay();
71652
+ const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
71653
+ switch (token) {
71654
+ // Numerical value (Nth day of week with current locale or weekStartsOn)
71655
+ case "e":
71656
+ return String(localDayOfWeek);
71657
+ // Padded numerical value
71658
+ case "ee":
71659
+ return addLeadingZeros(localDayOfWeek, 2);
71660
+ // 1st, 2nd, ..., 7th
71661
+ case "eo":
71662
+ return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
71663
+ case "eee":
71664
+ return localize.day(dayOfWeek, {
71665
+ width: "abbreviated",
71666
+ context: "formatting",
71667
+ });
71668
+ // T
71669
+ case "eeeee":
71670
+ return localize.day(dayOfWeek, {
71671
+ width: "narrow",
71672
+ context: "formatting",
71673
+ });
71674
+ // Tu
71675
+ case "eeeeee":
71676
+ return localize.day(dayOfWeek, {
71677
+ width: "short",
71678
+ context: "formatting",
71679
+ });
71680
+ // Tuesday
71681
+ case "eeee":
71682
+ default:
71683
+ return localize.day(dayOfWeek, {
71684
+ width: "wide",
71685
+ context: "formatting",
71686
+ });
71687
+ }
71688
+ },
71689
+
71690
+ // Stand-alone local day of week
71691
+ c: function (date, token, localize, options) {
71692
+ const dayOfWeek = date.getDay();
71693
+ const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
71694
+ switch (token) {
71695
+ // Numerical value (same as in `e`)
71696
+ case "c":
71697
+ return String(localDayOfWeek);
71698
+ // Padded numerical value
71699
+ case "cc":
71700
+ return addLeadingZeros(localDayOfWeek, token.length);
71701
+ // 1st, 2nd, ..., 7th
71702
+ case "co":
71703
+ return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
71704
+ case "ccc":
71705
+ return localize.day(dayOfWeek, {
71706
+ width: "abbreviated",
71707
+ context: "standalone",
71708
+ });
71709
+ // T
71710
+ case "ccccc":
71711
+ return localize.day(dayOfWeek, {
71712
+ width: "narrow",
71713
+ context: "standalone",
71714
+ });
71715
+ // Tu
71716
+ case "cccccc":
71717
+ return localize.day(dayOfWeek, {
71718
+ width: "short",
71719
+ context: "standalone",
71720
+ });
71721
+ // Tuesday
71722
+ case "cccc":
71723
+ default:
71724
+ return localize.day(dayOfWeek, {
71725
+ width: "wide",
71726
+ context: "standalone",
71727
+ });
71728
+ }
71729
+ },
71730
+
71731
+ // ISO day of week
71732
+ i: function (date, token, localize) {
71733
+ const dayOfWeek = date.getDay();
71734
+ const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
71735
+ switch (token) {
71736
+ // 2
71737
+ case "i":
71738
+ return String(isoDayOfWeek);
71739
+ // 02
71740
+ case "ii":
71741
+ return addLeadingZeros(isoDayOfWeek, token.length);
71742
+ // 2nd
71743
+ case "io":
71744
+ return localize.ordinalNumber(isoDayOfWeek, { unit: "day" });
71745
+ // Tue
71746
+ case "iii":
71747
+ return localize.day(dayOfWeek, {
71748
+ width: "abbreviated",
71749
+ context: "formatting",
71750
+ });
71751
+ // T
71752
+ case "iiiii":
71753
+ return localize.day(dayOfWeek, {
71754
+ width: "narrow",
71755
+ context: "formatting",
71756
+ });
71757
+ // Tu
71758
+ case "iiiiii":
71759
+ return localize.day(dayOfWeek, {
71760
+ width: "short",
71761
+ context: "formatting",
71762
+ });
71763
+ // Tuesday
71764
+ case "iiii":
71765
+ default:
71766
+ return localize.day(dayOfWeek, {
71767
+ width: "wide",
71768
+ context: "formatting",
71769
+ });
71770
+ }
71771
+ },
71772
+
71773
+ // AM or PM
71774
+ a: function (date, token, localize) {
71775
+ const hours = date.getHours();
71776
+ const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
71777
+
71778
+ switch (token) {
71779
+ case "a":
71780
+ case "aa":
71781
+ return localize.dayPeriod(dayPeriodEnumValue, {
71782
+ width: "abbreviated",
71783
+ context: "formatting",
71784
+ });
71785
+ case "aaa":
71786
+ return localize
71787
+ .dayPeriod(dayPeriodEnumValue, {
71788
+ width: "abbreviated",
71789
+ context: "formatting",
71790
+ })
71791
+ .toLowerCase();
71792
+ case "aaaaa":
71793
+ return localize.dayPeriod(dayPeriodEnumValue, {
71794
+ width: "narrow",
71795
+ context: "formatting",
71796
+ });
71797
+ case "aaaa":
71798
+ default:
71799
+ return localize.dayPeriod(dayPeriodEnumValue, {
71800
+ width: "wide",
71801
+ context: "formatting",
71802
+ });
71803
+ }
71804
+ },
71805
+
71806
+ // AM, PM, midnight, noon
71807
+ b: function (date, token, localize) {
71808
+ const hours = date.getHours();
71809
+ let dayPeriodEnumValue;
71810
+ if (hours === 12) {
71811
+ dayPeriodEnumValue = dayPeriodEnum.noon;
71812
+ } else if (hours === 0) {
71813
+ dayPeriodEnumValue = dayPeriodEnum.midnight;
71814
+ } else {
71815
+ dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
71816
+ }
71817
+
71818
+ switch (token) {
71819
+ case "b":
71820
+ case "bb":
71821
+ return localize.dayPeriod(dayPeriodEnumValue, {
71822
+ width: "abbreviated",
71823
+ context: "formatting",
71824
+ });
71825
+ case "bbb":
71826
+ return localize
71827
+ .dayPeriod(dayPeriodEnumValue, {
71828
+ width: "abbreviated",
71829
+ context: "formatting",
71830
+ })
71831
+ .toLowerCase();
71832
+ case "bbbbb":
71833
+ return localize.dayPeriod(dayPeriodEnumValue, {
71834
+ width: "narrow",
71835
+ context: "formatting",
71836
+ });
71837
+ case "bbbb":
71838
+ default:
71839
+ return localize.dayPeriod(dayPeriodEnumValue, {
71840
+ width: "wide",
71841
+ context: "formatting",
71842
+ });
71843
+ }
71844
+ },
71845
+
71846
+ // in the morning, in the afternoon, in the evening, at night
71847
+ B: function (date, token, localize) {
71848
+ const hours = date.getHours();
71849
+ let dayPeriodEnumValue;
71850
+ if (hours >= 17) {
71851
+ dayPeriodEnumValue = dayPeriodEnum.evening;
71852
+ } else if (hours >= 12) {
71853
+ dayPeriodEnumValue = dayPeriodEnum.afternoon;
71854
+ } else if (hours >= 4) {
71855
+ dayPeriodEnumValue = dayPeriodEnum.morning;
71856
+ } else {
71857
+ dayPeriodEnumValue = dayPeriodEnum.night;
71858
+ }
71859
+
71860
+ switch (token) {
71861
+ case "B":
71862
+ case "BB":
71863
+ case "BBB":
71864
+ return localize.dayPeriod(dayPeriodEnumValue, {
71865
+ width: "abbreviated",
71866
+ context: "formatting",
71867
+ });
71868
+ case "BBBBB":
71869
+ return localize.dayPeriod(dayPeriodEnumValue, {
71870
+ width: "narrow",
71871
+ context: "formatting",
71872
+ });
71873
+ case "BBBB":
71874
+ default:
71875
+ return localize.dayPeriod(dayPeriodEnumValue, {
71876
+ width: "wide",
71877
+ context: "formatting",
71878
+ });
71879
+ }
71880
+ },
71881
+
71882
+ // Hour [1-12]
71883
+ h: function (date, token, localize) {
71884
+ if (token === "ho") {
71885
+ let hours = date.getHours() % 12;
71886
+ if (hours === 0) hours = 12;
71887
+ return localize.ordinalNumber(hours, { unit: "hour" });
71888
+ }
71889
+
71890
+ return lightFormatters.h(date, token);
71891
+ },
71892
+
71893
+ // Hour [0-23]
71894
+ H: function (date, token, localize) {
71895
+ if (token === "Ho") {
71896
+ return localize.ordinalNumber(date.getHours(), { unit: "hour" });
71897
+ }
71898
+
71899
+ return lightFormatters.H(date, token);
71900
+ },
71901
+
71902
+ // Hour [0-11]
71903
+ K: function (date, token, localize) {
71904
+ const hours = date.getHours() % 12;
71905
+
71906
+ if (token === "Ko") {
71907
+ return localize.ordinalNumber(hours, { unit: "hour" });
71908
+ }
71909
+
71910
+ return addLeadingZeros(hours, token.length);
71911
+ },
71912
+
71913
+ // Hour [1-24]
71914
+ k: function (date, token, localize) {
71915
+ let hours = date.getHours();
71916
+ if (hours === 0) hours = 24;
71917
+
71918
+ if (token === "ko") {
71919
+ return localize.ordinalNumber(hours, { unit: "hour" });
71920
+ }
71921
+
71922
+ return addLeadingZeros(hours, token.length);
71923
+ },
71924
+
71925
+ // Minute
71926
+ m: function (date, token, localize) {
71927
+ if (token === "mo") {
71928
+ return localize.ordinalNumber(date.getMinutes(), { unit: "minute" });
71929
+ }
71930
+
71931
+ return lightFormatters.m(date, token);
71932
+ },
71933
+
71934
+ // Second
71935
+ s: function (date, token, localize) {
71936
+ if (token === "so") {
71937
+ return localize.ordinalNumber(date.getSeconds(), { unit: "second" });
71938
+ }
71939
+
71940
+ return lightFormatters.s(date, token);
71941
+ },
71942
+
71943
+ // Fraction of second
71944
+ S: function (date, token) {
71945
+ return lightFormatters.S(date, token);
71946
+ },
71947
+
71948
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
71949
+ X: function (date, token, _localize) {
71950
+ const timezoneOffset = date.getTimezoneOffset();
71951
+
71952
+ if (timezoneOffset === 0) {
71953
+ return "Z";
71954
+ }
71955
+
71956
+ switch (token) {
71957
+ // Hours and optional minutes
71958
+ case "X":
71959
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
71960
+
71961
+ // Hours, minutes and optional seconds without `:` delimiter
71962
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
71963
+ // so this token always has the same output as `XX`
71964
+ case "XXXX":
71965
+ case "XX": // Hours and minutes without `:` delimiter
71966
+ return formatTimezone(timezoneOffset);
71967
+
71968
+ // Hours, minutes and optional seconds with `:` delimiter
71969
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
71970
+ // so this token always has the same output as `XXX`
71971
+ case "XXXXX":
71972
+ case "XXX": // Hours and minutes with `:` delimiter
71973
+ default:
71974
+ return formatTimezone(timezoneOffset, ":");
71975
+ }
71976
+ },
71977
+
71978
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
71979
+ x: function (date, token, _localize) {
71980
+ const timezoneOffset = date.getTimezoneOffset();
71981
+
71982
+ switch (token) {
71983
+ // Hours and optional minutes
71984
+ case "x":
71985
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
71986
+
71987
+ // Hours, minutes and optional seconds without `:` delimiter
71988
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
71989
+ // so this token always has the same output as `xx`
71990
+ case "xxxx":
71991
+ case "xx": // Hours and minutes without `:` delimiter
71992
+ return formatTimezone(timezoneOffset);
71993
+
71994
+ // Hours, minutes and optional seconds with `:` delimiter
71995
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
71996
+ // so this token always has the same output as `xxx`
71997
+ case "xxxxx":
71998
+ case "xxx": // Hours and minutes with `:` delimiter
71999
+ default:
72000
+ return formatTimezone(timezoneOffset, ":");
72001
+ }
72002
+ },
72003
+
72004
+ // Timezone (GMT)
72005
+ O: function (date, token, _localize) {
72006
+ const timezoneOffset = date.getTimezoneOffset();
72007
+
72008
+ switch (token) {
72009
+ // Short
72010
+ case "O":
72011
+ case "OO":
72012
+ case "OOO":
72013
+ return "GMT" + formatTimezoneShort(timezoneOffset, ":");
72014
+ // Long
72015
+ case "OOOO":
72016
+ default:
72017
+ return "GMT" + formatTimezone(timezoneOffset, ":");
72018
+ }
72019
+ },
72020
+
72021
+ // Timezone (specific non-location)
72022
+ z: function (date, token, _localize) {
72023
+ const timezoneOffset = date.getTimezoneOffset();
72024
+
72025
+ switch (token) {
72026
+ // Short
72027
+ case "z":
72028
+ case "zz":
72029
+ case "zzz":
72030
+ return "GMT" + formatTimezoneShort(timezoneOffset, ":");
72031
+ // Long
72032
+ case "zzzz":
72033
+ default:
72034
+ return "GMT" + formatTimezone(timezoneOffset, ":");
72035
+ }
72036
+ },
72037
+
72038
+ // Seconds timestamp
72039
+ t: function (date, token, _localize) {
72040
+ const timestamp = Math.trunc(+date / 1000);
72041
+ return addLeadingZeros(timestamp, token.length);
72042
+ },
72043
+
72044
+ // Milliseconds timestamp
72045
+ T: function (date, token, _localize) {
72046
+ return addLeadingZeros(+date, token.length);
72047
+ },
72048
+ };
72049
+
72050
+ function formatTimezoneShort(offset, delimiter = "") {
72051
+ const sign = offset > 0 ? "-" : "+";
72052
+ const absOffset = Math.abs(offset);
72053
+ const hours = Math.trunc(absOffset / 60);
72054
+ const minutes = absOffset % 60;
72055
+ if (minutes === 0) {
72056
+ return sign + String(hours);
72057
+ }
72058
+ return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
72059
+ }
72060
+
72061
+ function formatTimezoneWithOptionalMinutes(offset, delimiter) {
72062
+ if (offset % 60 === 0) {
72063
+ const sign = offset > 0 ? "-" : "+";
72064
+ return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
72065
+ }
72066
+ return formatTimezone(offset, delimiter);
72067
+ }
72068
+
72069
+ function formatTimezone(offset, delimiter = "") {
72070
+ const sign = offset > 0 ? "-" : "+";
72071
+ const absOffset = Math.abs(offset);
72072
+ const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
72073
+ const minutes = addLeadingZeros(absOffset % 60, 2);
72074
+ return sign + hours + delimiter + minutes;
72075
+ }
72076
+
72077
+ const dateLongFormatter = (pattern, formatLong) => {
72078
+ switch (pattern) {
72079
+ case "P":
72080
+ return formatLong.date({ width: "short" });
72081
+ case "PP":
72082
+ return formatLong.date({ width: "medium" });
72083
+ case "PPP":
72084
+ return formatLong.date({ width: "long" });
72085
+ case "PPPP":
72086
+ default:
72087
+ return formatLong.date({ width: "full" });
72088
+ }
72089
+ };
72090
+
72091
+ const timeLongFormatter = (pattern, formatLong) => {
72092
+ switch (pattern) {
72093
+ case "p":
72094
+ return formatLong.time({ width: "short" });
72095
+ case "pp":
72096
+ return formatLong.time({ width: "medium" });
72097
+ case "ppp":
72098
+ return formatLong.time({ width: "long" });
72099
+ case "pppp":
72100
+ default:
72101
+ return formatLong.time({ width: "full" });
72102
+ }
72103
+ };
72104
+
72105
+ const dateTimeLongFormatter = (pattern, formatLong) => {
72106
+ const matchResult = pattern.match(/(P+)(p+)?/) || [];
72107
+ const datePattern = matchResult[1];
72108
+ const timePattern = matchResult[2];
72109
+
72110
+ if (!timePattern) {
72111
+ return dateLongFormatter(pattern, formatLong);
72112
+ }
72113
+
72114
+ let dateTimeFormat;
72115
+
72116
+ switch (datePattern) {
72117
+ case "P":
72118
+ dateTimeFormat = formatLong.dateTime({ width: "short" });
72119
+ break;
72120
+ case "PP":
72121
+ dateTimeFormat = formatLong.dateTime({ width: "medium" });
72122
+ break;
72123
+ case "PPP":
72124
+ dateTimeFormat = formatLong.dateTime({ width: "long" });
72125
+ break;
72126
+ case "PPPP":
72127
+ default:
72128
+ dateTimeFormat = formatLong.dateTime({ width: "full" });
72129
+ break;
72130
+ }
72131
+
72132
+ return dateTimeFormat
72133
+ .replace("{{date}}", dateLongFormatter(datePattern, formatLong))
72134
+ .replace("{{time}}", timeLongFormatter(timePattern, formatLong));
72135
+ };
72136
+
72137
+ const longFormatters = {
72138
+ p: timeLongFormatter,
72139
+ P: dateTimeLongFormatter,
72140
+ };
72141
+
72142
+ const dayOfYearTokenRE = /^D+$/;
72143
+ const weekYearTokenRE = /^Y+$/;
72144
+
72145
+ const throwTokens = ["D", "DD", "YY", "YYYY"];
72146
+
72147
+ function isProtectedDayOfYearToken(token) {
72148
+ return dayOfYearTokenRE.test(token);
72149
+ }
72150
+
72151
+ function isProtectedWeekYearToken(token) {
72152
+ return weekYearTokenRE.test(token);
72153
+ }
72154
+
72155
+ function warnOrThrowProtectedError(token, format, input) {
72156
+ const _message = message(token, format, input);
72157
+ console.warn(_message);
72158
+ if (throwTokens.includes(token)) throw new RangeError(_message);
72159
+ }
72160
+
72161
+ function message(token, format, input) {
72162
+ const subject = token[0] === "Y" ? "years" : "days of the month";
72163
+ 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`;
72164
+ }
72165
+
72166
+ // This RegExp consists of three parts separated by `|`:
72167
+ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
72168
+ // (one of the certain letters followed by `o`)
72169
+ // - (\w)\1* matches any sequences of the same letter
72170
+ // - '' matches two quote characters in a row
72171
+ // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
72172
+ // except a single quote symbol, which ends the sequence.
72173
+ // Two quote characters do not end the sequence.
72174
+ // If there is no matching single quote
72175
+ // then the sequence will continue until the end of the string.
72176
+ // - . matches any single character unmatched by previous parts of the RegExps
72177
+ const formattingTokensRegExp =
72178
+ /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
72179
+
72180
+ // This RegExp catches symbols escaped by quotes, and also
72181
+ // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
72182
+ const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
72183
+
72184
+ const escapedStringRegExp = /^'([^]*?)'?$/;
72185
+ const doubleQuoteRegExp = /''/g;
72186
+ const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
72187
+
72188
+ /**
72189
+ * The {@link format} function options.
72190
+ */
72191
+
72192
+ /**
72193
+ * @name format
72194
+ * @alias formatDate
72195
+ * @category Common Helpers
72196
+ * @summary Format the date.
72197
+ *
72198
+ * @description
72199
+ * Return the formatted date string in the given format. The result may vary by locale.
72200
+ *
72201
+ * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
72202
+ * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
72203
+ *
72204
+ * The characters wrapped between two single quotes characters (') are escaped.
72205
+ * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
72206
+ * (see the last example)
72207
+ *
72208
+ * Format of the string is based on Unicode Technical Standard #35:
72209
+ * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
72210
+ * with a few additions (see note 7 below the table).
72211
+ *
72212
+ * Accepted patterns:
72213
+ * | Unit | Pattern | Result examples | Notes |
72214
+ * |---------------------------------|---------|-----------------------------------|-------|
72215
+ * | Era | G..GGG | AD, BC | |
72216
+ * | | GGGG | Anno Domini, Before Christ | 2 |
72217
+ * | | GGGGG | A, B | |
72218
+ * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
72219
+ * | | yo | 44th, 1st, 0th, 17th | 5,7 |
72220
+ * | | yy | 44, 01, 00, 17 | 5 |
72221
+ * | | yyy | 044, 001, 1900, 2017 | 5 |
72222
+ * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
72223
+ * | | yyyyy | ... | 3,5 |
72224
+ * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
72225
+ * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
72226
+ * | | YY | 44, 01, 00, 17 | 5,8 |
72227
+ * | | YYY | 044, 001, 1900, 2017 | 5 |
72228
+ * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
72229
+ * | | YYYYY | ... | 3,5 |
72230
+ * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
72231
+ * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
72232
+ * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
72233
+ * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
72234
+ * | | RRRRR | ... | 3,5,7 |
72235
+ * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
72236
+ * | | uu | -43, 01, 1900, 2017 | 5 |
72237
+ * | | uuu | -043, 001, 1900, 2017 | 5 |
72238
+ * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
72239
+ * | | uuuuu | ... | 3,5 |
72240
+ * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
72241
+ * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
72242
+ * | | QQ | 01, 02, 03, 04 | |
72243
+ * | | QQQ | Q1, Q2, Q3, Q4 | |
72244
+ * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
72245
+ * | | QQQQQ | 1, 2, 3, 4 | 4 |
72246
+ * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
72247
+ * | | qo | 1st, 2nd, 3rd, 4th | 7 |
72248
+ * | | qq | 01, 02, 03, 04 | |
72249
+ * | | qqq | Q1, Q2, Q3, Q4 | |
72250
+ * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
72251
+ * | | qqqqq | 1, 2, 3, 4 | 4 |
72252
+ * | Month (formatting) | M | 1, 2, ..., 12 | |
72253
+ * | | Mo | 1st, 2nd, ..., 12th | 7 |
72254
+ * | | MM | 01, 02, ..., 12 | |
72255
+ * | | MMM | Jan, Feb, ..., Dec | |
72256
+ * | | MMMM | January, February, ..., December | 2 |
72257
+ * | | MMMMM | J, F, ..., D | |
72258
+ * | Month (stand-alone) | L | 1, 2, ..., 12 | |
72259
+ * | | Lo | 1st, 2nd, ..., 12th | 7 |
72260
+ * | | LL | 01, 02, ..., 12 | |
72261
+ * | | LLL | Jan, Feb, ..., Dec | |
72262
+ * | | LLLL | January, February, ..., December | 2 |
72263
+ * | | LLLLL | J, F, ..., D | |
72264
+ * | Local week of year | w | 1, 2, ..., 53 | |
72265
+ * | | wo | 1st, 2nd, ..., 53th | 7 |
72266
+ * | | ww | 01, 02, ..., 53 | |
72267
+ * | ISO week of year | I | 1, 2, ..., 53 | 7 |
72268
+ * | | Io | 1st, 2nd, ..., 53th | 7 |
72269
+ * | | II | 01, 02, ..., 53 | 7 |
72270
+ * | Day of month | d | 1, 2, ..., 31 | |
72271
+ * | | do | 1st, 2nd, ..., 31st | 7 |
72272
+ * | | dd | 01, 02, ..., 31 | |
72273
+ * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
72274
+ * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
72275
+ * | | DD | 01, 02, ..., 365, 366 | 9 |
72276
+ * | | DDD | 001, 002, ..., 365, 366 | |
72277
+ * | | DDDD | ... | 3 |
72278
+ * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
72279
+ * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
72280
+ * | | EEEEE | M, T, W, T, F, S, S | |
72281
+ * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
72282
+ * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
72283
+ * | | io | 1st, 2nd, ..., 7th | 7 |
72284
+ * | | ii | 01, 02, ..., 07 | 7 |
72285
+ * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
72286
+ * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
72287
+ * | | iiiii | M, T, W, T, F, S, S | 7 |
72288
+ * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
72289
+ * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
72290
+ * | | eo | 2nd, 3rd, ..., 1st | 7 |
72291
+ * | | ee | 02, 03, ..., 01 | |
72292
+ * | | eee | Mon, Tue, Wed, ..., Sun | |
72293
+ * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
72294
+ * | | eeeee | M, T, W, T, F, S, S | |
72295
+ * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
72296
+ * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
72297
+ * | | co | 2nd, 3rd, ..., 1st | 7 |
72298
+ * | | cc | 02, 03, ..., 01 | |
72299
+ * | | ccc | Mon, Tue, Wed, ..., Sun | |
72300
+ * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
72301
+ * | | ccccc | M, T, W, T, F, S, S | |
72302
+ * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
72303
+ * | AM, PM | a..aa | AM, PM | |
72304
+ * | | aaa | am, pm | |
72305
+ * | | aaaa | a.m., p.m. | 2 |
72306
+ * | | aaaaa | a, p | |
72307
+ * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
72308
+ * | | bbb | am, pm, noon, midnight | |
72309
+ * | | bbbb | a.m., p.m., noon, midnight | 2 |
72310
+ * | | bbbbb | a, p, n, mi | |
72311
+ * | Flexible day period | B..BBB | at night, in the morning, ... | |
72312
+ * | | BBBB | at night, in the morning, ... | 2 |
72313
+ * | | BBBBB | at night, in the morning, ... | |
72314
+ * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
72315
+ * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
72316
+ * | | hh | 01, 02, ..., 11, 12 | |
72317
+ * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
72318
+ * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
72319
+ * | | HH | 00, 01, 02, ..., 23 | |
72320
+ * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
72321
+ * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
72322
+ * | | KK | 01, 02, ..., 11, 00 | |
72323
+ * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
72324
+ * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
72325
+ * | | kk | 24, 01, 02, ..., 23 | |
72326
+ * | Minute | m | 0, 1, ..., 59 | |
72327
+ * | | mo | 0th, 1st, ..., 59th | 7 |
72328
+ * | | mm | 00, 01, ..., 59 | |
72329
+ * | Second | s | 0, 1, ..., 59 | |
72330
+ * | | so | 0th, 1st, ..., 59th | 7 |
72331
+ * | | ss | 00, 01, ..., 59 | |
72332
+ * | Fraction of second | S | 0, 1, ..., 9 | |
72333
+ * | | SS | 00, 01, ..., 99 | |
72334
+ * | | SSS | 000, 001, ..., 999 | |
72335
+ * | | SSSS | ... | 3 |
72336
+ * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
72337
+ * | | XX | -0800, +0530, Z | |
72338
+ * | | XXX | -08:00, +05:30, Z | |
72339
+ * | | XXXX | -0800, +0530, Z, +123456 | 2 |
72340
+ * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
72341
+ * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
72342
+ * | | xx | -0800, +0530, +0000 | |
72343
+ * | | xxx | -08:00, +05:30, +00:00 | 2 |
72344
+ * | | xxxx | -0800, +0530, +0000, +123456 | |
72345
+ * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
72346
+ * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
72347
+ * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
72348
+ * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
72349
+ * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
72350
+ * | Seconds timestamp | t | 512969520 | 7 |
72351
+ * | | tt | ... | 3,7 |
72352
+ * | Milliseconds timestamp | T | 512969520900 | 7 |
72353
+ * | | TT | ... | 3,7 |
72354
+ * | Long localized date | P | 04/29/1453 | 7 |
72355
+ * | | PP | Apr 29, 1453 | 7 |
72356
+ * | | PPP | April 29th, 1453 | 7 |
72357
+ * | | PPPP | Friday, April 29th, 1453 | 2,7 |
72358
+ * | Long localized time | p | 12:00 AM | 7 |
72359
+ * | | pp | 12:00:00 AM | 7 |
72360
+ * | | ppp | 12:00:00 AM GMT+2 | 7 |
72361
+ * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
72362
+ * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
72363
+ * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
72364
+ * | | PPPppp | April 29th, 1453 at ... | 7 |
72365
+ * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
72366
+ * Notes:
72367
+ * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
72368
+ * are the same as "stand-alone" units, but are different in some languages.
72369
+ * "Formatting" units are declined according to the rules of the language
72370
+ * in the context of a date. "Stand-alone" units are always nominative singular:
72371
+ *
72372
+ * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
72373
+ *
72374
+ * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
72375
+ *
72376
+ * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
72377
+ * the single quote characters (see below).
72378
+ * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
72379
+ * the output will be the same as default pattern for this unit, usually
72380
+ * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
72381
+ * are marked with "2" in the last column of the table.
72382
+ *
72383
+ * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
72384
+ *
72385
+ * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
72386
+ *
72387
+ * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
72388
+ *
72389
+ * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
72390
+ *
72391
+ * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
72392
+ *
72393
+ * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
72394
+ * The output will be padded with zeros to match the length of the pattern.
72395
+ *
72396
+ * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
72397
+ *
72398
+ * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
72399
+ * These tokens represent the shortest form of the quarter.
72400
+ *
72401
+ * 5. The main difference between `y` and `u` patterns are B.C. years:
72402
+ *
72403
+ * | Year | `y` | `u` |
72404
+ * |------|-----|-----|
72405
+ * | AC 1 | 1 | 1 |
72406
+ * | BC 1 | 1 | 0 |
72407
+ * | BC 2 | 2 | -1 |
72408
+ *
72409
+ * Also `yy` always returns the last two digits of a year,
72410
+ * while `uu` pads single digit years to 2 characters and returns other years unchanged:
72411
+ *
72412
+ * | Year | `yy` | `uu` |
72413
+ * |------|------|------|
72414
+ * | 1 | 01 | 01 |
72415
+ * | 14 | 14 | 14 |
72416
+ * | 376 | 76 | 376 |
72417
+ * | 1453 | 53 | 1453 |
72418
+ *
72419
+ * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
72420
+ * except local week-numbering years are dependent on `options.weekStartsOn`
72421
+ * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear)
72422
+ * and [getWeekYear](https://date-fns.org/docs/getWeekYear)).
72423
+ *
72424
+ * 6. Specific non-location timezones are currently unavailable in `date-fns`,
72425
+ * so right now these tokens fall back to GMT timezones.
72426
+ *
72427
+ * 7. These patterns are not in the Unicode Technical Standard #35:
72428
+ * - `i`: ISO day of week
72429
+ * - `I`: ISO week of year
72430
+ * - `R`: ISO week-numbering year
72431
+ * - `t`: seconds timestamp
72432
+ * - `T`: milliseconds timestamp
72433
+ * - `o`: ordinal number modifier
72434
+ * - `P`: long localized date
72435
+ * - `p`: long localized time
72436
+ *
72437
+ * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
72438
+ * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
72439
+ *
72440
+ * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
72441
+ * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
72442
+ *
72443
+ * @param date - The original date
72444
+ * @param format - The string of tokens
72445
+ * @param options - An object with options
72446
+ *
72447
+ * @returns The formatted date string
72448
+ *
72449
+ * @throws `date` must not be Invalid Date
72450
+ * @throws `options.locale` must contain `localize` property
72451
+ * @throws `options.locale` must contain `formatLong` property
72452
+ * @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
72453
+ * @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
72454
+ * @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
72455
+ * @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
72456
+ * @throws format string contains an unescaped latin alphabet character
72457
+ *
72458
+ * @example
72459
+ * // Represent 11 February 2014 in middle-endian format:
72460
+ * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
72461
+ * //=> '02/11/2014'
72462
+ *
72463
+ * @example
72464
+ * // Represent 2 July 2014 in Esperanto:
72465
+ * import { eoLocale } from 'date-fns/locale/eo'
72466
+ * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
72467
+ * locale: eoLocale
72468
+ * })
72469
+ * //=> '2-a de julio 2014'
72470
+ *
72471
+ * @example
72472
+ * // Escape string by single quote characters:
72473
+ * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
72474
+ * //=> "3 o'clock"
72475
+ */
72476
+ function format(date, formatStr, options) {
72477
+ const defaultOptions = getDefaultOptions();
72478
+ const locale = defaultOptions.locale ?? enUS;
72479
+
72480
+ const firstWeekContainsDate =
72481
+ defaultOptions.firstWeekContainsDate ??
72482
+ defaultOptions.locale?.options?.firstWeekContainsDate ??
72483
+ 1;
72484
+
72485
+ const weekStartsOn =
72486
+ defaultOptions.weekStartsOn ??
72487
+ defaultOptions.locale?.options?.weekStartsOn ??
72488
+ 0;
72489
+
72490
+ const originalDate = toDate(date, options?.in);
72491
+
72492
+ if (!isValid(originalDate)) {
72493
+ throw new RangeError("Invalid time value");
72494
+ }
72495
+
72496
+ let parts = formatStr
72497
+ .match(longFormattingTokensRegExp)
72498
+ .map((substring) => {
72499
+ const firstCharacter = substring[0];
72500
+ if (firstCharacter === "p" || firstCharacter === "P") {
72501
+ const longFormatter = longFormatters[firstCharacter];
72502
+ return longFormatter(substring, locale.formatLong);
72503
+ }
72504
+ return substring;
72505
+ })
72506
+ .join("")
72507
+ .match(formattingTokensRegExp)
72508
+ .map((substring) => {
72509
+ // Replace two single quote characters with one single quote character
72510
+ if (substring === "''") {
72511
+ return { isToken: false, value: "'" };
72512
+ }
72513
+
72514
+ const firstCharacter = substring[0];
72515
+ if (firstCharacter === "'") {
72516
+ return { isToken: false, value: cleanEscapedString(substring) };
72517
+ }
72518
+
72519
+ if (formatters[firstCharacter]) {
72520
+ return { isToken: true, value: substring };
72521
+ }
72522
+
72523
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
72524
+ throw new RangeError(
72525
+ "Format string contains an unescaped latin alphabet character `" +
72526
+ firstCharacter +
72527
+ "`",
72528
+ );
72529
+ }
72530
+
72531
+ return { isToken: false, value: substring };
72532
+ });
72533
+
72534
+ // invoke localize preprocessor (only for french locales at the moment)
72535
+ if (locale.localize.preprocessor) {
72536
+ parts = locale.localize.preprocessor(originalDate, parts);
72537
+ }
72538
+
72539
+ const formatterOptions = {
72540
+ firstWeekContainsDate,
72541
+ weekStartsOn,
72542
+ locale,
72543
+ };
72544
+
72545
+ return parts
72546
+ .map((part) => {
72547
+ if (!part.isToken) return part.value;
72548
+
72549
+ const token = part.value;
72550
+
72551
+ if (
72552
+ (isProtectedWeekYearToken(token)) ||
72553
+ (isProtectedDayOfYearToken(token))
72554
+ ) {
72555
+ warnOrThrowProtectedError(token, formatStr, String(date));
72556
+ }
72557
+
72558
+ const formatter = formatters[token[0]];
72559
+ return formatter(originalDate, token, locale.localize, formatterOptions);
72560
+ })
72561
+ .join("");
72562
+ }
72563
+
72564
+ function cleanEscapedString(input) {
72565
+ const matched = input.match(escapedStringRegExp);
72566
+
72567
+ if (!matched) {
72568
+ return input;
72569
+ }
72570
+
72571
+ return matched[1].replace(doubleQuoteRegExp, "'");
72572
+ }
72573
+
72574
+ /*
72575
+ * Copyright (C) 2025 Xibo Signage Ltd
72576
+ *
72577
+ * Xibo - Digital Signage - https://www.xibosignage.com
72578
+ *
72579
+ * This file is part of Xibo.
72580
+ *
72581
+ * Xibo is free software: you can redistribute it and/or modify
72582
+ * it under the terms of the GNU Lesser General Public License as published by
72583
+ * the Free Software Foundation, either version 3 of the License, or
72584
+ * any later version.
72585
+ *
72586
+ * Xibo is distributed in the hope that it will be useful,
72587
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
72588
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72589
+ * GNU Lesser General Public License for more details.
72590
+ *
72591
+ * You should have received a copy of the GNU Lesser General Public License
72592
+ * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
72593
+ */
69797
72594
  function PwaSW() {
69798
72595
  var swScope = '/pwa/sw.js';
69799
72596
  return {
@@ -69853,7 +72650,7 @@ function _composeVideoSource() {
69853
72650
  return _composeVideoSource.apply(this, arguments);
69854
72651
  }
69855
72652
  function VideoMedia(media, xlr) {
69856
- var videoMediaObject = {
72653
+ return {
69857
72654
  init: function init() {
69858
72655
  var $videoMedia = document.getElementById(getMediaId(media));
69859
72656
  if ($videoMedia) {
@@ -69896,14 +72693,14 @@ function VideoMedia(media, xlr) {
69896
72693
  if (hasSW) {
69897
72694
  playerSW.postMsg({
69898
72695
  type: 'MEDIA_FAULT',
69899
- code: '5002',
72696
+ code: 5002,
69900
72697
  reason: 'Video file source not supported',
69901
72698
  mediaId: media.id,
69902
72699
  regionId: media.region.id,
69903
72700
  layoutId: media.region.layout.id,
69904
- date: new Date().toJSON(),
72701
+ date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
69905
72702
  // Temporary setting
69906
- expiry: setExpiry(7)
72703
+ expires: format(new Date(setExpiry(7)), 'yyyy-MM-dd HH:mm:ss')
69907
72704
  })["finally"](function () {
69908
72705
  // Expire the media and dispose the video
69909
72706
  vjsPlayer.dispose();
@@ -69943,7 +72740,6 @@ function VideoMedia(media, xlr) {
69943
72740
  }
69944
72741
  }
69945
72742
  };
69946
- return videoMediaObject;
69947
72743
  }
69948
72744
 
69949
72745
  function AudioMedia(media) {