@trackunit/date-and-time-utils 0.0.2 → 0.0.3

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
@@ -991,6 +991,34 @@ const monthNameUtil = (date, format, locale) => {
991
991
  month: format,
992
992
  });
993
993
  };
994
+ /**
995
+ * Returns the day name for the given date.
996
+ *
997
+ * @param {TemporalDate | Date} date - The temporal or JavaScript Date object to get day name from.
998
+ * @param {TemporalFormatStyle} [format] - The format options for the name of the day.
999
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
1000
+ * @returns {string} The the name of the day from passed date.
1001
+ * @example
1002
+ * const dateString = "2023-04-10"
1003
+ * const date = new Date(dateString);
1004
+ * const dayName = dayNameUtil(date, "long");
1005
+ * Output: "Monday"
1006
+ * @example
1007
+ * const dateString = "2023-04-10"
1008
+ * const date = new Date(dateString);
1009
+ * const dayName = dayNameUtil(date, "short");
1010
+ * Output: "Mon"
1011
+ * @example
1012
+ * const dateString = "2023-04-10"
1013
+ * const date = new Date(dateString);
1014
+ * const dayName = dayNameUtil(date, "narrow");
1015
+ * Output: "M"
1016
+ */
1017
+ const dayNameUtil = (date, format, locale) => {
1018
+ return toZonedDateTimeUtil(date).toLocaleString(locale, {
1019
+ weekday: format,
1020
+ });
1021
+ };
994
1022
 
995
1023
  exports.addDaysUtil = addDaysUtil;
996
1024
  exports.addHoursUtil = addHoursUtil;
@@ -998,6 +1026,7 @@ exports.addMinutesUtil = addMinutesUtil;
998
1026
  exports.addMonthsUtil = addMonthsUtil;
999
1027
  exports.addWeeksUtil = addWeeksUtil;
1000
1028
  exports.addYearsUtil = addYearsUtil;
1029
+ exports.dayNameUtil = dayNameUtil;
1001
1030
  exports.differenceInDaysUtil = differenceInDaysUtil;
1002
1031
  exports.differenceInHoursUtil = differenceInHoursUtil;
1003
1032
  exports.differenceInMinutesUtil = differenceInMinutesUtil;
package/index.esm.js CHANGED
@@ -987,5 +987,33 @@ const monthNameUtil = (date, format, locale) => {
987
987
  month: format,
988
988
  });
989
989
  };
990
+ /**
991
+ * Returns the day name for the given date.
992
+ *
993
+ * @param {TemporalDate | Date} date - The temporal or JavaScript Date object to get day name from.
994
+ * @param {TemporalFormatStyle} [format] - The format options for the name of the day.
995
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
996
+ * @returns {string} The the name of the day from passed date.
997
+ * @example
998
+ * const dateString = "2023-04-10"
999
+ * const date = new Date(dateString);
1000
+ * const dayName = dayNameUtil(date, "long");
1001
+ * Output: "Monday"
1002
+ * @example
1003
+ * const dateString = "2023-04-10"
1004
+ * const date = new Date(dateString);
1005
+ * const dayName = dayNameUtil(date, "short");
1006
+ * Output: "Mon"
1007
+ * @example
1008
+ * const dateString = "2023-04-10"
1009
+ * const date = new Date(dateString);
1010
+ * const dayName = dayNameUtil(date, "narrow");
1011
+ * Output: "M"
1012
+ */
1013
+ const dayNameUtil = (date, format, locale) => {
1014
+ return toZonedDateTimeUtil(date).toLocaleString(locale, {
1015
+ weekday: format,
1016
+ });
1017
+ };
990
1018
 
991
- export { addDaysUtil, addHoursUtil, addMinutesUtil, addMonthsUtil, addWeeksUtil, addYearsUtil, differenceInDaysUtil, differenceInHoursUtil, differenceInMinutesUtil, differenceInMonthsUtil, differenceInWeeksUtil, endOfDayUtil, endOfHourUtil, endOfMinuteUtil, endOfMonthUtil, endOfWeekUtil, formatDateUtil, formatRangeUtil, isEqualUtil, isFutureUtil, isPastUtil, isSameDayUtil, isSameMonthUtil, isSameWeekUtil, isSameYearUtil, isTodayUtil, monthNameUtil, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, startOfMonthUtil, startOfWeekUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, subtractMonthsUtil, subtractWeeksUtil, subtractYearsUtil, timeSinceAuto, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInMonths, timeSinceInSeconds, timeSinceInYears, timeZonesAvailable, toDateUtil, toInstantUtil, toTemporalUtil, toZonedDateTimeUtil };
1019
+ export { addDaysUtil, addHoursUtil, addMinutesUtil, addMonthsUtil, addWeeksUtil, addYearsUtil, dayNameUtil, differenceInDaysUtil, differenceInHoursUtil, differenceInMinutesUtil, differenceInMonthsUtil, differenceInWeeksUtil, endOfDayUtil, endOfHourUtil, endOfMinuteUtil, endOfMonthUtil, endOfWeekUtil, formatDateUtil, formatRangeUtil, isEqualUtil, isFutureUtil, isPastUtil, isSameDayUtil, isSameMonthUtil, isSameWeekUtil, isSameYearUtil, isTodayUtil, monthNameUtil, startOfDayUtil, startOfHourUtil, startOfMinuteUtil, startOfMonthUtil, startOfWeekUtil, subtractDaysUtil, subtractHoursUtil, subtractMinutesUtil, subtractMonthsUtil, subtractWeeksUtil, subtractYearsUtil, timeSinceAuto, timeSinceInDays, timeSinceInHours, timeSinceInMinutes, timeSinceInMonths, timeSinceInSeconds, timeSinceInYears, timeZonesAvailable, toDateUtil, toInstantUtil, toTemporalUtil, toZonedDateTimeUtil };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/date-and-time-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -787,4 +787,28 @@ export declare const toZonedDateTimeUtil: (date: TemporalDate, timeZoneId?: stri
787
787
  * Output: "A"
788
788
  */
789
789
  export declare const monthNameUtil: (date: TemporalDate, format: TemporalFormatStyle, locale?: string) => string;
790
+ /**
791
+ * Returns the day name for the given date.
792
+ *
793
+ * @param {TemporalDate | Date} date - The temporal or JavaScript Date object to get day name from.
794
+ * @param {TemporalFormatStyle} [format] - The format options for the name of the day.
795
+ * @param {string} [locale] - The locale to use for formatting. If not provided, the system's default locale will be used.
796
+ * @returns {string} The the name of the day from passed date.
797
+ * @example
798
+ * const dateString = "2023-04-10"
799
+ * const date = new Date(dateString);
800
+ * const dayName = dayNameUtil(date, "long");
801
+ * Output: "Monday"
802
+ * @example
803
+ * const dateString = "2023-04-10"
804
+ * const date = new Date(dateString);
805
+ * const dayName = dayNameUtil(date, "short");
806
+ * Output: "Mon"
807
+ * @example
808
+ * const dateString = "2023-04-10"
809
+ * const date = new Date(dateString);
810
+ * const dayName = dayNameUtil(date, "narrow");
811
+ * Output: "M"
812
+ */
813
+ export declare const dayNameUtil: (date: TemporalDate, format: TemporalFormatStyle, locale?: string) => string;
790
814
  export {};