@zag-js/date-utils 1.24.1 → 1.25.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/dist/index.d.mts CHANGED
@@ -68,7 +68,9 @@ interface YearsRange {
68
68
  }
69
69
  declare function getYearsRange(range: YearsRange): number[];
70
70
  declare function normalizeYear(year: string | null | undefined): string | undefined;
71
- declare function getDecadeRange(year: number): number[];
71
+ declare function getDecadeRange(year: number, opts?: {
72
+ strict?: boolean;
73
+ }): number[];
72
74
 
73
75
  declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
74
76
  declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
package/dist/index.d.ts CHANGED
@@ -68,7 +68,9 @@ interface YearsRange {
68
68
  }
69
69
  declare function getYearsRange(range: YearsRange): number[];
70
70
  declare function normalizeYear(year: string | null | undefined): string | undefined;
71
- declare function getDecadeRange(year: number): number[];
71
+ declare function getDecadeRange(year: number, opts?: {
72
+ strict?: boolean;
73
+ }): number[];
72
74
 
73
75
  declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
74
76
  declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
package/dist/index.js CHANGED
@@ -271,10 +271,11 @@ function normalizeYear(year) {
271
271
  }
272
272
  return year;
273
273
  }
274
- function getDecadeRange(year) {
275
- const computedYear = year - year % 10 - 1;
274
+ function getDecadeRange(year, opts) {
275
+ const chunkSize = opts?.strict ? 10 : 12;
276
+ const computedYear = year - year % 10;
276
277
  const years = [];
277
- for (let i = 0; i < 12; i += 1) {
278
+ for (let i = 0; i < chunkSize; i += 1) {
278
279
  const value = computedYear + i;
279
280
  years.push(value);
280
281
  }
@@ -530,7 +531,7 @@ function getDateRangePreset(preset, locale, timeZone) {
530
531
  case "thisMonth":
531
532
  return [date.startOfMonth(today3), today3];
532
533
  case "thisQuarter":
533
- return [date.startOfMonth(today3).add({ months: -today3.month % 3 }), today3];
534
+ return [date.startOfMonth(today3).add({ months: -((today3.month - 1) % 3) }), today3];
534
535
  case "thisYear":
535
536
  return [date.startOfYear(today3), today3];
536
537
  case "last3Days":
@@ -547,8 +548,8 @@ function getDateRangePreset(preset, locale, timeZone) {
547
548
  return [date.startOfMonth(today3.add({ months: -1 })), date.endOfMonth(today3.add({ months: -1 }))];
548
549
  case "lastQuarter":
549
550
  return [
550
- date.startOfMonth(today3.add({ months: -today3.month % 3 - 3 })),
551
- date.endOfMonth(today3.add({ months: -today3.month % 3 - 1 }))
551
+ date.startOfMonth(today3.add({ months: -((today3.month - 1) % 3) - 3 })),
552
+ date.endOfMonth(today3.add({ months: -((today3.month - 1) % 3) - 1 }))
552
553
  ];
553
554
  case "lastWeek":
554
555
  return [date.startOfWeek(today3, locale).add({ weeks: -1 }), date.endOfWeek(today3, locale).add({ weeks: -1 })];
package/dist/index.mjs CHANGED
@@ -269,10 +269,11 @@ function normalizeYear(year) {
269
269
  }
270
270
  return year;
271
271
  }
272
- function getDecadeRange(year) {
273
- const computedYear = year - year % 10 - 1;
272
+ function getDecadeRange(year, opts) {
273
+ const chunkSize = opts?.strict ? 10 : 12;
274
+ const computedYear = year - year % 10;
274
275
  const years = [];
275
- for (let i = 0; i < 12; i += 1) {
276
+ for (let i = 0; i < chunkSize; i += 1) {
276
277
  const value = computedYear + i;
277
278
  years.push(value);
278
279
  }
@@ -528,7 +529,7 @@ function getDateRangePreset(preset, locale, timeZone) {
528
529
  case "thisMonth":
529
530
  return [startOfMonth(today3), today3];
530
531
  case "thisQuarter":
531
- return [startOfMonth(today3).add({ months: -today3.month % 3 }), today3];
532
+ return [startOfMonth(today3).add({ months: -((today3.month - 1) % 3) }), today3];
532
533
  case "thisYear":
533
534
  return [startOfYear(today3), today3];
534
535
  case "last3Days":
@@ -545,8 +546,8 @@ function getDateRangePreset(preset, locale, timeZone) {
545
546
  return [startOfMonth(today3.add({ months: -1 })), endOfMonth(today3.add({ months: -1 }))];
546
547
  case "lastQuarter":
547
548
  return [
548
- startOfMonth(today3.add({ months: -today3.month % 3 - 3 })),
549
- endOfMonth(today3.add({ months: -today3.month % 3 - 1 }))
549
+ startOfMonth(today3.add({ months: -((today3.month - 1) % 3) - 3 })),
550
+ endOfMonth(today3.add({ months: -((today3.month - 1) % 3) - 1 }))
550
551
  ];
551
552
  case "lastWeek":
552
553
  return [startOfWeek(today3, locale).add({ weeks: -1 }), endOfWeek(today3, locale).add({ weeks: -1 })];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/date-utils",
3
- "version": "1.24.1",
3
+ "version": "1.25.0",
4
4
  "description": "Date utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",