@trackunit/date-and-time-utils 1.20.34-alpha-2f5decf56c8.0 → 1.20.36

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.
package/index.cjs.js CHANGED
@@ -1559,20 +1559,18 @@ const monthNameUtil = (date, format, locale) => {
1559
1559
  });
1560
1560
  };
1561
1561
  /**
1562
- * Returns a list of month names
1562
+ * Returns the names of the Gregorian months, January to December, regardless of the locale's default calendar.
1563
1563
  *
1564
- * @param {TemporalFormatStyle} format - select the format of the month name
1565
- * @param {string} locale - The locale to use for formatting. If not provided, the system's default locale will be used.
1564
+ * @param {TemporalFormatStyle} [format] - The format of the month names. Defaults to "long".
1565
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
1566
+ * @returns {Array<string>} The 12 month names, where index 0 is January.
1567
+ * @example
1568
+ * monthsUtil("short", "en-US");
1569
+ * Output: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
1566
1570
  */
1567
1571
  const monthsUtil = (format, locale) => {
1568
- const months = [];
1569
- const d = new Date();
1570
- const monthsInYear = polyfill.Temporal.PlainDate.from(d.toISOString()).monthsInYear;
1571
- for (let month = 0; month < monthsInYear; ++month) {
1572
- d.setMonth(month);
1573
- months.push(d.toLocaleString(locale, { month: format ?? "long" }));
1574
- }
1575
- return months;
1572
+ const formatter = new Intl.DateTimeFormat(locale, { month: format ?? "long", timeZone: "UTC", calendar: "gregory" });
1573
+ return Array.from({ length: 12 }, (_, month) => formatter.format(Date.UTC(2023, month, 1)));
1576
1574
  };
1577
1575
  /**
1578
1576
  * Returns the day name for the given date.
@@ -1603,20 +1601,26 @@ const dayNameUtil = (date, format, locale) => {
1603
1601
  });
1604
1602
  };
1605
1603
  /**
1606
- * Returns a list of day names
1604
+ * Returns the names of the days of the week, Sunday to Saturday.
1605
+ *
1606
+ * The index matches `Date.prototype.getDay()` (0 = Sunday); it is not the locale's first day of the week.
1607
+ * For a Temporal `dayOfWeek` (1 = Monday ... 7 = Sunday), use `daysUtil()[dayOfWeek % 7]`.
1607
1608
  *
1608
- * @param {TemporalFormatStyle} format - select the format of the day name
1609
- * @param {string} locale - The locale to use for formatting. If not provided, the system's default locale will be used.
1609
+ * @param {TemporalFormatStyle} [format] - The format of the day names. Defaults to "long".
1610
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
1611
+ * @returns {Array<string>} The 7 day names, where index 0 is Sunday.
1612
+ * @example
1613
+ * daysUtil("short", "en-US");
1614
+ * Output: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
1610
1615
  */
1611
1616
  const daysUtil = (format, locale) => {
1612
- const days = [];
1613
- const d = new Date();
1614
- const daysInWeek = polyfill.Temporal.PlainDate.from(d.toISOString()).daysInWeek;
1615
- for (let day = 0; day < daysInWeek; ++day) {
1616
- d.setDate(day);
1617
- days.push(d.toLocaleString(locale, { weekday: format ?? "long" }));
1618
- }
1619
- return days;
1617
+ const formatter = new Intl.DateTimeFormat(locale, {
1618
+ weekday: format ?? "long",
1619
+ timeZone: "UTC",
1620
+ calendar: "gregory",
1621
+ });
1622
+ // 1 January 2023 was a Sunday.
1623
+ return Array.from({ length: 7 }, (_, day) => formatter.format(Date.UTC(2023, 0, 1 + day)));
1620
1624
  };
1621
1625
  /**
1622
1626
  * Returns the UTC date-time for the given time zone.
package/index.esm.js CHANGED
@@ -1558,20 +1558,18 @@ const monthNameUtil = (date, format, locale) => {
1558
1558
  });
1559
1559
  };
1560
1560
  /**
1561
- * Returns a list of month names
1561
+ * Returns the names of the Gregorian months, January to December, regardless of the locale's default calendar.
1562
1562
  *
1563
- * @param {TemporalFormatStyle} format - select the format of the month name
1564
- * @param {string} locale - The locale to use for formatting. If not provided, the system's default locale will be used.
1563
+ * @param {TemporalFormatStyle} [format] - The format of the month names. Defaults to "long".
1564
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
1565
+ * @returns {Array<string>} The 12 month names, where index 0 is January.
1566
+ * @example
1567
+ * monthsUtil("short", "en-US");
1568
+ * Output: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
1565
1569
  */
1566
1570
  const monthsUtil = (format, locale) => {
1567
- const months = [];
1568
- const d = new Date();
1569
- const monthsInYear = Temporal.PlainDate.from(d.toISOString()).monthsInYear;
1570
- for (let month = 0; month < monthsInYear; ++month) {
1571
- d.setMonth(month);
1572
- months.push(d.toLocaleString(locale, { month: format ?? "long" }));
1573
- }
1574
- return months;
1571
+ const formatter = new Intl.DateTimeFormat(locale, { month: format ?? "long", timeZone: "UTC", calendar: "gregory" });
1572
+ return Array.from({ length: 12 }, (_, month) => formatter.format(Date.UTC(2023, month, 1)));
1575
1573
  };
1576
1574
  /**
1577
1575
  * Returns the day name for the given date.
@@ -1602,20 +1600,26 @@ const dayNameUtil = (date, format, locale) => {
1602
1600
  });
1603
1601
  };
1604
1602
  /**
1605
- * Returns a list of day names
1603
+ * Returns the names of the days of the week, Sunday to Saturday.
1604
+ *
1605
+ * The index matches `Date.prototype.getDay()` (0 = Sunday); it is not the locale's first day of the week.
1606
+ * For a Temporal `dayOfWeek` (1 = Monday ... 7 = Sunday), use `daysUtil()[dayOfWeek % 7]`.
1606
1607
  *
1607
- * @param {TemporalFormatStyle} format - select the format of the day name
1608
- * @param {string} locale - The locale to use for formatting. If not provided, the system's default locale will be used.
1608
+ * @param {TemporalFormatStyle} [format] - The format of the day names. Defaults to "long".
1609
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
1610
+ * @returns {Array<string>} The 7 day names, where index 0 is Sunday.
1611
+ * @example
1612
+ * daysUtil("short", "en-US");
1613
+ * Output: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
1609
1614
  */
1610
1615
  const daysUtil = (format, locale) => {
1611
- const days = [];
1612
- const d = new Date();
1613
- const daysInWeek = Temporal.PlainDate.from(d.toISOString()).daysInWeek;
1614
- for (let day = 0; day < daysInWeek; ++day) {
1615
- d.setDate(day);
1616
- days.push(d.toLocaleString(locale, { weekday: format ?? "long" }));
1617
- }
1618
- return days;
1616
+ const formatter = new Intl.DateTimeFormat(locale, {
1617
+ weekday: format ?? "long",
1618
+ timeZone: "UTC",
1619
+ calendar: "gregory",
1620
+ });
1621
+ // 1 January 2023 was a Sunday.
1622
+ return Array.from({ length: 7 }, (_, day) => formatter.format(Date.UTC(2023, 0, 1 + day)));
1619
1623
  };
1620
1624
  /**
1621
1625
  * Returns the UTC date-time for the given time zone.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/date-and-time-utils",
3
- "version": "1.20.34-alpha-2f5decf56c8.0",
3
+ "version": "1.20.36",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -967,10 +967,14 @@ export declare const toZonedDateTimeUtil: (date: TemporalDate | string, timeZone
967
967
  */
968
968
  export declare const monthNameUtil: (date: TemporalDate, format: TemporalFormatStyle, locale?: string) => string;
969
969
  /**
970
- * Returns a list of month names
970
+ * Returns the names of the Gregorian months, January to December, regardless of the locale's default calendar.
971
971
  *
972
- * @param {TemporalFormatStyle} format - select the format of the month name
973
- * @param {string} locale - The locale to use for formatting. If not provided, the system's default locale will be used.
972
+ * @param {TemporalFormatStyle} [format] - The format of the month names. Defaults to "long".
973
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
974
+ * @returns {Array<string>} The 12 month names, where index 0 is January.
975
+ * @example
976
+ * monthsUtil("short", "en-US");
977
+ * Output: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
974
978
  */
975
979
  export declare const monthsUtil: (format?: TemporalFormatStyle, locale?: string) => Array<string>;
976
980
  /**
@@ -998,10 +1002,17 @@ export declare const monthsUtil: (format?: TemporalFormatStyle, locale?: string)
998
1002
  */
999
1003
  export declare const dayNameUtil: (date: TemporalDate, format: TemporalFormatStyle, locale?: string) => string;
1000
1004
  /**
1001
- * Returns a list of day names
1005
+ * Returns the names of the days of the week, Sunday to Saturday.
1006
+ *
1007
+ * The index matches `Date.prototype.getDay()` (0 = Sunday); it is not the locale's first day of the week.
1008
+ * For a Temporal `dayOfWeek` (1 = Monday ... 7 = Sunday), use `daysUtil()[dayOfWeek % 7]`.
1002
1009
  *
1003
- * @param {TemporalFormatStyle} format - select the format of the day name
1004
- * @param {string} locale - The locale to use for formatting. If not provided, the system's default locale will be used.
1010
+ * @param {TemporalFormatStyle} [format] - The format of the day names. Defaults to "long".
1011
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
1012
+ * @returns {Array<string>} The 7 day names, where index 0 is Sunday.
1013
+ * @example
1014
+ * daysUtil("short", "en-US");
1015
+ * Output: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
1005
1016
  */
1006
1017
  export declare const daysUtil: (format?: TemporalFormatStyle, locale?: string) => Array<string>;
1007
1018
  /**