@mrck-labs/vanaheim-shared 0.1.1 → 0.2.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.
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Date Utilities
3
+ *
4
+ * Pure functions for date manipulation and formatting.
5
+ * Works in both Node.js and browser/React Native environments.
6
+ *
7
+ * @example
8
+ * import { getTodayString, addDays, formatRelativeTime } from '@mrck-labs/vanaheim-shared/date'
9
+ *
10
+ * const today = getTodayString() // "2024-12-16"
11
+ * const nextWeek = addDays(today, 7) // "2024-12-23"
12
+ */
13
+ /**
14
+ * Normalize a date to midnight (00:00:00.000)
15
+ */
16
+ declare function normalizeToMidnight(date: Date): Date;
17
+ /**
18
+ * Get today's date normalized to midnight
19
+ */
20
+ declare function getTodayMidnight(): Date;
21
+ /**
22
+ * Format a Date object to YYYY-MM-DD string
23
+ * @example formatDateString(new Date()) => "2024-12-16"
24
+ */
25
+ declare function formatDateString(date: Date): string;
26
+ /**
27
+ * Get today's local date string (YYYY-MM-DD)
28
+ */
29
+ declare function getTodayString(): string;
30
+ /**
31
+ * Parse a YYYY-MM-DD string to a local Date object
32
+ * Avoids timezone issues by appending T00:00:00
33
+ */
34
+ declare function parseLocalDate(dateStr: string): Date;
35
+ /**
36
+ * Check if a date string is today
37
+ */
38
+ declare function isToday(dateStr: string | null): boolean;
39
+ /**
40
+ * Check if a date string is in the past (before today)
41
+ */
42
+ declare function isOverdue(dateStr: string | null): boolean;
43
+ /**
44
+ * Check if a date is due within a threshold of days
45
+ * @param dateStr - Date in YYYY-MM-DD format
46
+ * @param daysThreshold - Number of days to check (default: 7)
47
+ */
48
+ declare function isDueSoon(dateStr: string | null, daysThreshold?: number): boolean;
49
+ /**
50
+ * Add days to a date string
51
+ * @param dateStr - Date in YYYY-MM-DD format
52
+ * @param days - Number of days to add (can be negative)
53
+ * @returns New date string in YYYY-MM-DD format
54
+ */
55
+ declare function addDays(dateStr: string, days: number): string;
56
+ /**
57
+ * Subtract days from a date string
58
+ */
59
+ declare function subtractDays(dateStr: string, days: number): string;
60
+ /**
61
+ * Get yesterday's date string (YYYY-MM-DD)
62
+ */
63
+ declare function getYesterdayString(): string;
64
+ /**
65
+ * Get tomorrow's date string (YYYY-MM-DD)
66
+ */
67
+ declare function getTomorrowString(): string;
68
+ /**
69
+ * Get start of day as ISO string
70
+ * @param dateStr - Date in YYYY-MM-DD format
71
+ * @returns ISO string like "2024-12-15T00:00:00.000Z"
72
+ */
73
+ declare function getStartOfDayISO(dateStr: string): string;
74
+ /**
75
+ * Get end of day as ISO string
76
+ * @param dateStr - Date in YYYY-MM-DD format
77
+ * @returns ISO string like "2024-12-15T23:59:59.999Z"
78
+ */
79
+ declare function getEndOfDayISO(dateStr: string): string;
80
+ /**
81
+ * Get the start of the week (Monday) for a given date
82
+ */
83
+ declare function getWeekStart(date: Date): Date;
84
+ /**
85
+ * Get the end of the week (Sunday) for a given week start
86
+ */
87
+ declare function getWeekEnd(weekStart: Date): Date;
88
+ /**
89
+ * Get the start of the previous week
90
+ */
91
+ declare function getPreviousWeek(weekStart: Date): Date;
92
+ /**
93
+ * Get the start of the next week
94
+ */
95
+ declare function getNextWeek(weekStart: Date): Date;
96
+ /**
97
+ * Get start of week (Monday) as date string
98
+ */
99
+ declare function getWeekStartString(baseDate?: Date): string;
100
+ /**
101
+ * Get end of week (Sunday) as date string
102
+ */
103
+ declare function getWeekEndString(baseDate?: Date): string;
104
+ /**
105
+ * Format a week range for display
106
+ * @example "Dec 2 - 8, 2024" or "Nov 25 - Dec 1, 2024"
107
+ */
108
+ declare function formatWeekRange(weekStart: Date): string;
109
+ /**
110
+ * Format a date string for display with full weekday
111
+ * @example "Monday, December 15, 2024"
112
+ */
113
+ declare function formatFullDate(dateStr: string): string;
114
+ /**
115
+ * Format date for display in long form
116
+ * @example "Monday, 9 December"
117
+ */
118
+ declare function formatDateLong(dateStr: string): string;
119
+ /**
120
+ * Format month and year
121
+ * @example "December 2024"
122
+ */
123
+ declare function formatMonthYear(date: Date): string;
124
+ /**
125
+ * Format a date/time to HH:MM format
126
+ */
127
+ declare function formatTimeHHMM(date: Date | string): string;
128
+ /**
129
+ * Format a date/time to HH:MM:SS format
130
+ */
131
+ declare function formatTimeWithSeconds(date: Date | string): string;
132
+ /**
133
+ * Format a date string for display as a header
134
+ * Returns "Overdue", "Today", "Tomorrow", or formatted date
135
+ */
136
+ declare function formatDateHeader(dateStr: string): string;
137
+ /**
138
+ * Format a due date for display in task items (simple string version)
139
+ * Returns "Overdue", "Today", "Tomorrow", or formatted date
140
+ *
141
+ * Note: For version that returns { text, isOverdue }, use formatDueDate from utils/formatters
142
+ */
143
+ declare function formatDueDateString(dateStr: string | null): string;
144
+ /**
145
+ * Format a date/time as relative time string (extended version)
146
+ * Accepts both Date objects and ISO strings
147
+ * @example "Just now", "5m ago", "2h ago", "3d ago"
148
+ *
149
+ * Note: For simple string input, you can also use formatRelativeTime from utils/formatters
150
+ */
151
+ declare function formatRelativeTimeExtended(dateStr: string | Date): string;
152
+ /**
153
+ * Format a due date relative to today with contextual prefix
154
+ * @example "Due today", "Due tomorrow", "Due in 3 days", "2 days overdue"
155
+ */
156
+ declare function formatRelativeDueDate(dateStr: string, options?: {
157
+ duePrefix?: string;
158
+ overduePrefix?: string;
159
+ }): string;
160
+ /**
161
+ * Format a pay/income date relative to today
162
+ * @example "Today", "Tomorrow", "In 3 days", "2 days ago"
163
+ */
164
+ declare function formatRelativePayDate(dateStr: string): string;
165
+ type DateFormat = 'short' | 'medium' | 'long' | 'weekday';
166
+ type TimeFormat = 'short' | 'withSeconds';
167
+ /**
168
+ * Format a date with various preset formats
169
+ */
170
+ declare function formatDateLocalized(date: Date | string, format?: DateFormat): string;
171
+ /**
172
+ * Format a time with various preset formats
173
+ */
174
+ declare function formatTimeLocalized(date: Date | string, format?: TimeFormat): string;
175
+
176
+ export { type DateFormat, type TimeFormat, addDays, formatDateHeader, formatDateLocalized, formatDateLong, formatDateString, formatDueDateString, formatFullDate, formatMonthYear, formatRelativeDueDate, formatRelativePayDate, formatRelativeTimeExtended, formatTimeHHMM, formatTimeLocalized, formatTimeWithSeconds, formatWeekRange, getEndOfDayISO, getNextWeek, getPreviousWeek, getStartOfDayISO, getTodayMidnight, getTodayString, getTomorrowString, getWeekEnd, getWeekEndString, getWeekStart, getWeekStartString, getYesterdayString, isDueSoon, isOverdue, isToday, normalizeToMidnight, parseLocalDate, subtractDays };
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Date Utilities
3
+ *
4
+ * Pure functions for date manipulation and formatting.
5
+ * Works in both Node.js and browser/React Native environments.
6
+ *
7
+ * @example
8
+ * import { getTodayString, addDays, formatRelativeTime } from '@mrck-labs/vanaheim-shared/date'
9
+ *
10
+ * const today = getTodayString() // "2024-12-16"
11
+ * const nextWeek = addDays(today, 7) // "2024-12-23"
12
+ */
13
+ /**
14
+ * Normalize a date to midnight (00:00:00.000)
15
+ */
16
+ declare function normalizeToMidnight(date: Date): Date;
17
+ /**
18
+ * Get today's date normalized to midnight
19
+ */
20
+ declare function getTodayMidnight(): Date;
21
+ /**
22
+ * Format a Date object to YYYY-MM-DD string
23
+ * @example formatDateString(new Date()) => "2024-12-16"
24
+ */
25
+ declare function formatDateString(date: Date): string;
26
+ /**
27
+ * Get today's local date string (YYYY-MM-DD)
28
+ */
29
+ declare function getTodayString(): string;
30
+ /**
31
+ * Parse a YYYY-MM-DD string to a local Date object
32
+ * Avoids timezone issues by appending T00:00:00
33
+ */
34
+ declare function parseLocalDate(dateStr: string): Date;
35
+ /**
36
+ * Check if a date string is today
37
+ */
38
+ declare function isToday(dateStr: string | null): boolean;
39
+ /**
40
+ * Check if a date string is in the past (before today)
41
+ */
42
+ declare function isOverdue(dateStr: string | null): boolean;
43
+ /**
44
+ * Check if a date is due within a threshold of days
45
+ * @param dateStr - Date in YYYY-MM-DD format
46
+ * @param daysThreshold - Number of days to check (default: 7)
47
+ */
48
+ declare function isDueSoon(dateStr: string | null, daysThreshold?: number): boolean;
49
+ /**
50
+ * Add days to a date string
51
+ * @param dateStr - Date in YYYY-MM-DD format
52
+ * @param days - Number of days to add (can be negative)
53
+ * @returns New date string in YYYY-MM-DD format
54
+ */
55
+ declare function addDays(dateStr: string, days: number): string;
56
+ /**
57
+ * Subtract days from a date string
58
+ */
59
+ declare function subtractDays(dateStr: string, days: number): string;
60
+ /**
61
+ * Get yesterday's date string (YYYY-MM-DD)
62
+ */
63
+ declare function getYesterdayString(): string;
64
+ /**
65
+ * Get tomorrow's date string (YYYY-MM-DD)
66
+ */
67
+ declare function getTomorrowString(): string;
68
+ /**
69
+ * Get start of day as ISO string
70
+ * @param dateStr - Date in YYYY-MM-DD format
71
+ * @returns ISO string like "2024-12-15T00:00:00.000Z"
72
+ */
73
+ declare function getStartOfDayISO(dateStr: string): string;
74
+ /**
75
+ * Get end of day as ISO string
76
+ * @param dateStr - Date in YYYY-MM-DD format
77
+ * @returns ISO string like "2024-12-15T23:59:59.999Z"
78
+ */
79
+ declare function getEndOfDayISO(dateStr: string): string;
80
+ /**
81
+ * Get the start of the week (Monday) for a given date
82
+ */
83
+ declare function getWeekStart(date: Date): Date;
84
+ /**
85
+ * Get the end of the week (Sunday) for a given week start
86
+ */
87
+ declare function getWeekEnd(weekStart: Date): Date;
88
+ /**
89
+ * Get the start of the previous week
90
+ */
91
+ declare function getPreviousWeek(weekStart: Date): Date;
92
+ /**
93
+ * Get the start of the next week
94
+ */
95
+ declare function getNextWeek(weekStart: Date): Date;
96
+ /**
97
+ * Get start of week (Monday) as date string
98
+ */
99
+ declare function getWeekStartString(baseDate?: Date): string;
100
+ /**
101
+ * Get end of week (Sunday) as date string
102
+ */
103
+ declare function getWeekEndString(baseDate?: Date): string;
104
+ /**
105
+ * Format a week range for display
106
+ * @example "Dec 2 - 8, 2024" or "Nov 25 - Dec 1, 2024"
107
+ */
108
+ declare function formatWeekRange(weekStart: Date): string;
109
+ /**
110
+ * Format a date string for display with full weekday
111
+ * @example "Monday, December 15, 2024"
112
+ */
113
+ declare function formatFullDate(dateStr: string): string;
114
+ /**
115
+ * Format date for display in long form
116
+ * @example "Monday, 9 December"
117
+ */
118
+ declare function formatDateLong(dateStr: string): string;
119
+ /**
120
+ * Format month and year
121
+ * @example "December 2024"
122
+ */
123
+ declare function formatMonthYear(date: Date): string;
124
+ /**
125
+ * Format a date/time to HH:MM format
126
+ */
127
+ declare function formatTimeHHMM(date: Date | string): string;
128
+ /**
129
+ * Format a date/time to HH:MM:SS format
130
+ */
131
+ declare function formatTimeWithSeconds(date: Date | string): string;
132
+ /**
133
+ * Format a date string for display as a header
134
+ * Returns "Overdue", "Today", "Tomorrow", or formatted date
135
+ */
136
+ declare function formatDateHeader(dateStr: string): string;
137
+ /**
138
+ * Format a due date for display in task items (simple string version)
139
+ * Returns "Overdue", "Today", "Tomorrow", or formatted date
140
+ *
141
+ * Note: For version that returns { text, isOverdue }, use formatDueDate from utils/formatters
142
+ */
143
+ declare function formatDueDateString(dateStr: string | null): string;
144
+ /**
145
+ * Format a date/time as relative time string (extended version)
146
+ * Accepts both Date objects and ISO strings
147
+ * @example "Just now", "5m ago", "2h ago", "3d ago"
148
+ *
149
+ * Note: For simple string input, you can also use formatRelativeTime from utils/formatters
150
+ */
151
+ declare function formatRelativeTimeExtended(dateStr: string | Date): string;
152
+ /**
153
+ * Format a due date relative to today with contextual prefix
154
+ * @example "Due today", "Due tomorrow", "Due in 3 days", "2 days overdue"
155
+ */
156
+ declare function formatRelativeDueDate(dateStr: string, options?: {
157
+ duePrefix?: string;
158
+ overduePrefix?: string;
159
+ }): string;
160
+ /**
161
+ * Format a pay/income date relative to today
162
+ * @example "Today", "Tomorrow", "In 3 days", "2 days ago"
163
+ */
164
+ declare function formatRelativePayDate(dateStr: string): string;
165
+ type DateFormat = 'short' | 'medium' | 'long' | 'weekday';
166
+ type TimeFormat = 'short' | 'withSeconds';
167
+ /**
168
+ * Format a date with various preset formats
169
+ */
170
+ declare function formatDateLocalized(date: Date | string, format?: DateFormat): string;
171
+ /**
172
+ * Format a time with various preset formats
173
+ */
174
+ declare function formatTimeLocalized(date: Date | string, format?: TimeFormat): string;
175
+
176
+ export { type DateFormat, type TimeFormat, addDays, formatDateHeader, formatDateLocalized, formatDateLong, formatDateString, formatDueDateString, formatFullDate, formatMonthYear, formatRelativeDueDate, formatRelativePayDate, formatRelativeTimeExtended, formatTimeHHMM, formatTimeLocalized, formatTimeWithSeconds, formatWeekRange, getEndOfDayISO, getNextWeek, getPreviousWeek, getStartOfDayISO, getTodayMidnight, getTodayString, getTomorrowString, getWeekEnd, getWeekEndString, getWeekStart, getWeekStartString, getYesterdayString, isDueSoon, isOverdue, isToday, normalizeToMidnight, parseLocalDate, subtractDays };
@@ -0,0 +1,347 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/date/index.ts
21
+ var date_exports = {};
22
+ __export(date_exports, {
23
+ addDays: () => addDays,
24
+ formatDateHeader: () => formatDateHeader,
25
+ formatDateLocalized: () => formatDateLocalized,
26
+ formatDateLong: () => formatDateLong,
27
+ formatDateString: () => formatDateString,
28
+ formatDueDateString: () => formatDueDateString,
29
+ formatFullDate: () => formatFullDate,
30
+ formatMonthYear: () => formatMonthYear,
31
+ formatRelativeDueDate: () => formatRelativeDueDate,
32
+ formatRelativePayDate: () => formatRelativePayDate,
33
+ formatRelativeTimeExtended: () => formatRelativeTimeExtended,
34
+ formatTimeHHMM: () => formatTimeHHMM,
35
+ formatTimeLocalized: () => formatTimeLocalized,
36
+ formatTimeWithSeconds: () => formatTimeWithSeconds,
37
+ formatWeekRange: () => formatWeekRange,
38
+ getEndOfDayISO: () => getEndOfDayISO,
39
+ getNextWeek: () => getNextWeek,
40
+ getPreviousWeek: () => getPreviousWeek,
41
+ getStartOfDayISO: () => getStartOfDayISO,
42
+ getTodayMidnight: () => getTodayMidnight,
43
+ getTodayString: () => getTodayString,
44
+ getTomorrowString: () => getTomorrowString,
45
+ getWeekEnd: () => getWeekEnd,
46
+ getWeekEndString: () => getWeekEndString,
47
+ getWeekStart: () => getWeekStart,
48
+ getWeekStartString: () => getWeekStartString,
49
+ getYesterdayString: () => getYesterdayString,
50
+ isDueSoon: () => isDueSoon,
51
+ isOverdue: () => isOverdue,
52
+ isToday: () => isToday,
53
+ normalizeToMidnight: () => normalizeToMidnight,
54
+ parseLocalDate: () => parseLocalDate,
55
+ subtractDays: () => subtractDays
56
+ });
57
+ module.exports = __toCommonJS(date_exports);
58
+ function normalizeToMidnight(date) {
59
+ const d = new Date(date);
60
+ d.setHours(0, 0, 0, 0);
61
+ return d;
62
+ }
63
+ function getTodayMidnight() {
64
+ return normalizeToMidnight(/* @__PURE__ */ new Date());
65
+ }
66
+ function formatDateString(date) {
67
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
68
+ }
69
+ function getTodayString() {
70
+ return formatDateString(/* @__PURE__ */ new Date());
71
+ }
72
+ function parseLocalDate(dateStr) {
73
+ return /* @__PURE__ */ new Date(dateStr + "T00:00:00");
74
+ }
75
+ function isToday(dateStr) {
76
+ if (!dateStr) return false;
77
+ return dateStr === getTodayString();
78
+ }
79
+ function isOverdue(dateStr) {
80
+ if (!dateStr) return false;
81
+ return dateStr < getTodayString();
82
+ }
83
+ function isDueSoon(dateStr, daysThreshold = 7) {
84
+ if (!dateStr) return false;
85
+ if (isOverdue(dateStr)) return false;
86
+ const today = getTodayMidnight();
87
+ const targetDate = parseLocalDate(dateStr);
88
+ const diffMs = targetDate.getTime() - today.getTime();
89
+ const diffDays = Math.ceil(diffMs / (1e3 * 60 * 60 * 24));
90
+ return diffDays >= 0 && diffDays <= daysThreshold;
91
+ }
92
+ function addDays(dateStr, days) {
93
+ const date = parseLocalDate(dateStr);
94
+ date.setDate(date.getDate() + days);
95
+ return formatDateString(date);
96
+ }
97
+ function subtractDays(dateStr, days) {
98
+ return addDays(dateStr, -days);
99
+ }
100
+ function getYesterdayString() {
101
+ return subtractDays(getTodayString(), 1);
102
+ }
103
+ function getTomorrowString() {
104
+ return addDays(getTodayString(), 1);
105
+ }
106
+ function getStartOfDayISO(dateStr) {
107
+ const date = parseLocalDate(dateStr);
108
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate()).toISOString();
109
+ }
110
+ function getEndOfDayISO(dateStr) {
111
+ const date = parseLocalDate(dateStr);
112
+ return new Date(
113
+ date.getFullYear(),
114
+ date.getMonth(),
115
+ date.getDate(),
116
+ 23,
117
+ 59,
118
+ 59,
119
+ 999
120
+ ).toISOString();
121
+ }
122
+ function getWeekStart(date) {
123
+ const d = new Date(date);
124
+ const day = d.getDay();
125
+ const diff = d.getDate() - day + (day === 0 ? -6 : 1);
126
+ d.setDate(diff);
127
+ d.setHours(0, 0, 0, 0);
128
+ return d;
129
+ }
130
+ function getWeekEnd(weekStart) {
131
+ const d = new Date(weekStart);
132
+ d.setDate(d.getDate() + 6);
133
+ return d;
134
+ }
135
+ function getPreviousWeek(weekStart) {
136
+ const d = new Date(weekStart);
137
+ d.setDate(d.getDate() - 7);
138
+ return d;
139
+ }
140
+ function getNextWeek(weekStart) {
141
+ const d = new Date(weekStart);
142
+ d.setDate(d.getDate() + 7);
143
+ return d;
144
+ }
145
+ function getWeekStartString(baseDate = /* @__PURE__ */ new Date()) {
146
+ return formatDateString(getWeekStart(baseDate));
147
+ }
148
+ function getWeekEndString(baseDate = /* @__PURE__ */ new Date()) {
149
+ return formatDateString(getWeekEnd(getWeekStart(baseDate)));
150
+ }
151
+ function formatWeekRange(weekStart) {
152
+ const weekEnd = getWeekEnd(weekStart);
153
+ const startMonth = weekStart.toLocaleDateString("en-US", { month: "short" });
154
+ const endMonth = weekEnd.toLocaleDateString("en-US", { month: "short" });
155
+ if (startMonth === endMonth) {
156
+ return `${startMonth} ${weekStart.getDate()} - ${weekEnd.getDate()}, ${weekStart.getFullYear()}`;
157
+ }
158
+ return `${startMonth} ${weekStart.getDate()} - ${endMonth} ${weekEnd.getDate()}, ${weekStart.getFullYear()}`;
159
+ }
160
+ function formatFullDate(dateStr) {
161
+ const date = parseLocalDate(dateStr);
162
+ return date.toLocaleDateString("en-US", {
163
+ weekday: "long",
164
+ year: "numeric",
165
+ month: "long",
166
+ day: "numeric"
167
+ });
168
+ }
169
+ function formatDateLong(dateStr) {
170
+ const date = parseLocalDate(dateStr);
171
+ return date.toLocaleDateString("en-GB", {
172
+ weekday: "long",
173
+ day: "numeric",
174
+ month: "long"
175
+ });
176
+ }
177
+ function formatMonthYear(date) {
178
+ return date.toLocaleDateString("en-US", {
179
+ month: "long",
180
+ year: "numeric"
181
+ });
182
+ }
183
+ function formatTimeHHMM(date) {
184
+ const d = typeof date === "string" ? new Date(date) : date;
185
+ return d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
186
+ }
187
+ function formatTimeWithSeconds(date) {
188
+ const d = typeof date === "string" ? new Date(date) : date;
189
+ return d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" });
190
+ }
191
+ function formatDateHeader(dateStr) {
192
+ const today = getTodayString();
193
+ if (dateStr < today) {
194
+ return "Overdue";
195
+ }
196
+ if (dateStr === today) {
197
+ return "Today";
198
+ }
199
+ const tomorrowStr = getTomorrowString();
200
+ if (dateStr === tomorrowStr) {
201
+ return "Tomorrow";
202
+ }
203
+ const date = parseLocalDate(dateStr);
204
+ return date.toLocaleDateString("en-US", {
205
+ weekday: "long",
206
+ month: "short",
207
+ day: "numeric"
208
+ });
209
+ }
210
+ function formatDueDateString(dateStr) {
211
+ if (!dateStr) return "No due date";
212
+ const today = getTodayString();
213
+ const tomorrowStr = getTomorrowString();
214
+ if (dateStr < today) {
215
+ const date2 = parseLocalDate(dateStr);
216
+ return `Overdue \u2022 ${date2.toLocaleDateString("en-US", { month: "short", day: "numeric" })}`;
217
+ }
218
+ if (dateStr === today) {
219
+ return "Today";
220
+ }
221
+ if (dateStr === tomorrowStr) {
222
+ return "Tomorrow";
223
+ }
224
+ const date = parseLocalDate(dateStr);
225
+ const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
226
+ const dateYear = date.getFullYear();
227
+ return date.toLocaleDateString("en-US", {
228
+ month: "short",
229
+ day: "numeric",
230
+ year: dateYear !== currentYear ? "numeric" : void 0
231
+ });
232
+ }
233
+ function formatRelativeTimeExtended(dateStr) {
234
+ const date = typeof dateStr === "string" ? new Date(dateStr) : dateStr;
235
+ const now = /* @__PURE__ */ new Date();
236
+ const diffMs = now.getTime() - date.getTime();
237
+ const diffMins = Math.floor(diffMs / 6e4);
238
+ const diffHours = Math.floor(diffMins / 60);
239
+ const diffDays = Math.floor(diffHours / 24);
240
+ if (diffMins < 1) return "Just now";
241
+ if (diffMins < 60) return `${diffMins}m ago`;
242
+ if (diffHours < 24) return `${diffHours}h ago`;
243
+ if (diffDays < 7) return `${diffDays}d ago`;
244
+ return date.toLocaleDateString();
245
+ }
246
+ function formatRelativeDueDate(dateStr, options) {
247
+ const { duePrefix = "Due", overduePrefix = "" } = options || {};
248
+ const date = parseLocalDate(dateStr);
249
+ const now = normalizeToMidnight(/* @__PURE__ */ new Date());
250
+ const diffMs = date.getTime() - now.getTime();
251
+ const diffDays = Math.round(diffMs / (1e3 * 60 * 60 * 24));
252
+ if (diffDays < 0) {
253
+ const absDays = Math.abs(diffDays);
254
+ return overduePrefix ? `${overduePrefix} ${absDays} day${absDays !== 1 ? "s" : ""} overdue` : `${absDays} day${absDays !== 1 ? "s" : ""} overdue`;
255
+ }
256
+ if (diffDays === 0) return `${duePrefix} today`;
257
+ if (diffDays === 1) return `${duePrefix} tomorrow`;
258
+ if (diffDays <= 7) return `${duePrefix} in ${diffDays} days`;
259
+ return date.toLocaleDateString("en-GB", { day: "numeric", month: "short" });
260
+ }
261
+ function formatRelativePayDate(dateStr) {
262
+ const date = parseLocalDate(dateStr);
263
+ const now = normalizeToMidnight(/* @__PURE__ */ new Date());
264
+ const diffMs = date.getTime() - now.getTime();
265
+ const diffDays = Math.round(diffMs / (1e3 * 60 * 60 * 24));
266
+ if (diffDays < 0) {
267
+ const absDays = Math.abs(diffDays);
268
+ return `${absDays} day${absDays !== 1 ? "s" : ""} ago`;
269
+ }
270
+ if (diffDays === 0) return "Today";
271
+ if (diffDays === 1) return "Tomorrow";
272
+ if (diffDays <= 7) return `In ${diffDays} days`;
273
+ return date.toLocaleDateString("en-GB", { day: "numeric", month: "short" });
274
+ }
275
+ function formatDateLocalized(date, format = "medium") {
276
+ const d = typeof date === "string" ? new Date(date) : date;
277
+ switch (format) {
278
+ case "short":
279
+ return d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
280
+ case "medium":
281
+ return d.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
282
+ case "long":
283
+ return d.toLocaleDateString("en-US", {
284
+ weekday: "long",
285
+ month: "long",
286
+ day: "numeric",
287
+ year: "numeric"
288
+ });
289
+ case "weekday":
290
+ return d.toLocaleDateString("en-US", { weekday: "short" });
291
+ default:
292
+ return d.toLocaleDateString();
293
+ }
294
+ }
295
+ function formatTimeLocalized(date, format = "short") {
296
+ const d = typeof date === "string" ? new Date(date) : date;
297
+ switch (format) {
298
+ case "short":
299
+ return d.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: true });
300
+ case "withSeconds":
301
+ return d.toLocaleTimeString("en-US", {
302
+ hour: "2-digit",
303
+ minute: "2-digit",
304
+ second: "2-digit",
305
+ hour12: true
306
+ });
307
+ default:
308
+ return d.toLocaleTimeString();
309
+ }
310
+ }
311
+ // Annotate the CommonJS export names for ESM import in node:
312
+ 0 && (module.exports = {
313
+ addDays,
314
+ formatDateHeader,
315
+ formatDateLocalized,
316
+ formatDateLong,
317
+ formatDateString,
318
+ formatDueDateString,
319
+ formatFullDate,
320
+ formatMonthYear,
321
+ formatRelativeDueDate,
322
+ formatRelativePayDate,
323
+ formatRelativeTimeExtended,
324
+ formatTimeHHMM,
325
+ formatTimeLocalized,
326
+ formatTimeWithSeconds,
327
+ formatWeekRange,
328
+ getEndOfDayISO,
329
+ getNextWeek,
330
+ getPreviousWeek,
331
+ getStartOfDayISO,
332
+ getTodayMidnight,
333
+ getTodayString,
334
+ getTomorrowString,
335
+ getWeekEnd,
336
+ getWeekEndString,
337
+ getWeekStart,
338
+ getWeekStartString,
339
+ getYesterdayString,
340
+ isDueSoon,
341
+ isOverdue,
342
+ isToday,
343
+ normalizeToMidnight,
344
+ parseLocalDate,
345
+ subtractDays
346
+ });
347
+ //# sourceMappingURL=index.js.map