@uxf/datepicker 11.90.0 → 11.93.2

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,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getDateIntervals = getDateIntervals;
7
4
  const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
8
- const dayjs_1 = __importDefault(require("dayjs"));
5
+ const dayjs_en_1 = require("./dayjs-en");
9
6
  function getDateIntervals(dates) {
10
7
  const sortedDates = dates.slice().sort((a, b) => a.getTime() - b.getTime());
11
8
  const intervals = [];
@@ -14,9 +11,9 @@ function getDateIntervals(dates) {
14
11
  let currentEnd = firstSortedDate !== null && firstSortedDate !== void 0 ? firstSortedDate : new Date();
15
12
  for (let i = 1; i < sortedDates.length; i++) {
16
13
  const currentDate = sortedDates[i];
17
- const nextDate = (0, dayjs_1.default)(currentEnd).add(1, "day").toDate();
14
+ const nextDate = (0, dayjs_en_1.dayjsEn)(currentEnd).add(1, "day").toDate();
18
15
  // If the current date matches the expected next date, it's contiguous
19
- if ((0, dayjs_1.default)(currentDate).isSame(nextDate, "day")) {
16
+ if ((0, dayjs_en_1.dayjsEn)(currentDate).isSame(nextDate, "day")) {
20
17
  currentEnd = currentDate;
21
18
  }
22
19
  else {
@@ -5,11 +5,11 @@ test("getDateMonthAndYear", () => {
5
5
  expect((0, get_date_month_and_year_1.getDateMonthAndYear)(new Date("2021-08-10"))).toStrictEqual({
6
6
  year: 2021,
7
7
  month: 7,
8
- date: new Date("2021-08-01"),
8
+ date: new Date("2021-08-01T00:00:00+02:00"),
9
9
  });
10
10
  expect((0, get_date_month_and_year_1.getDateMonthAndYear)(new Date("2020-02-15"))).toStrictEqual({
11
11
  year: 2020,
12
12
  month: 1,
13
- date: new Date("2020-02-01"),
13
+ date: new Date("2020-02-01T00:00:00+01:00"),
14
14
  });
15
15
  });
package/utils/get-days.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDays = getDays;
4
+ const create_date_string_1 = require("./create-date-string");
4
5
  const dayjs_en_1 = require("./dayjs-en");
5
6
  const get_each_1 = require("./get-each");
6
7
  function getDays({ year, month, firstDayOfWeek = 0, dayLabelFormat = (date) => (0, dayjs_en_1.dayjsEn)(date).format("DD"), }) {
7
- const date = new Date(year, month);
8
+ const date = new Date((0, create_date_string_1.createDateString)(year, month));
8
9
  const lastDayOfWeek = firstDayOfWeek + 7;
9
10
  const monthStart = (0, dayjs_en_1.dayjsEn)(date).startOf("month").toDate();
10
11
  const monthStartDay = (0, dayjs_en_1.dayjsEn)(monthStart).day();
@@ -1,138 +1,135 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const dayjs_1 = __importDefault(require("dayjs"));
3
+ const dayjs_en_1 = require("./dayjs-en");
7
4
  const get_days_1 = require("./get-days");
8
5
  test("getDays", () => {
9
6
  expect((0, get_days_1.getDays)({ year: 2021, month: 0 })).toStrictEqual([
10
- { dayLabel: "27", date: new Date("2020-12-27"), currentMonth: false },
11
- { dayLabel: "28", date: new Date("2020-12-28"), currentMonth: false },
12
- { dayLabel: "29", date: new Date("2020-12-29"), currentMonth: false },
13
- { dayLabel: "30", date: new Date("2020-12-30"), currentMonth: false },
14
- { dayLabel: "31", date: new Date("2020-12-31"), currentMonth: false },
15
- { dayLabel: "01", date: new Date("2021-01-01"), currentMonth: true },
16
- { dayLabel: "02", date: new Date("2021-01-02"), currentMonth: true },
17
- { dayLabel: "03", date: new Date("2021-01-03"), currentMonth: true },
18
- { dayLabel: "04", date: new Date("2021-01-04"), currentMonth: true },
19
- { dayLabel: "05", date: new Date("2021-01-05"), currentMonth: true },
20
- { dayLabel: "06", date: new Date("2021-01-06"), currentMonth: true },
21
- { dayLabel: "07", date: new Date("2021-01-07"), currentMonth: true },
22
- { dayLabel: "08", date: new Date("2021-01-08"), currentMonth: true },
23
- { dayLabel: "09", date: new Date("2021-01-09"), currentMonth: true },
24
- { dayLabel: "10", date: new Date("2021-01-10"), currentMonth: true },
25
- { dayLabel: "11", date: new Date("2021-01-11"), currentMonth: true },
26
- { dayLabel: "12", date: new Date("2021-01-12"), currentMonth: true },
27
- { dayLabel: "13", date: new Date("2021-01-13"), currentMonth: true },
28
- { dayLabel: "14", date: new Date("2021-01-14"), currentMonth: true },
29
- { dayLabel: "15", date: new Date("2021-01-15"), currentMonth: true },
30
- { dayLabel: "16", date: new Date("2021-01-16"), currentMonth: true },
31
- { dayLabel: "17", date: new Date("2021-01-17"), currentMonth: true },
32
- { dayLabel: "18", date: new Date("2021-01-18"), currentMonth: true },
33
- { dayLabel: "19", date: new Date("2021-01-19"), currentMonth: true },
34
- { dayLabel: "20", date: new Date("2021-01-20"), currentMonth: true },
35
- { dayLabel: "21", date: new Date("2021-01-21"), currentMonth: true },
36
- { dayLabel: "22", date: new Date("2021-01-22"), currentMonth: true },
37
- { dayLabel: "23", date: new Date("2021-01-23"), currentMonth: true },
38
- { dayLabel: "24", date: new Date("2021-01-24"), currentMonth: true },
39
- { dayLabel: "25", date: new Date("2021-01-25"), currentMonth: true },
40
- { dayLabel: "26", date: new Date("2021-01-26"), currentMonth: true },
41
- { dayLabel: "27", date: new Date("2021-01-27"), currentMonth: true },
42
- { dayLabel: "28", date: new Date("2021-01-28"), currentMonth: true },
43
- { dayLabel: "29", date: new Date("2021-01-29"), currentMonth: true },
44
- { dayLabel: "30", date: new Date("2021-01-30"), currentMonth: true },
45
- { dayLabel: "31", date: new Date("2021-01-31"), currentMonth: true },
46
- { dayLabel: "01", date: new Date("2021-02-01"), currentMonth: false },
47
- { dayLabel: "02", date: new Date("2021-02-02"), currentMonth: false },
48
- { dayLabel: "03", date: new Date("2021-02-03"), currentMonth: false },
49
- { dayLabel: "04", date: new Date("2021-02-04"), currentMonth: false },
50
- { dayLabel: "05", date: new Date("2021-02-05"), currentMonth: false },
51
- { dayLabel: "06", date: new Date("2021-02-06"), currentMonth: false },
7
+ { dayLabel: "27", date: new Date("2020-12-27T00:00:00+01:00"), currentMonth: false },
8
+ { dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00"), currentMonth: false },
9
+ { dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00"), currentMonth: false },
10
+ { dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00"), currentMonth: false },
11
+ { dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00"), currentMonth: false },
12
+ { dayLabel: "01", date: new Date("2021-01-01T00:00:00+01:00"), currentMonth: true },
13
+ { dayLabel: "02", date: new Date("2021-01-02T00:00:00+01:00"), currentMonth: true },
14
+ { dayLabel: "03", date: new Date("2021-01-03T00:00:00+01:00"), currentMonth: true },
15
+ { dayLabel: "04", date: new Date("2021-01-04T00:00:00+01:00"), currentMonth: true },
16
+ { dayLabel: "05", date: new Date("2021-01-05T00:00:00+01:00"), currentMonth: true },
17
+ { dayLabel: "06", date: new Date("2021-01-06T00:00:00+01:00"), currentMonth: true },
18
+ { dayLabel: "07", date: new Date("2021-01-07T00:00:00+01:00"), currentMonth: true },
19
+ { dayLabel: "08", date: new Date("2021-01-08T00:00:00+01:00"), currentMonth: true },
20
+ { dayLabel: "09", date: new Date("2021-01-09T00:00:00+01:00"), currentMonth: true },
21
+ { dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00"), currentMonth: true },
22
+ { dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00"), currentMonth: true },
23
+ { dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00"), currentMonth: true },
24
+ { dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00"), currentMonth: true },
25
+ { dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00"), currentMonth: true },
26
+ { dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00"), currentMonth: true },
27
+ { dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00"), currentMonth: true },
28
+ { dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00"), currentMonth: true },
29
+ { dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00"), currentMonth: true },
30
+ { dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00"), currentMonth: true },
31
+ { dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00"), currentMonth: true },
32
+ { dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00"), currentMonth: true },
33
+ { dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00"), currentMonth: true },
34
+ { dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00"), currentMonth: true },
35
+ { dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00"), currentMonth: true },
36
+ { dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00"), currentMonth: true },
37
+ { dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00"), currentMonth: true },
38
+ { dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00"), currentMonth: true },
39
+ { dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00"), currentMonth: true },
40
+ { dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00"), currentMonth: true },
41
+ { dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00"), currentMonth: true },
42
+ { dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00"), currentMonth: true },
43
+ { dayLabel: "01", date: new Date("2021-02-01T00:00:00+01:00"), currentMonth: false },
44
+ { dayLabel: "02", date: new Date("2021-02-02T00:00:00+01:00"), currentMonth: false },
45
+ { dayLabel: "03", date: new Date("2021-02-03T00:00:00+01:00"), currentMonth: false },
46
+ { dayLabel: "04", date: new Date("2021-02-04T00:00:00+01:00"), currentMonth: false },
47
+ { dayLabel: "05", date: new Date("2021-02-05T00:00:00+01:00"), currentMonth: false },
48
+ { dayLabel: "06", date: new Date("2021-02-06T00:00:00+01:00"), currentMonth: false },
52
49
  ]);
53
50
  });
54
51
  test("getDays with custom format", () => {
55
- expect((0, get_days_1.getDays)({ year: 2021, month: 0, dayLabelFormat: (date) => (0, dayjs_1.default)(date).format("D") })).toStrictEqual([
56
- { dayLabel: "27", date: new Date("2020-12-27"), currentMonth: false },
57
- { dayLabel: "28", date: new Date("2020-12-28"), currentMonth: false },
58
- { dayLabel: "29", date: new Date("2020-12-29"), currentMonth: false },
59
- { dayLabel: "30", date: new Date("2020-12-30"), currentMonth: false },
60
- { dayLabel: "31", date: new Date("2020-12-31"), currentMonth: false },
61
- { dayLabel: "1", date: new Date("2021-01-01"), currentMonth: true },
62
- { dayLabel: "2", date: new Date("2021-01-02"), currentMonth: true },
63
- { dayLabel: "3", date: new Date("2021-01-03"), currentMonth: true },
64
- { dayLabel: "4", date: new Date("2021-01-04"), currentMonth: true },
65
- { dayLabel: "5", date: new Date("2021-01-05"), currentMonth: true },
66
- { dayLabel: "6", date: new Date("2021-01-06"), currentMonth: true },
67
- { dayLabel: "7", date: new Date("2021-01-07"), currentMonth: true },
68
- { dayLabel: "8", date: new Date("2021-01-08"), currentMonth: true },
69
- { dayLabel: "9", date: new Date("2021-01-09"), currentMonth: true },
70
- { dayLabel: "10", date: new Date("2021-01-10"), currentMonth: true },
71
- { dayLabel: "11", date: new Date("2021-01-11"), currentMonth: true },
72
- { dayLabel: "12", date: new Date("2021-01-12"), currentMonth: true },
73
- { dayLabel: "13", date: new Date("2021-01-13"), currentMonth: true },
74
- { dayLabel: "14", date: new Date("2021-01-14"), currentMonth: true },
75
- { dayLabel: "15", date: new Date("2021-01-15"), currentMonth: true },
76
- { dayLabel: "16", date: new Date("2021-01-16"), currentMonth: true },
77
- { dayLabel: "17", date: new Date("2021-01-17"), currentMonth: true },
78
- { dayLabel: "18", date: new Date("2021-01-18"), currentMonth: true },
79
- { dayLabel: "19", date: new Date("2021-01-19"), currentMonth: true },
80
- { dayLabel: "20", date: new Date("2021-01-20"), currentMonth: true },
81
- { dayLabel: "21", date: new Date("2021-01-21"), currentMonth: true },
82
- { dayLabel: "22", date: new Date("2021-01-22"), currentMonth: true },
83
- { dayLabel: "23", date: new Date("2021-01-23"), currentMonth: true },
84
- { dayLabel: "24", date: new Date("2021-01-24"), currentMonth: true },
85
- { dayLabel: "25", date: new Date("2021-01-25"), currentMonth: true },
86
- { dayLabel: "26", date: new Date("2021-01-26"), currentMonth: true },
87
- { dayLabel: "27", date: new Date("2021-01-27"), currentMonth: true },
88
- { dayLabel: "28", date: new Date("2021-01-28"), currentMonth: true },
89
- { dayLabel: "29", date: new Date("2021-01-29"), currentMonth: true },
90
- { dayLabel: "30", date: new Date("2021-01-30"), currentMonth: true },
91
- { dayLabel: "31", date: new Date("2021-01-31"), currentMonth: true },
92
- { dayLabel: "1", date: new Date("2021-02-01"), currentMonth: false },
93
- { dayLabel: "2", date: new Date("2021-02-02"), currentMonth: false },
94
- { dayLabel: "3", date: new Date("2021-02-03"), currentMonth: false },
95
- { dayLabel: "4", date: new Date("2021-02-04"), currentMonth: false },
96
- { dayLabel: "5", date: new Date("2021-02-05"), currentMonth: false },
97
- { dayLabel: "6", date: new Date("2021-02-06"), currentMonth: false },
52
+ expect((0, get_days_1.getDays)({ year: 2021, month: 0, dayLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("D") })).toStrictEqual([
53
+ { dayLabel: "27", date: new Date("2020-12-27T00:00:00+01:00"), currentMonth: false },
54
+ { dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00"), currentMonth: false },
55
+ { dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00"), currentMonth: false },
56
+ { dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00"), currentMonth: false },
57
+ { dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00"), currentMonth: false },
58
+ { dayLabel: "1", date: new Date("2021-01-01T00:00:00+01:00"), currentMonth: true },
59
+ { dayLabel: "2", date: new Date("2021-01-02T00:00:00+01:00"), currentMonth: true },
60
+ { dayLabel: "3", date: new Date("2021-01-03T00:00:00+01:00"), currentMonth: true },
61
+ { dayLabel: "4", date: new Date("2021-01-04T00:00:00+01:00"), currentMonth: true },
62
+ { dayLabel: "5", date: new Date("2021-01-05T00:00:00+01:00"), currentMonth: true },
63
+ { dayLabel: "6", date: new Date("2021-01-06T00:00:00+01:00"), currentMonth: true },
64
+ { dayLabel: "7", date: new Date("2021-01-07T00:00:00+01:00"), currentMonth: true },
65
+ { dayLabel: "8", date: new Date("2021-01-08T00:00:00+01:00"), currentMonth: true },
66
+ { dayLabel: "9", date: new Date("2021-01-09T00:00:00+01:00"), currentMonth: true },
67
+ { dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00"), currentMonth: true },
68
+ { dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00"), currentMonth: true },
69
+ { dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00"), currentMonth: true },
70
+ { dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00"), currentMonth: true },
71
+ { dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00"), currentMonth: true },
72
+ { dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00"), currentMonth: true },
73
+ { dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00"), currentMonth: true },
74
+ { dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00"), currentMonth: true },
75
+ { dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00"), currentMonth: true },
76
+ { dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00"), currentMonth: true },
77
+ { dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00"), currentMonth: true },
78
+ { dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00"), currentMonth: true },
79
+ { dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00"), currentMonth: true },
80
+ { dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00"), currentMonth: true },
81
+ { dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00"), currentMonth: true },
82
+ { dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00"), currentMonth: true },
83
+ { dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00"), currentMonth: true },
84
+ { dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00"), currentMonth: true },
85
+ { dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00"), currentMonth: true },
86
+ { dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00"), currentMonth: true },
87
+ { dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00"), currentMonth: true },
88
+ { dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00"), currentMonth: true },
89
+ { dayLabel: "1", date: new Date("2021-02-01T00:00:00+01:00"), currentMonth: false },
90
+ { dayLabel: "2", date: new Date("2021-02-02T00:00:00+01:00"), currentMonth: false },
91
+ { dayLabel: "3", date: new Date("2021-02-03T00:00:00+01:00"), currentMonth: false },
92
+ { dayLabel: "4", date: new Date("2021-02-04T00:00:00+01:00"), currentMonth: false },
93
+ { dayLabel: "5", date: new Date("2021-02-05T00:00:00+01:00"), currentMonth: false },
94
+ { dayLabel: "6", date: new Date("2021-02-06T00:00:00+01:00"), currentMonth: false },
98
95
  ]);
99
96
  });
100
97
  test("getDays with custom firstDayOfWeek", () => {
101
98
  expect((0, get_days_1.getDays)({ year: 2021, month: 0, firstDayOfWeek: 1 })).toStrictEqual([
102
- { dayLabel: "28", date: new Date("2020-12-28"), currentMonth: false },
103
- { dayLabel: "29", date: new Date("2020-12-29"), currentMonth: false },
104
- { dayLabel: "30", date: new Date("2020-12-30"), currentMonth: false },
105
- { dayLabel: "31", date: new Date("2020-12-31"), currentMonth: false },
106
- { dayLabel: "01", date: new Date("2021-01-01"), currentMonth: true },
107
- { dayLabel: "02", date: new Date("2021-01-02"), currentMonth: true },
108
- { dayLabel: "03", date: new Date("2021-01-03"), currentMonth: true },
109
- { dayLabel: "04", date: new Date("2021-01-04"), currentMonth: true },
110
- { dayLabel: "05", date: new Date("2021-01-05"), currentMonth: true },
111
- { dayLabel: "06", date: new Date("2021-01-06"), currentMonth: true },
112
- { dayLabel: "07", date: new Date("2021-01-07"), currentMonth: true },
113
- { dayLabel: "08", date: new Date("2021-01-08"), currentMonth: true },
114
- { dayLabel: "09", date: new Date("2021-01-09"), currentMonth: true },
115
- { dayLabel: "10", date: new Date("2021-01-10"), currentMonth: true },
116
- { dayLabel: "11", date: new Date("2021-01-11"), currentMonth: true },
117
- { dayLabel: "12", date: new Date("2021-01-12"), currentMonth: true },
118
- { dayLabel: "13", date: new Date("2021-01-13"), currentMonth: true },
119
- { dayLabel: "14", date: new Date("2021-01-14"), currentMonth: true },
120
- { dayLabel: "15", date: new Date("2021-01-15"), currentMonth: true },
121
- { dayLabel: "16", date: new Date("2021-01-16"), currentMonth: true },
122
- { dayLabel: "17", date: new Date("2021-01-17"), currentMonth: true },
123
- { dayLabel: "18", date: new Date("2021-01-18"), currentMonth: true },
124
- { dayLabel: "19", date: new Date("2021-01-19"), currentMonth: true },
125
- { dayLabel: "20", date: new Date("2021-01-20"), currentMonth: true },
126
- { dayLabel: "21", date: new Date("2021-01-21"), currentMonth: true },
127
- { dayLabel: "22", date: new Date("2021-01-22"), currentMonth: true },
128
- { dayLabel: "23", date: new Date("2021-01-23"), currentMonth: true },
129
- { dayLabel: "24", date: new Date("2021-01-24"), currentMonth: true },
130
- { dayLabel: "25", date: new Date("2021-01-25"), currentMonth: true },
131
- { dayLabel: "26", date: new Date("2021-01-26"), currentMonth: true },
132
- { dayLabel: "27", date: new Date("2021-01-27"), currentMonth: true },
133
- { dayLabel: "28", date: new Date("2021-01-28"), currentMonth: true },
134
- { dayLabel: "29", date: new Date("2021-01-29"), currentMonth: true },
135
- { dayLabel: "30", date: new Date("2021-01-30"), currentMonth: true },
136
- { dayLabel: "31", date: new Date("2021-01-31"), currentMonth: true },
99
+ { dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00"), currentMonth: false },
100
+ { dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00"), currentMonth: false },
101
+ { dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00"), currentMonth: false },
102
+ { dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00"), currentMonth: false },
103
+ { dayLabel: "01", date: new Date("2021-01-01T00:00:00+01:00"), currentMonth: true },
104
+ { dayLabel: "02", date: new Date("2021-01-02T00:00:00+01:00"), currentMonth: true },
105
+ { dayLabel: "03", date: new Date("2021-01-03T00:00:00+01:00"), currentMonth: true },
106
+ { dayLabel: "04", date: new Date("2021-01-04T00:00:00+01:00"), currentMonth: true },
107
+ { dayLabel: "05", date: new Date("2021-01-05T00:00:00+01:00"), currentMonth: true },
108
+ { dayLabel: "06", date: new Date("2021-01-06T00:00:00+01:00"), currentMonth: true },
109
+ { dayLabel: "07", date: new Date("2021-01-07T00:00:00+01:00"), currentMonth: true },
110
+ { dayLabel: "08", date: new Date("2021-01-08T00:00:00+01:00"), currentMonth: true },
111
+ { dayLabel: "09", date: new Date("2021-01-09T00:00:00+01:00"), currentMonth: true },
112
+ { dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00"), currentMonth: true },
113
+ { dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00"), currentMonth: true },
114
+ { dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00"), currentMonth: true },
115
+ { dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00"), currentMonth: true },
116
+ { dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00"), currentMonth: true },
117
+ { dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00"), currentMonth: true },
118
+ { dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00"), currentMonth: true },
119
+ { dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00"), currentMonth: true },
120
+ { dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00"), currentMonth: true },
121
+ { dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00"), currentMonth: true },
122
+ { dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00"), currentMonth: true },
123
+ { dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00"), currentMonth: true },
124
+ { dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00"), currentMonth: true },
125
+ { dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00"), currentMonth: true },
126
+ { dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00"), currentMonth: true },
127
+ { dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00"), currentMonth: true },
128
+ { dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00"), currentMonth: true },
129
+ { dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00"), currentMonth: true },
130
+ { dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00"), currentMonth: true },
131
+ { dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00"), currentMonth: true },
132
+ { dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00"), currentMonth: true },
133
+ { dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00"), currentMonth: true },
137
134
  ]);
138
135
  });
package/utils/get-each.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEach = getEach;
4
4
  const dayjs_en_1 = require("./dayjs-en");
5
5
  function getEach(start, end, type, arr = [(0, dayjs_en_1.dayjsEn)(start).startOf(type).toDate()]) {
6
- if ((0, dayjs_en_1.dayjsEn)(start).isAfter(end)) {
6
+ if ((0, dayjs_en_1.dayjsEn)(start).isAfter(end, type)) {
7
7
  throw new Error("start must precede end");
8
8
  }
9
9
  const next = (0, dayjs_en_1.dayjsEn)(start).add(1, type).startOf(type).toDate();
@@ -2,30 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const get_each_1 = require("./get-each");
4
4
  test("getEach day", () => {
5
- expect((0, get_each_1.getEach)(new Date("2021-05-05"), new Date("2021-05-07"), "day")).toStrictEqual([
6
- new Date("2021-05-05"),
7
- new Date("2021-05-06"),
8
- new Date("2021-05-07"),
5
+ expect((0, get_each_1.getEach)(new Date("2021-05-05T00:00:00+02:00"), new Date("2021-05-07T00:00:00+02:00"), "day")).toStrictEqual([
6
+ new Date("2021-05-05T00:00:00+02:00"),
7
+ new Date("2021-05-06T00:00:00+02:00"),
8
+ new Date("2021-05-07T00:00:00+02:00"),
9
9
  ]);
10
10
  });
11
11
  test("getEach month", () => {
12
12
  expect((0, get_each_1.getEach)(new Date("2021-05-05"), new Date("2021-08-07"), "month")).toStrictEqual([
13
- new Date("2021-05-01"),
14
- new Date("2021-06-01"),
15
- new Date("2021-07-01"),
16
- new Date("2021-08-01"),
13
+ new Date("2021-05-01T00:00:00+02:00"),
14
+ new Date("2021-06-01T00:00:00+02:00"),
15
+ new Date("2021-07-01T00:00:00+02:00"),
16
+ new Date("2021-08-01T00:00:00+02:00"),
17
17
  ]);
18
18
  });
19
19
  test("getEach year", () => {
20
20
  expect((0, get_each_1.getEach)(new Date("2015-05-05"), new Date("2020-05-07"), "year")).toStrictEqual([
21
- new Date("2015-01-01"),
22
- new Date("2016-01-01"),
23
- new Date("2017-01-01"),
24
- new Date("2018-01-01"),
25
- new Date("2019-01-01"),
26
- new Date("2020-01-01"),
21
+ new Date("2015-01-01T00:00:00+01:00"),
22
+ new Date("2016-01-01T00:00:00+01:00"),
23
+ new Date("2017-01-01T00:00:00+01:00"),
24
+ new Date("2018-01-01T00:00:00+01:00"),
25
+ new Date("2019-01-01T00:00:00+01:00"),
26
+ new Date("2020-01-01T00:00:00+01:00"),
27
27
  ]);
28
28
  });
29
29
  test("getEach invalid input", () => {
30
- expect(() => (0, get_each_1.getEach)(new Date("2015-05-05"), new Date("2014-05-07"), "day")).toThrow();
30
+ expect(() => (0, get_each_1.getEach)(new Date("2015-05-05"), new Date("2014-05-07T00:00:00+02:00"), "day")).toThrow();
31
31
  });
@@ -4,7 +4,7 @@ const get_initial_months_1 = require("./get-initial-months");
4
4
  test("getInitialMonths", () => {
5
5
  expect((0, get_initial_months_1.getInitialMonths)(1, new Date("2021-09-15"))).toStrictEqual([
6
6
  {
7
- date: new Date("2021-09-01"),
7
+ date: new Date("2021-09-01T00:00:00+02:00"),
8
8
  month: 8,
9
9
  year: 2021,
10
10
  },
@@ -13,12 +13,12 @@ test("getInitialMonths", () => {
13
13
  test("getInitialMonths 2 months", () => {
14
14
  expect((0, get_initial_months_1.getInitialMonths)(2, new Date("2021-09-15"))).toStrictEqual([
15
15
  {
16
- date: new Date("2021-09-01"),
16
+ date: new Date("2021-09-01T00:00:00+02:00"),
17
17
  month: 8,
18
18
  year: 2021,
19
19
  },
20
20
  {
21
- date: new Date("2021-10-01"),
21
+ date: new Date("2021-10-01T00:00:00+02:00"),
22
22
  month: 9,
23
23
  year: 2021,
24
24
  },
@@ -29,7 +29,7 @@ test("getInitialMonths without date", () => {
29
29
  jest.setSystemTime(new Date("2021-09-15"));
30
30
  expect((0, get_initial_months_1.getInitialMonths)(1, null)).toStrictEqual([
31
31
  {
32
- date: new Date("2021-09-01"),
32
+ date: new Date("2021-09-01T00:00:00+02:00"),
33
33
  month: 8,
34
34
  year: 2021,
35
35
  },
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMonths = getMonths;
4
+ const create_date_string_1 = require("./create-date-string");
4
5
  const dayjs_en_1 = require("./dayjs-en");
5
6
  const get_each_1 = require("./get-each");
6
7
  function getMonths({ year, monthLabelFormat = (date) => (0, dayjs_en_1.dayjsEn)(date).format("MMMM"), }) {
7
- const date = new Date(year, 0);
8
+ const date = new Date((0, create_date_string_1.createDateString)(year, 0));
8
9
  const yearStart = (0, dayjs_en_1.dayjsEn)(date).startOf("year").toDate();
9
10
  const yearEnd = (0, dayjs_en_1.dayjsEn)(date).endOf("year").toDate();
10
11
  return (0, get_each_1.getEach)(yearStart, yearEnd, "month").map((d) => ({
@@ -1,39 +1,36 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const dayjs_1 = __importDefault(require("dayjs"));
3
+ const dayjs_en_1 = require("./dayjs-en");
7
4
  const get_months_1 = require("./get-months");
8
5
  test("getMonths", () => {
9
6
  expect((0, get_months_1.getMonths)({ year: 2021 })).toStrictEqual([
10
- { monthLabel: "January", date: new Date("2021-01-01") },
11
- { monthLabel: "February", date: new Date("2021-02-01") },
12
- { monthLabel: "March", date: new Date("2021-03-01") },
13
- { monthLabel: "April", date: new Date("2021-04-01") },
14
- { monthLabel: "May", date: new Date("2021-05-01") },
15
- { monthLabel: "June", date: new Date("2021-06-01") },
16
- { monthLabel: "July", date: new Date("2021-07-01") },
17
- { monthLabel: "August", date: new Date("2021-08-01") },
18
- { monthLabel: "September", date: new Date("2021-09-01") },
19
- { monthLabel: "October", date: new Date("2021-10-01") },
20
- { monthLabel: "November", date: new Date("2021-11-01") },
21
- { monthLabel: "December", date: new Date("2021-12-01") },
7
+ { monthLabel: "January", date: new Date("2021-01-01T00:00:00+01:00") },
8
+ { monthLabel: "February", date: new Date("2021-02-01T00:00:00+01:00") },
9
+ { monthLabel: "March", date: new Date("2021-03-01T00:00:00+01:00") },
10
+ { monthLabel: "April", date: new Date("2021-04-01T00:00:00+02:00") },
11
+ { monthLabel: "May", date: new Date("2021-05-01T00:00:00+02:00") },
12
+ { monthLabel: "June", date: new Date("2021-06-01T00:00:00+02:00") },
13
+ { monthLabel: "July", date: new Date("2021-07-01T00:00:00+02:00") },
14
+ { monthLabel: "August", date: new Date("2021-08-01T00:00:00+02:00") },
15
+ { monthLabel: "September", date: new Date("2021-09-01T00:00:00+02:00") },
16
+ { monthLabel: "October", date: new Date("2021-10-01T00:00:00+02:00") },
17
+ { monthLabel: "November", date: new Date("2021-11-01T00:00:00+01:00") },
18
+ { monthLabel: "December", date: new Date("2021-12-01T00:00:00+01:00") },
22
19
  ]);
23
20
  });
24
21
  test("getMonths with custom format", () => {
25
- expect((0, get_months_1.getMonths)({ year: 2021, monthLabelFormat: (date) => (0, dayjs_1.default)(date).format("MM") })).toStrictEqual([
26
- { monthLabel: "01", date: new Date("2021-01-01") },
27
- { monthLabel: "02", date: new Date("2021-02-01") },
28
- { monthLabel: "03", date: new Date("2021-03-01") },
29
- { monthLabel: "04", date: new Date("2021-04-01") },
30
- { monthLabel: "05", date: new Date("2021-05-01") },
31
- { monthLabel: "06", date: new Date("2021-06-01") },
32
- { monthLabel: "07", date: new Date("2021-07-01") },
33
- { monthLabel: "08", date: new Date("2021-08-01") },
34
- { monthLabel: "09", date: new Date("2021-09-01") },
35
- { monthLabel: "10", date: new Date("2021-10-01") },
36
- { monthLabel: "11", date: new Date("2021-11-01") },
37
- { monthLabel: "12", date: new Date("2021-12-01") },
22
+ expect((0, get_months_1.getMonths)({ year: 2021, monthLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("MM") })).toStrictEqual([
23
+ { monthLabel: "01", date: new Date("2021-01-01T00:00:00+01:00") },
24
+ { monthLabel: "02", date: new Date("2021-02-01T00:00:00+01:00") },
25
+ { monthLabel: "03", date: new Date("2021-03-01T00:00:00+01:00") },
26
+ { monthLabel: "04", date: new Date("2021-04-01T00:00:00+02:00") },
27
+ { monthLabel: "05", date: new Date("2021-05-01T00:00:00+02:00") },
28
+ { monthLabel: "06", date: new Date("2021-06-01T00:00:00+02:00") },
29
+ { monthLabel: "07", date: new Date("2021-07-01T00:00:00+02:00") },
30
+ { monthLabel: "08", date: new Date("2021-08-01T00:00:00+02:00") },
31
+ { monthLabel: "09", date: new Date("2021-09-01T00:00:00+02:00") },
32
+ { monthLabel: "10", date: new Date("2021-10-01T00:00:00+02:00") },
33
+ { monthLabel: "11", date: new Date("2021-11-01T00:00:00+01:00") },
34
+ { monthLabel: "12", date: new Date("2021-12-01T00:00:00+01:00") },
38
35
  ]);
39
36
  });
@@ -14,11 +14,12 @@ function getNextActiveMonth(activeMonth, numberOfMonths, counter, step) {
14
14
  let prevMonthDate = activeMonth[prevMonth].date;
15
15
  return Array.from(Array(numberOfMonths).keys()).reduce((m) => {
16
16
  if (m.length === 0) {
17
- prevMonthDate = (0, dayjs_en_1.dayjsEn)(prevMonthDate).add(counter, "month").toDate();
17
+ prevMonthDate = (0, dayjs_en_1.dayjsEn)(prevMonthDate).add(counter, "month").startOf("month").toDate();
18
18
  }
19
19
  else {
20
20
  prevMonthDate = (0, dayjs_en_1.dayjsEn)(prevMonthDate)
21
21
  .add(counter >= 0 ? 1 : -1, "month")
22
+ .startOf("month")
22
23
  .toDate();
23
24
  }
24
25
  return counter > 0
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const get_next_active_month_1 = require("./get-next-active-month");
4
4
  test("getNextActiveMonth", () => {
5
5
  expect((0, get_next_active_month_1.getNextActiveMonth)([{ year: 2021, month: 0, date: new Date("2021-01-01") }], 1, 1)).toStrictEqual([
6
- { year: 2021, month: 1, date: new Date("2021-02-01") },
6
+ { year: 2021, month: 1, date: new Date("2021-02-01T00:00:00+01:00") },
7
+ ]);
8
+ expect((0, get_next_active_month_1.getNextActiveMonth)([{ year: 2021, month: 9, date: new Date("2021-10-01") }], 1, 1)).toStrictEqual([
9
+ { year: 2021, month: 10, date: new Date("2021-11-01T00:00:00+01:00") },
7
10
  ]);
8
11
  });
9
12
  test("getNextActiveMonth with 2 months", () => {
@@ -11,8 +14,8 @@ test("getNextActiveMonth with 2 months", () => {
11
14
  { year: 2021, month: 0, date: new Date("2021-01-01") },
12
15
  { year: 2021, month: 1, date: new Date("2021-02-01") },
13
16
  ], 2, 1)).toStrictEqual([
14
- { year: 2021, month: 2, date: new Date("2021-03-01") },
15
- { year: 2021, month: 3, date: new Date("2021-04-01") },
17
+ { year: 2021, month: 2, date: new Date("2021-03-01T00:00:00+01:00") },
18
+ { year: 2021, month: 3, date: new Date("2021-04-01T00:00:00+02:00") },
16
19
  ]);
17
20
  });
18
21
  test("getNextActiveMonth with 2 months and step", () => {
@@ -20,8 +23,8 @@ test("getNextActiveMonth with 2 months and step", () => {
20
23
  { year: 2021, month: 0, date: new Date("2021-01-01") },
21
24
  { year: 2021, month: 1, date: new Date("2021-02-01") },
22
25
  ], 2, 1, 1)).toStrictEqual([
23
- { year: 2021, month: 1, date: new Date("2021-02-01") },
24
- { year: 2021, month: 2, date: new Date("2021-03-01") },
26
+ { year: 2021, month: 1, date: new Date("2021-02-01T00:00:00+01:00") },
27
+ { year: 2021, month: 2, date: new Date("2021-03-01T00:00:00+01:00") },
25
28
  ]);
26
29
  });
27
30
  test("getNextActiveMonth with 2 months and counter 0", () => {
@@ -29,8 +32,8 @@ test("getNextActiveMonth with 2 months and counter 0", () => {
29
32
  { year: 2021, month: 0, date: new Date("2021-01-01") },
30
33
  { year: 2021, month: 1, date: new Date("2021-02-01") },
31
34
  ], 2, 0)).toStrictEqual([
32
- { year: 2021, month: 1, date: new Date("2021-02-01") },
33
- { year: 2021, month: 0, date: new Date("2021-01-01") },
35
+ { year: 2021, month: 1, date: new Date("2021-02-01T00:00:00+01:00") },
36
+ { year: 2021, month: 0, date: new Date("2021-01-01T00:00:00+01:00") },
34
37
  ]);
35
38
  });
36
39
  test("getNextActiveMonth with 2 months and step and counter 0", () => {
@@ -38,8 +41,8 @@ test("getNextActiveMonth with 2 months and step and counter 0", () => {
38
41
  { year: 2021, month: 0, date: new Date("2021-01-01") },
39
42
  { year: 2021, month: 1, date: new Date("2021-02-01") },
40
43
  ], 2, 0, 1)).toStrictEqual([
41
- { year: 2021, month: 2, date: new Date("2021-03-01") },
42
- { year: 2021, month: 1, date: new Date("2021-02-01") },
44
+ { year: 2021, month: 2, date: new Date("2021-03-01T00:00:00+01:00") },
45
+ { year: 2021, month: 1, date: new Date("2021-02-01T00:00:00+01:00") },
43
46
  ]);
44
47
  });
45
48
  test("getNextActiveMonth with 2 months and negative counter", () => {
@@ -47,8 +50,8 @@ test("getNextActiveMonth with 2 months and negative counter", () => {
47
50
  { year: 2021, month: 0, date: new Date("2021-01-01") },
48
51
  { year: 2021, month: 1, date: new Date("2021-02-01") },
49
52
  ], 2, -1)).toStrictEqual([
50
- { year: 2020, month: 10, date: new Date("2020-11-01") },
51
- { year: 2020, month: 11, date: new Date("2020-12-01") },
53
+ { year: 2020, month: 10, date: new Date("2020-11-01T00:00:00+01:00") },
54
+ { year: 2020, month: 11, date: new Date("2020-12-01T00:00:00+01:00") },
52
55
  ]);
53
56
  });
54
57
  test("getNextActiveMonth with 2 months and step and negative counter", () => {
@@ -56,7 +59,7 @@ test("getNextActiveMonth with 2 months and step and negative counter", () => {
56
59
  { year: 2021, month: 0, date: new Date("2021-01-01") },
57
60
  { year: 2021, month: 1, date: new Date("2021-02-01") },
58
61
  ], 2, -1, 1)).toStrictEqual([
59
- { year: 2020, month: 11, date: new Date("2020-12-01") },
60
- { year: 2021, month: 0, date: new Date("2021-01-01") },
62
+ { year: 2020, month: 11, date: new Date("2020-12-01T00:00:00+01:00") },
63
+ { year: 2021, month: 0, date: new Date("2021-01-01T00:00:00+01:00") },
61
64
  ]);
62
65
  });