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