@trackunit/react-date-and-time-components 1.5.17 → 1.6.0

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
@@ -219,18 +219,14 @@ const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, dataTestId,
219
219
  const temporalArithmeticTypeMapping = {
220
220
  day: "days",
221
221
  days: "days",
222
- week: "weeks",
223
- weeks: "weeks",
224
- month: "months",
225
- months: "months",
226
222
  };
227
223
 
228
224
  /**
229
225
  * Calculate a date range based on a temporal period.
230
226
  *
231
227
  * @example
232
- * getDataRange({ direction: "next", count: 1, unit: "month" }); // { from: 2025-06-01, to: 2025-07-01 }
233
- * getDataRange({ direction: "last", count: 2, unit: "weeks" }); // { from: 2025-05-24, to: 2025-06-01 }
228
+ * getDataRange({ direction: "next", count: 7, unit: "days" }); // { from: 2025-06-01, to: 2025-07-01 }
229
+ * getDataRange({ direction: "last", count: 14, unit: "days" }); // { from: 2025-05-24, to: 2025-06-01 }
234
230
  */
235
231
  const useCalculateDateRange = () => {
236
232
  const { nowDate, startOf, endOf, subtract, add } = reactDateAndTimeHooks.useDateAndTime();
@@ -262,7 +258,7 @@ const useCalculateDateRange = () => {
262
258
  *
263
259
  * @example
264
260
  * formatTemporalPeriodLabel({ direction: "last", count: 2, unit: "days" }); // Last 2 days
265
- * formatTemporalPeriodLabel({ direction: "next", count: 1, unit: "week" }); // Next week
261
+ * formatTemporalPeriodLabel({ direction: "next", count: 7, unit: "days" }); // Next 7 days
266
262
  */
267
263
  const useFormatTemporalPeriodLabel = () => {
268
264
  const [t] = useTranslation();
@@ -366,12 +362,12 @@ const useCalculateCustomDateRangeDisabledDays = () => {
366
362
  * @example
367
363
  * getTemporalPeriodsInRange({
368
364
  * temporalPeriods: [
369
- * { direction: "next", count: 1, unit: "week" },
370
- * { direction: "next", count: 1, unit: "month" },
365
+ * { direction: "next", count: 7, unit: "days" },
366
+ * { direction: "next", count: 30, unit: "days" },
371
367
  * ],
372
368
  * maxDaysInRange: 7,
373
369
  * });
374
- * ); // [{ direction: "next", count: 1, unit: "week" }]
370
+ * ); // [{ direction: "next", count: 7, unit: "days" }]
375
371
  */
376
372
  const useFilterTemporalPeriodsInRange = () => {
377
373
  const { difference } = reactDateAndTimeHooks.useDateAndTime();
@@ -416,10 +412,6 @@ const useFindTemporalUnit = () => {
416
412
  const temporalUnitsMap = react.useMemo(() => ({
417
413
  day: t("input.unit.day"),
418
414
  days: t("input.unit.days"),
419
- week: t("input.unit.week"),
420
- weeks: t("input.unit.weeks"),
421
- month: t("input.unit.month"),
422
- months: t("input.unit.months"),
423
415
  }), [t]);
424
416
  return react.useCallback((value) => {
425
417
  if (!value) {
@@ -435,7 +427,7 @@ const useFindTemporalUnit = () => {
435
427
  * @example
436
428
  * parseTemporalPeriodFromText("Last 2 days"); // { direction: "last", count: 2, unit: "days" }
437
429
  * parseTemporalPeriodFromText("next 3"); // { direction: "next", count: 3 }
438
- * parseTemporalPeriodFromText("1 month"); // {count: 1, unit: "month" }
430
+ * parseTemporalPeriodFromText("3 days"); // {count: 3, unit: "days" }
439
431
  */
440
432
  const useParseTemporalPeriodFromText = () => {
441
433
  const [t] = useTranslation();
@@ -447,8 +439,17 @@ const useParseTemporalPeriodFromText = () => {
447
439
  new RegExp(`${t("input.direction.next")}|${t("input.direction.last")}`, "i"))?.[0];
448
440
  const countMatch = value.match(/\d+/)?.[0];
449
441
  const unitMatch = value.match(
450
- // Matches any of the translated time unit strings both plural and singular (days, day, weeks, week, months, month)
451
- new RegExp(`${t("input.unit.days")}|${t("input.unit.day")}|${t("input.unit.weeks")}|${t("input.unit.week")}|${t("input.unit.months")}|${t("input.unit.month")}`, "i"))?.[0];
442
+ // Matches any of the translated time unit strings both plural and singular (days, day)
443
+ new RegExp(`${t("input.unit.days")}|${t("input.unit.day")}`, "i"))?.[0];
444
+ // Matches the string "today"
445
+ const todayMatch = value.match(new RegExp(`${t("input.today")}`, "i"))?.[0];
446
+ if (todayMatch) {
447
+ return {
448
+ direction: findTemporalDirection(directionMatch),
449
+ count: 1,
450
+ unit: "day",
451
+ };
452
+ }
452
453
  return {
453
454
  direction: findTemporalDirection(directionMatch),
454
455
  count: sharedUtils.nonNullable(countMatch) ? parseInt(countMatch) : undefined,
@@ -458,7 +459,7 @@ const useParseTemporalPeriodFromText = () => {
458
459
  };
459
460
 
460
461
  const DEFAULT_DIRECTIONS = ["last", "next"];
461
- const DEFAULT_COUNT = 1;
462
+ const DEFAULT_COUNT = 7;
462
463
  /**
463
464
  * Generate all possible temporal period combinations for a given temporal period.
464
465
  * If direction is not provided, both "last" and "next" directions are used.
@@ -467,25 +468,20 @@ const DEFAULT_COUNT = 1;
467
468
  *
468
469
  * @example
469
470
  * createTemporalPeriodCombinations({ direction: "last", count: 2, unit: "days" }); // [{ direction: "last", count: 2, unit: "days" }]
470
- * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }, { direction: "next", count: 1, unit: "week" }, { direction: "next", count: 1, unit: "month" }]
471
+ * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }]
471
472
  */
472
473
  const createTemporalPeriodCombinations = ({ direction, count, unit, }) => {
473
474
  const directions = direction ? [direction] : DEFAULT_DIRECTIONS;
474
- const isCountPlural = sharedUtils.nonNullable(count) ? count > 1 : false;
475
- const units = unit
476
- ? [unit]
477
- : isCountPlural
478
- ? ["days", "weeks", "months"]
479
- : ["day", "week", "month"];
475
+ const _count = count ?? DEFAULT_COUNT;
476
+ const isCountPlural = _count > 1;
477
+ const _unit = isCountPlural ? "days" : "day";
480
478
  return (directions
481
- .flatMap(_direction => {
482
- return units.map((_unit) => {
483
- return {
484
- direction: _direction,
485
- count: count ?? DEFAULT_COUNT,
486
- unit: _unit,
487
- };
488
- });
479
+ .map((_direction) => {
480
+ return {
481
+ direction: _direction,
482
+ count: _count,
483
+ unit: _unit,
484
+ };
489
485
  })
490
486
  // If temporal direction isn't provided, filter out either of the 1 day options as they are both rendered as "Today"
491
487
  .filter((period, index, array) => {
@@ -537,9 +533,9 @@ const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, on
537
533
  }
538
534
  const defaultCombinations = [
539
535
  { direction: allowedDirection ?? "last", count: 1, unit: "day" },
540
- { direction: allowedDirection ?? "last", count: 1, unit: "week" },
541
- { direction: allowedDirection ?? "last", count: 1, unit: "month" },
542
- { direction: allowedDirection ?? "last", count: 12, unit: "months" },
536
+ { direction: allowedDirection ?? "last", count: 7, unit: "days" },
537
+ { direction: allowedDirection ?? "last", count: 30, unit: "days" },
538
+ { direction: allowedDirection ?? "last", count: 365, unit: "days" },
543
539
  ];
544
540
  return filterTemporalPeriodsInRange({ temporalPeriods: defaultCombinations, maxDaysInRange });
545
541
  }, [initialDateRangeOptions, filterTemporalPeriodsInRange, allowedDirection, maxDaysInRange]);
package/index.esm.js CHANGED
@@ -217,18 +217,14 @@ const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, dataTestId,
217
217
  const temporalArithmeticTypeMapping = {
218
218
  day: "days",
219
219
  days: "days",
220
- week: "weeks",
221
- weeks: "weeks",
222
- month: "months",
223
- months: "months",
224
220
  };
225
221
 
226
222
  /**
227
223
  * Calculate a date range based on a temporal period.
228
224
  *
229
225
  * @example
230
- * getDataRange({ direction: "next", count: 1, unit: "month" }); // { from: 2025-06-01, to: 2025-07-01 }
231
- * getDataRange({ direction: "last", count: 2, unit: "weeks" }); // { from: 2025-05-24, to: 2025-06-01 }
226
+ * getDataRange({ direction: "next", count: 7, unit: "days" }); // { from: 2025-06-01, to: 2025-07-01 }
227
+ * getDataRange({ direction: "last", count: 14, unit: "days" }); // { from: 2025-05-24, to: 2025-06-01 }
232
228
  */
233
229
  const useCalculateDateRange = () => {
234
230
  const { nowDate, startOf, endOf, subtract, add } = useDateAndTime();
@@ -260,7 +256,7 @@ const useCalculateDateRange = () => {
260
256
  *
261
257
  * @example
262
258
  * formatTemporalPeriodLabel({ direction: "last", count: 2, unit: "days" }); // Last 2 days
263
- * formatTemporalPeriodLabel({ direction: "next", count: 1, unit: "week" }); // Next week
259
+ * formatTemporalPeriodLabel({ direction: "next", count: 7, unit: "days" }); // Next 7 days
264
260
  */
265
261
  const useFormatTemporalPeriodLabel = () => {
266
262
  const [t] = useTranslation();
@@ -364,12 +360,12 @@ const useCalculateCustomDateRangeDisabledDays = () => {
364
360
  * @example
365
361
  * getTemporalPeriodsInRange({
366
362
  * temporalPeriods: [
367
- * { direction: "next", count: 1, unit: "week" },
368
- * { direction: "next", count: 1, unit: "month" },
363
+ * { direction: "next", count: 7, unit: "days" },
364
+ * { direction: "next", count: 30, unit: "days" },
369
365
  * ],
370
366
  * maxDaysInRange: 7,
371
367
  * });
372
- * ); // [{ direction: "next", count: 1, unit: "week" }]
368
+ * ); // [{ direction: "next", count: 7, unit: "days" }]
373
369
  */
374
370
  const useFilterTemporalPeriodsInRange = () => {
375
371
  const { difference } = useDateAndTime();
@@ -414,10 +410,6 @@ const useFindTemporalUnit = () => {
414
410
  const temporalUnitsMap = useMemo(() => ({
415
411
  day: t("input.unit.day"),
416
412
  days: t("input.unit.days"),
417
- week: t("input.unit.week"),
418
- weeks: t("input.unit.weeks"),
419
- month: t("input.unit.month"),
420
- months: t("input.unit.months"),
421
413
  }), [t]);
422
414
  return useCallback((value) => {
423
415
  if (!value) {
@@ -433,7 +425,7 @@ const useFindTemporalUnit = () => {
433
425
  * @example
434
426
  * parseTemporalPeriodFromText("Last 2 days"); // { direction: "last", count: 2, unit: "days" }
435
427
  * parseTemporalPeriodFromText("next 3"); // { direction: "next", count: 3 }
436
- * parseTemporalPeriodFromText("1 month"); // {count: 1, unit: "month" }
428
+ * parseTemporalPeriodFromText("3 days"); // {count: 3, unit: "days" }
437
429
  */
438
430
  const useParseTemporalPeriodFromText = () => {
439
431
  const [t] = useTranslation();
@@ -445,8 +437,17 @@ const useParseTemporalPeriodFromText = () => {
445
437
  new RegExp(`${t("input.direction.next")}|${t("input.direction.last")}`, "i"))?.[0];
446
438
  const countMatch = value.match(/\d+/)?.[0];
447
439
  const unitMatch = value.match(
448
- // Matches any of the translated time unit strings both plural and singular (days, day, weeks, week, months, month)
449
- new RegExp(`${t("input.unit.days")}|${t("input.unit.day")}|${t("input.unit.weeks")}|${t("input.unit.week")}|${t("input.unit.months")}|${t("input.unit.month")}`, "i"))?.[0];
440
+ // Matches any of the translated time unit strings both plural and singular (days, day)
441
+ new RegExp(`${t("input.unit.days")}|${t("input.unit.day")}`, "i"))?.[0];
442
+ // Matches the string "today"
443
+ const todayMatch = value.match(new RegExp(`${t("input.today")}`, "i"))?.[0];
444
+ if (todayMatch) {
445
+ return {
446
+ direction: findTemporalDirection(directionMatch),
447
+ count: 1,
448
+ unit: "day",
449
+ };
450
+ }
450
451
  return {
451
452
  direction: findTemporalDirection(directionMatch),
452
453
  count: nonNullable(countMatch) ? parseInt(countMatch) : undefined,
@@ -456,7 +457,7 @@ const useParseTemporalPeriodFromText = () => {
456
457
  };
457
458
 
458
459
  const DEFAULT_DIRECTIONS = ["last", "next"];
459
- const DEFAULT_COUNT = 1;
460
+ const DEFAULT_COUNT = 7;
460
461
  /**
461
462
  * Generate all possible temporal period combinations for a given temporal period.
462
463
  * If direction is not provided, both "last" and "next" directions are used.
@@ -465,25 +466,20 @@ const DEFAULT_COUNT = 1;
465
466
  *
466
467
  * @example
467
468
  * createTemporalPeriodCombinations({ direction: "last", count: 2, unit: "days" }); // [{ direction: "last", count: 2, unit: "days" }]
468
- * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }, { direction: "next", count: 1, unit: "week" }, { direction: "next", count: 1, unit: "month" }]
469
+ * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }]
469
470
  */
470
471
  const createTemporalPeriodCombinations = ({ direction, count, unit, }) => {
471
472
  const directions = direction ? [direction] : DEFAULT_DIRECTIONS;
472
- const isCountPlural = nonNullable(count) ? count > 1 : false;
473
- const units = unit
474
- ? [unit]
475
- : isCountPlural
476
- ? ["days", "weeks", "months"]
477
- : ["day", "week", "month"];
473
+ const _count = count ?? DEFAULT_COUNT;
474
+ const isCountPlural = _count > 1;
475
+ const _unit = isCountPlural ? "days" : "day";
478
476
  return (directions
479
- .flatMap(_direction => {
480
- return units.map((_unit) => {
481
- return {
482
- direction: _direction,
483
- count: count ?? DEFAULT_COUNT,
484
- unit: _unit,
485
- };
486
- });
477
+ .map((_direction) => {
478
+ return {
479
+ direction: _direction,
480
+ count: _count,
481
+ unit: _unit,
482
+ };
487
483
  })
488
484
  // If temporal direction isn't provided, filter out either of the 1 day options as they are both rendered as "Today"
489
485
  .filter((period, index, array) => {
@@ -535,9 +531,9 @@ const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, on
535
531
  }
536
532
  const defaultCombinations = [
537
533
  { direction: allowedDirection ?? "last", count: 1, unit: "day" },
538
- { direction: allowedDirection ?? "last", count: 1, unit: "week" },
539
- { direction: allowedDirection ?? "last", count: 1, unit: "month" },
540
- { direction: allowedDirection ?? "last", count: 12, unit: "months" },
534
+ { direction: allowedDirection ?? "last", count: 7, unit: "days" },
535
+ { direction: allowedDirection ?? "last", count: 30, unit: "days" },
536
+ { direction: allowedDirection ?? "last", count: 365, unit: "days" },
541
537
  ];
542
538
  return filterTemporalPeriodsInRange({ temporalPeriods: defaultCombinations, maxDaysInRange });
543
539
  }, [initialDateRangeOptions, filterTemporalPeriodsInRange, allowedDirection, maxDaysInRange]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-date-and-time-components",
3
- "version": "1.5.17",
3
+ "version": "1.6.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -8,16 +8,16 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "react": "19.0.0",
11
- "@trackunit/react-components": "1.5.11",
12
- "@trackunit/react-date-and-time-hooks": "1.4.7",
11
+ "@trackunit/react-components": "1.5.12",
12
+ "@trackunit/react-date-and-time-hooks": "1.4.8",
13
13
  "@trackunit/date-and-time-utils": "1.4.6",
14
14
  "@trackunit/css-class-variance-utilities": "1.4.6",
15
15
  "@trackunit/ui-icons": "1.4.6",
16
16
  "@trackunit/ui-design-tokens": "1.4.8",
17
17
  "@trackunit/shared-utils": "1.6.6",
18
- "@trackunit/i18n-library-translation": "1.4.7",
18
+ "@trackunit/i18n-library-translation": "1.4.8",
19
19
  "@trackunit/react-test-setup": "1.1.6",
20
- "@trackunit/react-form-components": "1.4.12",
20
+ "@trackunit/react-form-components": "1.4.14",
21
21
  "string-ts": "^2.0.0",
22
22
  "tailwind-merge": "^2.0.0",
23
23
  "react-calendar": "^6.0.0"
@@ -4,7 +4,7 @@ import { TemporalPeriod } from "../../types";
4
4
  * Calculate a date range based on a temporal period.
5
5
  *
6
6
  * @example
7
- * getDataRange({ direction: "next", count: 1, unit: "month" }); // { from: 2025-06-01, to: 2025-07-01 }
8
- * getDataRange({ direction: "last", count: 2, unit: "weeks" }); // { from: 2025-05-24, to: 2025-06-01 }
7
+ * getDataRange({ direction: "next", count: 7, unit: "days" }); // { from: 2025-06-01, to: 2025-07-01 }
8
+ * getDataRange({ direction: "last", count: 14, unit: "days" }); // { from: 2025-05-24, to: 2025-06-01 }
9
9
  */
10
10
  export declare const useCalculateDateRange: () => ({ direction, count, unit }: TemporalPeriod) => DateRange;
@@ -5,12 +5,12 @@ import { TemporalPeriod } from "../../types";
5
5
  * @example
6
6
  * getTemporalPeriodsInRange({
7
7
  * temporalPeriods: [
8
- * { direction: "next", count: 1, unit: "week" },
9
- * { direction: "next", count: 1, unit: "month" },
8
+ * { direction: "next", count: 7, unit: "days" },
9
+ * { direction: "next", count: 30, unit: "days" },
10
10
  * ],
11
11
  * maxDaysInRange: 7,
12
12
  * });
13
- * ); // [{ direction: "next", count: 1, unit: "week" }]
13
+ * ); // [{ direction: "next", count: 7, unit: "days" }]
14
14
  */
15
15
  export declare const useFilterTemporalPeriodsInRange: () => ({ temporalPeriods, maxDaysInRange, }: {
16
16
  temporalPeriods: Array<TemporalPeriod>;
@@ -4,6 +4,6 @@ import { TemporalPeriod } from "../../types";
4
4
  *
5
5
  * @example
6
6
  * formatTemporalPeriodLabel({ direction: "last", count: 2, unit: "days" }); // Last 2 days
7
- * formatTemporalPeriodLabel({ direction: "next", count: 1, unit: "week" }); // Next week
7
+ * formatTemporalPeriodLabel({ direction: "next", count: 7, unit: "days" }); // Next 7 days
8
8
  */
9
9
  export declare const useFormatTemporalPeriodLabel: () => (option: TemporalPeriod) => string;
@@ -5,6 +5,6 @@ import { TemporalPeriod } from "../../types";
5
5
  * @example
6
6
  * parseTemporalPeriodFromText("Last 2 days"); // { direction: "last", count: 2, unit: "days" }
7
7
  * parseTemporalPeriodFromText("next 3"); // { direction: "next", count: 3 }
8
- * parseTemporalPeriodFromText("1 month"); // {count: 1, unit: "month" }
8
+ * parseTemporalPeriodFromText("3 days"); // {count: 3, unit: "days" }
9
9
  */
10
10
  export declare const useParseTemporalPeriodFromText: () => (value: string) => Partial<TemporalPeriod>;
@@ -1,6 +1,6 @@
1
1
  import { DateRange } from "@trackunit/date-and-time-utils";
2
2
  import { TemporalArithmeticType, TemporalSameType } from "@trackunit/react-date-and-time-hooks";
3
- export type TemporalUnit = Exclude<TemporalArithmeticType | TemporalSameType, "year" | "hours" | "minutes" | "years">;
3
+ export type TemporalUnit = Extract<TemporalArithmeticType | TemporalSameType, "day" | "days">;
4
4
  export type TemporalDirection = "next" | "last";
5
5
  export type TemporalPeriod = {
6
6
  direction: TemporalDirection;
@@ -7,6 +7,6 @@ import { TemporalPeriod } from "../../types";
7
7
  *
8
8
  * @example
9
9
  * createTemporalPeriodCombinations({ direction: "last", count: 2, unit: "days" }); // [{ direction: "last", count: 2, unit: "days" }]
10
- * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }, { direction: "next", count: 1, unit: "week" }, { direction: "next", count: 1, unit: "month" }]
10
+ * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }]
11
11
  */
12
12
  export declare const createTemporalPeriodCombinations: ({ direction, count, unit, }: Partial<TemporalPeriod>) => Array<TemporalPeriod>;
@@ -12,7 +12,7 @@ var translation = {
12
12
  "input.today": "Heute",
13
13
  "input.unit.day": "Tag",
14
14
  "input.unit.days": "Tage",
15
- "input.unit.month": "monat",
15
+ "input.unit.month": "Monat",
16
16
  "input.unit.months": "Monate",
17
17
  "input.unit.week": "Woche",
18
18
  "input.unit.weeks": "Wochen",
@@ -10,7 +10,7 @@ var translation = {
10
10
  "input.today": "Heute",
11
11
  "input.unit.day": "Tag",
12
12
  "input.unit.days": "Tage",
13
- "input.unit.month": "monat",
13
+ "input.unit.month": "Monat",
14
14
  "input.unit.months": "Monate",
15
15
  "input.unit.week": "Woche",
16
16
  "input.unit.weeks": "Wochen",