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