@abgov/react-components 6.11.0-dev.12 → 6.11.0-dev.15

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.
@@ -1,3 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1
4
  const lowercase = (input) => input.toLowerCase();
2
5
  const kebab = (input) => input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
3
6
  function transformProps(props, transform = lowercase) {
@@ -29,6 +32,36 @@ function constructFrom(date, value) {
29
32
  return new Date(value);
30
33
  }
31
34
  }
35
+ function addDays(date, amount) {
36
+ const _date = toDate(date);
37
+ if (isNaN(amount)) return constructFrom(date, NaN);
38
+ if (!amount) {
39
+ return _date;
40
+ }
41
+ _date.setDate(_date.getDate() + amount);
42
+ return _date;
43
+ }
44
+ function addMonths(date, amount) {
45
+ const _date = toDate(date);
46
+ if (isNaN(amount)) return constructFrom(date, NaN);
47
+ if (!amount) {
48
+ return _date;
49
+ }
50
+ const dayOfMonth = _date.getDate();
51
+ const endOfDesiredMonth = constructFrom(date, _date.getTime());
52
+ endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
53
+ const daysInMonth = endOfDesiredMonth.getDate();
54
+ if (dayOfMonth >= daysInMonth) {
55
+ return endOfDesiredMonth;
56
+ } else {
57
+ _date.setFullYear(
58
+ endOfDesiredMonth.getFullYear(),
59
+ endOfDesiredMonth.getMonth(),
60
+ dayOfMonth
61
+ );
62
+ return _date;
63
+ }
64
+ }
32
65
  const millisecondsInWeek = 6048e5;
33
66
  const millisecondsInDay = 864e5;
34
67
  const millisecondsInMinute = 6e4;
@@ -105,6 +138,11 @@ function startOfISOWeekYear(date) {
105
138
  fourthOfJanuary.setHours(0, 0, 0, 0);
106
139
  return startOfISOWeek(fourthOfJanuary);
107
140
  }
141
+ function isSameDay(dateLeft, dateRight) {
142
+ const dateLeftStartOfDay = startOfDay(dateLeft);
143
+ const dateRightStartOfDay = startOfDay(dateRight);
144
+ return +dateLeftStartOfDay === +dateRightStartOfDay;
145
+ }
108
146
  function isDate(value) {
109
147
  return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
110
148
  }
@@ -1504,6 +1542,37 @@ function cleanEscapedString(input) {
1504
1542
  }
1505
1543
  return matched[1].replace(doubleQuoteRegExp, "'");
1506
1544
  }
1545
+ function getDaysInMonth(date) {
1546
+ const _date = toDate(date);
1547
+ const year = _date.getFullYear();
1548
+ const monthIndex = _date.getMonth();
1549
+ const lastDayOfMonth2 = constructFrom(date, 0);
1550
+ lastDayOfMonth2.setFullYear(year, monthIndex + 1, 0);
1551
+ lastDayOfMonth2.setHours(0, 0, 0, 0);
1552
+ return lastDayOfMonth2.getDate();
1553
+ }
1554
+ function lastDayOfMonth(date) {
1555
+ const _date = toDate(date);
1556
+ const month = _date.getMonth();
1557
+ _date.setFullYear(_date.getFullYear(), month + 1, 0);
1558
+ _date.setHours(0, 0, 0, 0);
1559
+ return _date;
1560
+ }
1561
+ function isAfter(date, dateToCompare) {
1562
+ const _date = toDate(date);
1563
+ const _dateToCompare = toDate(dateToCompare);
1564
+ return _date.getTime() > _dateToCompare.getTime();
1565
+ }
1566
+ function isBefore(date, dateToCompare) {
1567
+ const _date = toDate(date);
1568
+ const _dateToCompare = toDate(dateToCompare);
1569
+ return +_date < +_dateToCompare;
1570
+ }
1571
+ function isSameMonth(dateLeft, dateRight) {
1572
+ const _dateLeft = toDate(dateLeft);
1573
+ const _dateRight = toDate(dateRight);
1574
+ return _dateLeft.getFullYear() === _dateRight.getFullYear() && _dateLeft.getMonth() === _dateRight.getMonth();
1575
+ }
1507
1576
  function parseISO(argument, options) {
1508
1577
  const additionalDigits = 2;
1509
1578
  const dateStrings = splitDateString(argument);
@@ -1682,7 +1751,139 @@ function validateTime(hours, minutes, seconds) {
1682
1751
  function validateTimezone(_hours, minutes) {
1683
1752
  return minutes >= 0 && minutes <= 59;
1684
1753
  }
1754
+ class CalendarDate {
1755
+ constructor(value) {
1756
+ __publicField(this, "_dateNums");
1757
+ if (value || value === 0) {
1758
+ this._dateNums = CalendarDate.parse(value);
1759
+ } else {
1760
+ this._dateNums = CalendarDate.parse(/* @__PURE__ */ new Date());
1761
+ }
1762
+ }
1763
+ static parse(value) {
1764
+ if (typeof value === "string") {
1765
+ value = value.split("T")[0];
1766
+ return value.split("-").map((v) => +v);
1767
+ } else if (value instanceof Date) {
1768
+ return [value.getFullYear(), value.getMonth() + 1, value.getDate()];
1769
+ } else if (value === 0) {
1770
+ return [0, 0, 0];
1771
+ } else {
1772
+ return [value.year, value.month, value.day];
1773
+ }
1774
+ }
1775
+ static init() {
1776
+ return new CalendarDate(0);
1777
+ }
1778
+ // Used internally to get the date value for the date_fns
1779
+ get date() {
1780
+ return new Date(
1781
+ this._dateNums[0],
1782
+ this._dateNums[1] - 1,
1783
+ this._dateNums[2]
1784
+ );
1785
+ }
1786
+ get year() {
1787
+ return this._dateNums[0];
1788
+ }
1789
+ get month() {
1790
+ return this._dateNums[1];
1791
+ }
1792
+ get day() {
1793
+ return this._dateNums[2];
1794
+ }
1795
+ get dayOfWeek() {
1796
+ return this.date.getDay();
1797
+ }
1798
+ get daysInMonth() {
1799
+ return getDaysInMonth(this.date);
1800
+ }
1801
+ get firstDayOfMonth() {
1802
+ return new CalendarDate({ year: this.year, month: this.month, day: 1 });
1803
+ }
1804
+ get lastDayOfMonth() {
1805
+ return new CalendarDate(lastDayOfMonth(this.date));
1806
+ }
1807
+ get previousDay() {
1808
+ return this.clone().addDays(-1);
1809
+ }
1810
+ get nextDay() {
1811
+ return this.clone().addDays(1);
1812
+ }
1813
+ get previousWeek() {
1814
+ return this.clone().addDays(-7);
1815
+ }
1816
+ get nextWeek() {
1817
+ return this.clone().addDays(7);
1818
+ }
1819
+ get previousMonth() {
1820
+ return this.clone().addMonths(-1);
1821
+ }
1822
+ get nextMonth() {
1823
+ return this.clone().addMonths(1);
1824
+ }
1825
+ clone() {
1826
+ return new CalendarDate(this.toString());
1827
+ }
1828
+ setYear(val) {
1829
+ this._dateNums[0] = val;
1830
+ }
1831
+ setMonth(val) {
1832
+ this._dateNums[1] = val;
1833
+ }
1834
+ setDay(val) {
1835
+ this._dateNums[2] = val;
1836
+ return this;
1837
+ }
1838
+ addYears(count) {
1839
+ this._dateNums[0] += count;
1840
+ return this;
1841
+ }
1842
+ addMonths(count) {
1843
+ this._dateNums = CalendarDate.parse(addMonths(this.date, count));
1844
+ return this;
1845
+ }
1846
+ addDays(count) {
1847
+ this._dateNums = CalendarDate.parse(addDays(this.date, count));
1848
+ return this;
1849
+ }
1850
+ isSameDay(cmp) {
1851
+ return isSameDay(this.date, cmp.date);
1852
+ }
1853
+ isSameMonth(value) {
1854
+ return isSameMonth(this.date, value.date);
1855
+ }
1856
+ isBefore(cmp) {
1857
+ return isBefore(this.date, cmp.date);
1858
+ }
1859
+ isAfter(cmp) {
1860
+ return isAfter(this.date, cmp.date);
1861
+ }
1862
+ isZero() {
1863
+ return this._dateNums[0] === 0 && this._dateNums[1] === 0 && this._dateNums[2] === 0;
1864
+ }
1865
+ isValid() {
1866
+ const comparisonDate = new Date(this.toString());
1867
+ if (isNaN(comparisonDate.getTime()) || this.toString() !== comparisonDate.toISOString().split("T")[0]) {
1868
+ return false;
1869
+ }
1870
+ return true;
1871
+ }
1872
+ format(tmpl) {
1873
+ if (this.isZero()) {
1874
+ return "";
1875
+ }
1876
+ return format(this.date, tmpl);
1877
+ }
1878
+ toString() {
1879
+ if (this.isZero()) {
1880
+ return "";
1881
+ }
1882
+ return this._dateNums.map((num) => `${num}`.length < 2 ? `0${num}` : `${num}`).join("-");
1883
+ }
1884
+ }
1685
1885
  export {
1886
+ CalendarDate as C,
1686
1887
  format as f,
1687
1888
  isValid as i,
1688
1889
  kebab as k,
@@ -1690,4 +1891,4 @@ export {
1690
1891
  parseISO as p,
1691
1892
  transformProps as t
1692
1893
  };
1693
- //# sourceMappingURL=parseISO-BHUUf1QW.mjs.map
1894
+ //# sourceMappingURL=calendar-date-Chmr7h4a.mjs.map