@trackunit/date-and-time-utils 1.3.139 → 1.3.141

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
@@ -813,19 +813,19 @@ const isBetweenUtil = (date, start, end) => {
813
813
  if (!start || !end) {
814
814
  throw new Error("Start and end dates must be provided");
815
815
  }
816
- const dateToCheck = new Date(date.toLocaleString());
817
- const startDate = new Date(start.toLocaleString());
818
- const endDate = new Date(end.toLocaleString());
819
- return dateToCheck >= startDate && dateToCheck <= endDate;
816
+ const dateCompareStart = polyfill.Temporal.PlainDateTime.compare(toZonedDateTimeUtil(date), toZonedDateTimeUtil(start));
817
+ const dateCompareEnd = polyfill.Temporal.PlainDateTime.compare(toZonedDateTimeUtil(date), toZonedDateTimeUtil(end));
818
+ return dateCompareStart >= 0 && dateCompareEnd <= 0;
820
819
  };
821
820
  /**
822
821
  * Checks if a date is same day as current.
823
822
  *
824
823
  * @param {TemporalDate} date - The date to check.
824
+ * @param {TemporalDate} compareTo - The date to compare against. Defaults to the current date.
825
825
  * @returns {boolean} `true` if the date is current day, `false` otherwise.
826
826
  */
827
- const isSameDayUtil = (date) => {
828
- const today = toZonedDateTimeUtil(polyfill.Temporal.Now.instant());
827
+ const isSameDayUtil = (date, compareTo) => {
828
+ const today = toZonedDateTimeUtil(compareTo ?? polyfill.Temporal.Now.instant());
829
829
  const input = toZonedDateTimeUtil(date);
830
830
  return today.dayOfYear === input.dayOfYear && today.year === input.year;
831
831
  };
package/index.esm.js CHANGED
@@ -811,19 +811,19 @@ const isBetweenUtil = (date, start, end) => {
811
811
  if (!start || !end) {
812
812
  throw new Error("Start and end dates must be provided");
813
813
  }
814
- const dateToCheck = new Date(date.toLocaleString());
815
- const startDate = new Date(start.toLocaleString());
816
- const endDate = new Date(end.toLocaleString());
817
- return dateToCheck >= startDate && dateToCheck <= endDate;
814
+ const dateCompareStart = Temporal.PlainDateTime.compare(toZonedDateTimeUtil(date), toZonedDateTimeUtil(start));
815
+ const dateCompareEnd = Temporal.PlainDateTime.compare(toZonedDateTimeUtil(date), toZonedDateTimeUtil(end));
816
+ return dateCompareStart >= 0 && dateCompareEnd <= 0;
818
817
  };
819
818
  /**
820
819
  * Checks if a date is same day as current.
821
820
  *
822
821
  * @param {TemporalDate} date - The date to check.
822
+ * @param {TemporalDate} compareTo - The date to compare against. Defaults to the current date.
823
823
  * @returns {boolean} `true` if the date is current day, `false` otherwise.
824
824
  */
825
- const isSameDayUtil = (date) => {
826
- const today = toZonedDateTimeUtil(Temporal.Now.instant());
825
+ const isSameDayUtil = (date, compareTo) => {
826
+ const today = toZonedDateTimeUtil(compareTo ?? Temporal.Now.instant());
827
827
  const input = toZonedDateTimeUtil(date);
828
828
  return today.dayOfYear === input.dayOfYear && today.year === input.year;
829
829
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/date-and-time-utils",
3
- "version": "1.3.139",
3
+ "version": "1.3.141",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -10,7 +10,7 @@
10
10
  "@formatjs/intl-enumerator": "^1.8.1",
11
11
  "@js-temporal/polyfill": "^0.4.4",
12
12
  "@formatjs/intl-durationformat": "^0.6.1",
13
- "@trackunit/react-test-setup": "1.0.29"
13
+ "@trackunit/react-test-setup": "1.0.31"
14
14
  },
15
15
  "module": "./index.esm.js",
16
16
  "main": "./index.cjs.js",
@@ -612,9 +612,10 @@ export declare const isBetweenUtil: (date: TemporalDate, start?: TemporalDate, e
612
612
  * Checks if a date is same day as current.
613
613
  *
614
614
  * @param {TemporalDate} date - The date to check.
615
+ * @param {TemporalDate} compareTo - The date to compare against. Defaults to the current date.
615
616
  * @returns {boolean} `true` if the date is current day, `false` otherwise.
616
617
  */
617
- export declare const isSameDayUtil: (date: TemporalDate) => boolean;
618
+ export declare const isSameDayUtil: (date: TemporalDate, compareTo?: TemporalDate) => boolean;
618
619
  /**
619
620
  * Checks if a date is same week as current.
620
621
  *