@xibosignage/xibo-layout-renderer 1.0.8 → 1.0.10

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