@uxf/datepicker 11.93.3 → 11.94.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/datepicker",
3
- "version": "11.93.3",
3
+ "version": "11.94.0",
4
4
  "description": "A set of React hooks to create an awesome datepicker.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1 +1 @@
1
- export declare function getEach(start: Date, end: Date, type: "day" | "month" | "year", arr?: Date[]): Date[];
1
+ export declare function getEach(start: Date, end: Date, type: "day" | "month" | "year"): Date[];
package/utils/get-each.js CHANGED
@@ -1,14 +1,101 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEach = getEach;
4
- const dayjs_en_1 = require("./dayjs-en");
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, type)) {
4
+ const DEFAULT_TIMEZONE = "Europe/Prague";
5
+ const DAY_IN_MS = 24 * 60 * 60 * 1000;
6
+ const partsFormatter = new Intl.DateTimeFormat("en-GB", {
7
+ timeZone: DEFAULT_TIMEZONE,
8
+ year: "numeric",
9
+ month: "numeric",
10
+ day: "numeric",
11
+ hour: "numeric",
12
+ hour12: false,
13
+ });
14
+ const hourFormatter = new Intl.DateTimeFormat("en-GB", {
15
+ timeZone: DEFAULT_TIMEZONE,
16
+ hour: "numeric",
17
+ hour12: false,
18
+ });
19
+ function getHour(date) {
20
+ return parseInt(hourFormatter.format(date), 10) % 24;
21
+ }
22
+ function getDateParts(date) {
23
+ const parts = partsFormatter.formatToParts(date);
24
+ let year = 0;
25
+ let month = 0;
26
+ let day = 0;
27
+ let hour = 0;
28
+ for (let i = 0; i < parts.length; i++) {
29
+ const part = parts[i];
30
+ if (part.type === "year") {
31
+ year = parseInt(part.value, 10);
32
+ }
33
+ else if (part.type === "month") {
34
+ month = parseInt(part.value, 10);
35
+ }
36
+ else if (part.type === "day") {
37
+ day = parseInt(part.value, 10);
38
+ }
39
+ else if (part.type === "hour") {
40
+ hour = parseInt(part.value, 10);
41
+ }
42
+ }
43
+ return { year, month, day, hour: hour % 24 };
44
+ }
45
+ /**
46
+ * Creates a date in the default timezone (Prague)
47
+ */
48
+ function createDate(year, month, day) {
49
+ const date = new Date(Date.UTC(year, month - 1, day));
50
+ const hour = getHour(date);
51
+ if (hour !== 0) {
52
+ // Adjust UTC midnight to Prague midnight
53
+ // Prague is UTC+1 or UTC+2, so hour will be 1 or 2 (or 23/24 if something shifted)
54
+ const diff = hour > 12 ? hour - 24 : hour;
55
+ date.setUTCHours(date.getUTCHours() - diff);
56
+ }
57
+ return date;
58
+ }
59
+ function startOf(date, type) {
60
+ const p = getDateParts(date);
61
+ if (type === "year") {
62
+ return createDate(p.year, 1, 1);
63
+ }
64
+ if (type === "month") {
65
+ return createDate(p.year, p.month, 1);
66
+ }
67
+ return createDate(p.year, p.month, p.day);
68
+ }
69
+ function getEach(start, end, type) {
70
+ const startOfStart = startOf(start, type);
71
+ const startOfEnd = startOf(end, type);
72
+ if (startOfStart.getTime() > startOfEnd.getTime()) {
7
73
  throw new Error("start must precede end");
8
74
  }
9
- const next = (0, dayjs_en_1.dayjsEn)(start).add(1, type).startOf(type).toDate();
10
- if ((0, dayjs_en_1.dayjsEn)(next).isAfter(end, type)) {
11
- return arr;
75
+ const results = [];
76
+ let current = startOfStart;
77
+ while (current.getTime() <= startOfEnd.getTime()) {
78
+ results.push(new Date(current.getTime()));
79
+ if (type === "day") {
80
+ // Optimized day increment: add 24 hours and correct for DST if needed
81
+ const next = new Date(current.getTime() + DAY_IN_MS);
82
+ const hour = getHour(next);
83
+ if (hour !== 0) {
84
+ const diff = hour > 12 ? hour - 24 : hour;
85
+ next.setUTCHours(next.getUTCHours() - diff);
86
+ }
87
+ current = next;
88
+ }
89
+ else {
90
+ const p = getDateParts(current);
91
+ if (type === "year") {
92
+ current = createDate(p.year + 1, 1, 1);
93
+ }
94
+ else {
95
+ // month
96
+ current = createDate(p.year, p.month + 1, 1);
97
+ }
98
+ }
12
99
  }
13
- return getEach(next, end, type, arr.concat(next));
100
+ return results;
14
101
  }