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