ts-time-utils 1.1.0 → 3.0.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.
Files changed (92) hide show
  1. package/README.md +567 -12
  2. package/dist/calculate.d.ts +7 -2
  3. package/dist/calculate.d.ts.map +1 -1
  4. package/dist/calculate.js +13 -3
  5. package/dist/calendar.d.ts +103 -0
  6. package/dist/calendar.d.ts.map +1 -1
  7. package/dist/calendar.js +224 -0
  8. package/dist/chain.d.ts +269 -0
  9. package/dist/chain.d.ts.map +1 -0
  10. package/dist/chain.js +422 -0
  11. package/dist/compare.d.ts +217 -0
  12. package/dist/compare.d.ts.map +1 -0
  13. package/dist/compare.js +417 -0
  14. package/dist/cron.d.ts +82 -0
  15. package/dist/cron.d.ts.map +1 -0
  16. package/dist/cron.js +294 -0
  17. package/dist/esm/calculate.d.ts +7 -2
  18. package/dist/esm/calculate.d.ts.map +1 -1
  19. package/dist/esm/calculate.js +13 -3
  20. package/dist/esm/calendar.d.ts +103 -0
  21. package/dist/esm/calendar.d.ts.map +1 -1
  22. package/dist/esm/calendar.js +224 -0
  23. package/dist/esm/chain.d.ts +269 -0
  24. package/dist/esm/chain.d.ts.map +1 -0
  25. package/dist/esm/chain.js +422 -0
  26. package/dist/esm/compare.d.ts +217 -0
  27. package/dist/esm/compare.d.ts.map +1 -0
  28. package/dist/esm/compare.js +417 -0
  29. package/dist/esm/cron.d.ts +82 -0
  30. package/dist/esm/cron.d.ts.map +1 -0
  31. package/dist/esm/cron.js +294 -0
  32. package/dist/esm/fiscal.d.ts +195 -0
  33. package/dist/esm/fiscal.d.ts.map +1 -0
  34. package/dist/esm/fiscal.js +295 -0
  35. package/dist/esm/format.d.ts +65 -0
  36. package/dist/esm/format.d.ts.map +1 -1
  37. package/dist/esm/format.js +202 -0
  38. package/dist/esm/holidays.d.ts +62 -0
  39. package/dist/esm/holidays.d.ts.map +1 -0
  40. package/dist/esm/holidays.js +793 -0
  41. package/dist/esm/index.d.ts +18 -6
  42. package/dist/esm/index.d.ts.map +1 -1
  43. package/dist/esm/index.js +20 -6
  44. package/dist/esm/iterate.d.ts +212 -0
  45. package/dist/esm/iterate.d.ts.map +1 -0
  46. package/dist/esm/iterate.js +409 -0
  47. package/dist/esm/parse.d.ts +45 -0
  48. package/dist/esm/parse.d.ts.map +1 -1
  49. package/dist/esm/parse.js +207 -0
  50. package/dist/esm/plugins.d.ts +129 -0
  51. package/dist/esm/plugins.d.ts.map +1 -0
  52. package/dist/esm/plugins.js +173 -0
  53. package/dist/esm/timezone.d.ts +52 -0
  54. package/dist/esm/timezone.d.ts.map +1 -1
  55. package/dist/esm/timezone.js +171 -0
  56. package/dist/esm/validate.d.ts +51 -0
  57. package/dist/esm/validate.d.ts.map +1 -1
  58. package/dist/esm/validate.js +92 -0
  59. package/dist/esm/workingHours.d.ts +70 -0
  60. package/dist/esm/workingHours.d.ts.map +1 -1
  61. package/dist/esm/workingHours.js +161 -0
  62. package/dist/fiscal.d.ts +195 -0
  63. package/dist/fiscal.d.ts.map +1 -0
  64. package/dist/fiscal.js +295 -0
  65. package/dist/format.d.ts +65 -0
  66. package/dist/format.d.ts.map +1 -1
  67. package/dist/format.js +202 -0
  68. package/dist/holidays.d.ts +62 -0
  69. package/dist/holidays.d.ts.map +1 -0
  70. package/dist/holidays.js +793 -0
  71. package/dist/index.d.ts +18 -6
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +20 -6
  74. package/dist/iterate.d.ts +212 -0
  75. package/dist/iterate.d.ts.map +1 -0
  76. package/dist/iterate.js +409 -0
  77. package/dist/parse.d.ts +45 -0
  78. package/dist/parse.d.ts.map +1 -1
  79. package/dist/parse.js +207 -0
  80. package/dist/plugins.d.ts +129 -0
  81. package/dist/plugins.d.ts.map +1 -0
  82. package/dist/plugins.js +173 -0
  83. package/dist/timezone.d.ts +52 -0
  84. package/dist/timezone.d.ts.map +1 -1
  85. package/dist/timezone.js +171 -0
  86. package/dist/validate.d.ts +51 -0
  87. package/dist/validate.d.ts.map +1 -1
  88. package/dist/validate.js +92 -0
  89. package/dist/workingHours.d.ts +70 -0
  90. package/dist/workingHours.d.ts.map +1 -1
  91. package/dist/workingHours.js +161 -0
  92. package/package.json +40 -1
@@ -106,3 +106,95 @@ export function isValidISOString(dateString) {
106
106
  const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
107
107
  return isoRegex.test(dateString) && isValidDate(dateString);
108
108
  }
109
+ /**
110
+ * Check if two dates are in the same week (ISO week, Monday-Sunday)
111
+ * @param date1 - first date
112
+ * @param date2 - second date
113
+ */
114
+ export function isSameWeek(date1, date2) {
115
+ const getWeekStart = (d) => {
116
+ const date = new Date(d);
117
+ const day = date.getDay();
118
+ const diff = date.getDate() - day + (day === 0 ? -6 : 1); // Adjust for Monday start
119
+ date.setDate(diff);
120
+ date.setHours(0, 0, 0, 0);
121
+ return date;
122
+ };
123
+ return getWeekStart(date1).getTime() === getWeekStart(date2).getTime();
124
+ }
125
+ /**
126
+ * Check if two dates are in the same month
127
+ * @param date1 - first date
128
+ * @param date2 - second date
129
+ */
130
+ export function isSameMonth(date1, date2) {
131
+ return (date1.getMonth() === date2.getMonth() &&
132
+ date1.getFullYear() === date2.getFullYear());
133
+ }
134
+ /**
135
+ * Check if two dates are in the same year
136
+ * @param date1 - first date
137
+ * @param date2 - second date
138
+ */
139
+ export function isSameYear(date1, date2) {
140
+ return date1.getFullYear() === date2.getFullYear();
141
+ }
142
+ /**
143
+ * Check if a date is in the current week
144
+ * @param date - date to check
145
+ */
146
+ export function isThisWeek(date) {
147
+ return isSameWeek(date, new Date());
148
+ }
149
+ /**
150
+ * Check if a date is in the current month
151
+ * @param date - date to check
152
+ */
153
+ export function isThisMonth(date) {
154
+ return isSameMonth(date, new Date());
155
+ }
156
+ /**
157
+ * Check if a date is in the current year
158
+ * @param date - date to check
159
+ */
160
+ export function isThisYear(date) {
161
+ return isSameYear(date, new Date());
162
+ }
163
+ /**
164
+ * Check if a date is a business day (weekday, optionally excluding holidays)
165
+ * @param date - date to check
166
+ * @param holidays - optional array of holiday dates to exclude
167
+ */
168
+ export function isBusinessDay(date, holidays = []) {
169
+ if (isWeekend(date))
170
+ return false;
171
+ return !holidays.some(holiday => isSameDay(date, holiday));
172
+ }
173
+ /**
174
+ * Check if a date is in the last N days (including today)
175
+ * @param date - date to check
176
+ * @param n - number of days
177
+ */
178
+ export function isInLastNDays(date, n) {
179
+ const now = new Date();
180
+ const nDaysAgo = new Date(now);
181
+ nDaysAgo.setDate(nDaysAgo.getDate() - n);
182
+ nDaysAgo.setHours(0, 0, 0, 0);
183
+ const endOfToday = new Date(now);
184
+ endOfToday.setHours(23, 59, 59, 999);
185
+ return date >= nDaysAgo && date <= endOfToday;
186
+ }
187
+ /**
188
+ * Check if a date is in the next N days (including today)
189
+ * @param date - date to check
190
+ * @param n - number of days
191
+ */
192
+ export function isInNextNDays(date, n) {
193
+ const now = new Date();
194
+ const startOfToday = new Date(now);
195
+ startOfToday.setHours(0, 0, 0, 0);
196
+ const nDaysFromNow = new Date(now);
197
+ nDaysFromNow.setDate(nDaysFromNow.getDate() + n);
198
+ nDaysFromNow.setHours(23, 59, 59, 999);
199
+ return date >= startOfToday && date <= nDaysFromNow;
200
+ }
@@ -13,4 +13,74 @@ export declare function nextWorkingTime(date: Date, config?: WorkingHoursConfig)
13
13
  export declare function workingTimeBetween(start: Date, end: Date, config?: WorkingHoursConfig): number;
14
14
  /** Advance by working hours amount (simple iterative approach) */
15
15
  export declare function addWorkingHours(start: Date, hours: number, config?: WorkingHoursConfig): Date;
16
+ /**
17
+ * Add working days to a date
18
+ * @param start - start date
19
+ * @param days - number of working days to add
20
+ * @param config - working hours configuration
21
+ */
22
+ export declare function addWorkingDays(start: Date, days: number, config?: WorkingHoursConfig): Date;
23
+ /**
24
+ * Subtract working days from a date
25
+ * @param start - start date
26
+ * @param days - number of working days to subtract
27
+ * @param config - working hours configuration
28
+ */
29
+ export declare function subtractWorkingDays(start: Date, days: number, config?: WorkingHoursConfig): Date;
30
+ /**
31
+ * Get the next working day from a given date
32
+ * @param date - start date
33
+ * @param config - working hours configuration
34
+ */
35
+ export declare function getNextWorkingDay(date: Date, config?: WorkingHoursConfig): Date;
36
+ /**
37
+ * Get the previous working day from a given date
38
+ * @param date - start date
39
+ * @param config - working hours configuration
40
+ */
41
+ export declare function getPreviousWorkingDay(date: Date, config?: WorkingHoursConfig): Date;
42
+ /**
43
+ * Get the number of working days in a month
44
+ * @param year - year
45
+ * @param month - month (0-11)
46
+ * @param config - working hours configuration
47
+ */
48
+ export declare function getWorkingDaysInMonth(year: number, month: number, config?: WorkingHoursConfig): number;
49
+ /**
50
+ * Get all working days in a month as an array of dates
51
+ * @param year - year
52
+ * @param month - month (0-11)
53
+ * @param config - working hours configuration
54
+ */
55
+ export declare function getWorkingDaysInMonthArray(year: number, month: number, config?: WorkingHoursConfig): Date[];
56
+ /**
57
+ * Get working days between two dates (inclusive)
58
+ * @param start - start date
59
+ * @param end - end date
60
+ * @param config - working hours configuration
61
+ */
62
+ export declare function workingDaysBetween(start: Date, end: Date, config?: WorkingHoursConfig): number;
63
+ /**
64
+ * Check if a date is during work break
65
+ * @param date - date to check
66
+ * @param config - working hours configuration
67
+ */
68
+ export declare function isBreakTime(date: Date, config?: WorkingHoursConfig): boolean;
69
+ /**
70
+ * Get the start of the work day for a given date
71
+ * @param date - date to get work start for
72
+ * @param config - working hours configuration
73
+ */
74
+ export declare function getWorkDayStart(date: Date, config?: WorkingHoursConfig): Date;
75
+ /**
76
+ * Get the end of the work day for a given date
77
+ * @param date - date to get work end for
78
+ * @param config - working hours configuration
79
+ */
80
+ export declare function getWorkDayEnd(date: Date, config?: WorkingHoursConfig): Date;
81
+ /**
82
+ * Get the total working hours per day (excluding breaks)
83
+ * @param config - working hours configuration
84
+ */
85
+ export declare function getWorkingHoursPerDay(config?: WorkingHoursConfig): number;
16
86
  //# sourceMappingURL=workingHours.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workingHours.d.ts","sourceRoot":"","sources":["../../src/workingHours.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,kBAInC,CAAC;AAEF,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CAEpG;AAOD,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CAUrG;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAMpG;AAYD,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,MAAM,CA+BrH;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAcpH"}
1
+ {"version":3,"file":"workingHours.d.ts","sourceRoot":"","sources":["../../src/workingHours.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,kBAInC,CAAC;AAEF,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CAEpG;AAOD,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CAUrG;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,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,EAAE,MAAM,GAAE,kBAA0C,GAAG,OAAO,CASnG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAIpG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,kBAA0C,GAAG,IAAI,CAIlG;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,kBAA0C,GAAG,MAAM,CAUhG"}
@@ -107,3 +107,164 @@ export function addWorkingHours(start, hours, config = DEFAULT_WORKING_HOURS) {
107
107
  }
108
108
  return cursor;
109
109
  }
110
+ /**
111
+ * Add working days to a date
112
+ * @param start - start date
113
+ * @param days - number of working days to add
114
+ * @param config - working hours configuration
115
+ */
116
+ export function addWorkingDays(start, days, config = DEFAULT_WORKING_HOURS) {
117
+ if (days === 0)
118
+ return new Date(start);
119
+ const result = new Date(start);
120
+ const direction = days > 0 ? 1 : -1;
121
+ let remaining = Math.abs(days);
122
+ while (remaining > 0) {
123
+ result.setDate(result.getDate() + direction);
124
+ if (isWorkingDay(result, config)) {
125
+ remaining--;
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ /**
131
+ * Subtract working days from a date
132
+ * @param start - start date
133
+ * @param days - number of working days to subtract
134
+ * @param config - working hours configuration
135
+ */
136
+ export function subtractWorkingDays(start, days, config = DEFAULT_WORKING_HOURS) {
137
+ return addWorkingDays(start, -days, config);
138
+ }
139
+ /**
140
+ * Get the next working day from a given date
141
+ * @param date - start date
142
+ * @param config - working hours configuration
143
+ */
144
+ export function getNextWorkingDay(date, config = DEFAULT_WORKING_HOURS) {
145
+ const result = new Date(date);
146
+ result.setDate(result.getDate() + 1);
147
+ while (!isWorkingDay(result, config)) {
148
+ result.setDate(result.getDate() + 1);
149
+ }
150
+ return result;
151
+ }
152
+ /**
153
+ * Get the previous working day from a given date
154
+ * @param date - start date
155
+ * @param config - working hours configuration
156
+ */
157
+ export function getPreviousWorkingDay(date, config = DEFAULT_WORKING_HOURS) {
158
+ const result = new Date(date);
159
+ result.setDate(result.getDate() - 1);
160
+ while (!isWorkingDay(result, config)) {
161
+ result.setDate(result.getDate() - 1);
162
+ }
163
+ return result;
164
+ }
165
+ /**
166
+ * Get the number of working days in a month
167
+ * @param year - year
168
+ * @param month - month (0-11)
169
+ * @param config - working hours configuration
170
+ */
171
+ export function getWorkingDaysInMonth(year, month, config = DEFAULT_WORKING_HOURS) {
172
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
173
+ let count = 0;
174
+ for (let day = 1; day <= daysInMonth; day++) {
175
+ const date = new Date(year, month, day);
176
+ if (isWorkingDay(date, config)) {
177
+ count++;
178
+ }
179
+ }
180
+ return count;
181
+ }
182
+ /**
183
+ * Get all working days in a month as an array of dates
184
+ * @param year - year
185
+ * @param month - month (0-11)
186
+ * @param config - working hours configuration
187
+ */
188
+ export function getWorkingDaysInMonthArray(year, month, config = DEFAULT_WORKING_HOURS) {
189
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
190
+ const workingDays = [];
191
+ for (let day = 1; day <= daysInMonth; day++) {
192
+ const date = new Date(year, month, day);
193
+ if (isWorkingDay(date, config)) {
194
+ workingDays.push(date);
195
+ }
196
+ }
197
+ return workingDays;
198
+ }
199
+ /**
200
+ * Get working days between two dates (inclusive)
201
+ * @param start - start date
202
+ * @param end - end date
203
+ * @param config - working hours configuration
204
+ */
205
+ export function workingDaysBetween(start, end, config = DEFAULT_WORKING_HOURS) {
206
+ if (end < start)
207
+ return 0;
208
+ let count = 0;
209
+ const current = new Date(start);
210
+ current.setHours(0, 0, 0, 0);
211
+ const endDate = new Date(end);
212
+ endDate.setHours(0, 0, 0, 0);
213
+ while (current <= endDate) {
214
+ if (isWorkingDay(current, config)) {
215
+ count++;
216
+ }
217
+ current.setDate(current.getDate() + 1);
218
+ }
219
+ return count;
220
+ }
221
+ /**
222
+ * Check if a date is during work break
223
+ * @param date - date to check
224
+ * @param config - working hours configuration
225
+ */
226
+ export function isBreakTime(date, config = DEFAULT_WORKING_HOURS) {
227
+ if (!isWorkingDay(date, config))
228
+ return false;
229
+ if (!config.breaks || config.breaks.length === 0)
230
+ return false;
231
+ const h = toHourFraction(date);
232
+ for (const b of config.breaks) {
233
+ if (h >= b.start && h < b.end)
234
+ return true;
235
+ }
236
+ return false;
237
+ }
238
+ /**
239
+ * Get the start of the work day for a given date
240
+ * @param date - date to get work start for
241
+ * @param config - working hours configuration
242
+ */
243
+ export function getWorkDayStart(date, config = DEFAULT_WORKING_HOURS) {
244
+ const result = new Date(date);
245
+ result.setHours(config.hours.start, 0, 0, 0);
246
+ return result;
247
+ }
248
+ /**
249
+ * Get the end of the work day for a given date
250
+ * @param date - date to get work end for
251
+ * @param config - working hours configuration
252
+ */
253
+ export function getWorkDayEnd(date, config = DEFAULT_WORKING_HOURS) {
254
+ const result = new Date(date);
255
+ result.setHours(config.hours.end, 0, 0, 0);
256
+ return result;
257
+ }
258
+ /**
259
+ * Get the total working hours per day (excluding breaks)
260
+ * @param config - working hours configuration
261
+ */
262
+ export function getWorkingHoursPerDay(config = DEFAULT_WORKING_HOURS) {
263
+ let hours = config.hours.end - config.hours.start;
264
+ if (config.breaks) {
265
+ for (const b of config.breaks) {
266
+ hours -= (b.end - b.start);
267
+ }
268
+ }
269
+ return hours;
270
+ }
@@ -0,0 +1,195 @@
1
+ /**
2
+ * @fileoverview Fiscal year and accounting period utilities
3
+ * Supports configurable fiscal year start months for business calculations
4
+ */
5
+ /**
6
+ * Fiscal year configuration
7
+ */
8
+ export interface FiscalConfig {
9
+ /** Month when fiscal year starts (1-12, default: 1 for January) */
10
+ startMonth: number;
11
+ }
12
+ /**
13
+ * Get the fiscal year for a given date
14
+ * @param date - The date to check
15
+ * @param config - Fiscal year configuration
16
+ * @returns The fiscal year number
17
+ * @example
18
+ * // Calendar year (Jan start)
19
+ * getFiscalYear(new Date('2024-03-15')) // 2024
20
+ *
21
+ * // April fiscal year (UK/India style)
22
+ * getFiscalYear(new Date('2024-03-15'), { startMonth: 4 }) // 2023
23
+ * getFiscalYear(new Date('2024-04-15'), { startMonth: 4 }) // 2024
24
+ *
25
+ * // July fiscal year (Australia style)
26
+ * getFiscalYear(new Date('2024-06-15'), { startMonth: 7 }) // 2023
27
+ * getFiscalYear(new Date('2024-07-15'), { startMonth: 7 }) // 2024
28
+ */
29
+ export declare function getFiscalYear(date: Date, config?: Partial<FiscalConfig>): number;
30
+ /**
31
+ * Get the fiscal quarter for a given date (1-4)
32
+ * @param date - The date to check
33
+ * @param config - Fiscal year configuration
34
+ * @returns The fiscal quarter (1-4)
35
+ * @example
36
+ * // Calendar year quarters
37
+ * getFiscalQuarter(new Date('2024-01-15')) // 1
38
+ * getFiscalQuarter(new Date('2024-04-15')) // 2
39
+ *
40
+ * // April fiscal year
41
+ * getFiscalQuarter(new Date('2024-04-15'), { startMonth: 4 }) // 1
42
+ * getFiscalQuarter(new Date('2024-07-15'), { startMonth: 4 }) // 2
43
+ */
44
+ export declare function getFiscalQuarter(date: Date, config?: Partial<FiscalConfig>): number;
45
+ /**
46
+ * Get the start date of a fiscal year
47
+ * @param fiscalYear - The fiscal year
48
+ * @param config - Fiscal year configuration
49
+ * @returns Start date of the fiscal year
50
+ * @example
51
+ * getFiscalYearStart(2024) // 2024-01-01
52
+ * getFiscalYearStart(2024, { startMonth: 4 }) // 2024-04-01 (FY2024 starts Apr 2024)
53
+ * getFiscalYearStart(2024, { startMonth: 7 }) // 2024-07-01 (FY2024 starts Jul 2024)
54
+ */
55
+ export declare function getFiscalYearStart(fiscalYear: number, config?: Partial<FiscalConfig>): Date;
56
+ /**
57
+ * Get the end date of a fiscal year
58
+ * @param fiscalYear - The fiscal year
59
+ * @param config - Fiscal year configuration
60
+ * @returns End date of the fiscal year (last day, 23:59:59.999)
61
+ * @example
62
+ * getFiscalYearEnd(2024) // 2024-12-31
63
+ * getFiscalYearEnd(2024, { startMonth: 4 }) // 2025-03-31 (FY2024 ends Mar 2025)
64
+ * getFiscalYearEnd(2024, { startMonth: 7 }) // 2025-06-30 (FY2024 ends Jun 2025)
65
+ */
66
+ export declare function getFiscalYearEnd(fiscalYear: number, config?: Partial<FiscalConfig>): Date;
67
+ /**
68
+ * Get the start date of a fiscal quarter
69
+ * @param fiscalYear - The fiscal year
70
+ * @param quarter - The quarter (1-4)
71
+ * @param config - Fiscal year configuration
72
+ * @returns Start date of the fiscal quarter
73
+ * @example
74
+ * getFiscalQuarterStart(2024, 1) // 2024-01-01
75
+ * getFiscalQuarterStart(2024, 2) // 2024-04-01
76
+ * getFiscalQuarterStart(2024, 1, { startMonth: 4 }) // 2023-04-01
77
+ * getFiscalQuarterStart(2024, 2, { startMonth: 4 }) // 2023-07-01
78
+ */
79
+ export declare function getFiscalQuarterStart(fiscalYear: number, quarter: number, config?: Partial<FiscalConfig>): Date;
80
+ /**
81
+ * Get the end date of a fiscal quarter
82
+ * @param fiscalYear - The fiscal year
83
+ * @param quarter - The quarter (1-4)
84
+ * @param config - Fiscal year configuration
85
+ * @returns End date of the fiscal quarter (last day, 23:59:59.999)
86
+ * @example
87
+ * getFiscalQuarterEnd(2024, 1) // 2024-03-31
88
+ * getFiscalQuarterEnd(2024, 2) // 2024-06-30
89
+ * getFiscalQuarterEnd(2024, 1, { startMonth: 4 }) // 2023-06-30
90
+ */
91
+ export declare function getFiscalQuarterEnd(fiscalYear: number, quarter: number, config?: Partial<FiscalConfig>): Date;
92
+ /**
93
+ * Check if two dates are in the same fiscal year
94
+ * @param date1 - First date
95
+ * @param date2 - Second date
96
+ * @param config - Fiscal year configuration
97
+ * @returns True if both dates are in the same fiscal year
98
+ */
99
+ export declare function isSameFiscalYear(date1: Date, date2: Date, config?: Partial<FiscalConfig>): boolean;
100
+ /**
101
+ * Check if two dates are in the same fiscal quarter
102
+ * @param date1 - First date
103
+ * @param date2 - Second date
104
+ * @param config - Fiscal year configuration
105
+ * @returns True if both dates are in the same fiscal year and quarter
106
+ */
107
+ export declare function isSameFiscalQuarter(date1: Date, date2: Date, config?: Partial<FiscalConfig>): boolean;
108
+ /**
109
+ * Get the fiscal month (1-12) within the fiscal year
110
+ * @param date - The date to check
111
+ * @param config - Fiscal year configuration
112
+ * @returns The fiscal month (1-12, where 1 is the first month of fiscal year)
113
+ * @example
114
+ * getFiscalMonth(new Date('2024-01-15')) // 1
115
+ * getFiscalMonth(new Date('2024-04-15'), { startMonth: 4 }) // 1
116
+ * getFiscalMonth(new Date('2024-03-15'), { startMonth: 4 }) // 12
117
+ */
118
+ export declare function getFiscalMonth(date: Date, config?: Partial<FiscalConfig>): number;
119
+ /**
120
+ * Get the number of days remaining in the fiscal year
121
+ * @param date - The date to check
122
+ * @param config - Fiscal year configuration
123
+ * @returns Number of days remaining in the fiscal year
124
+ */
125
+ export declare function getDaysRemainingInFiscalYear(date: Date, config?: Partial<FiscalConfig>): number;
126
+ /**
127
+ * Get the number of days elapsed in the fiscal year
128
+ * @param date - The date to check
129
+ * @param config - Fiscal year configuration
130
+ * @returns Number of days elapsed in the fiscal year (including the given date)
131
+ */
132
+ export declare function getDaysElapsedInFiscalYear(date: Date, config?: Partial<FiscalConfig>): number;
133
+ /**
134
+ * Get fiscal year progress as a percentage
135
+ * @param date - The date to check
136
+ * @param config - Fiscal year configuration
137
+ * @returns Percentage of fiscal year completed (0-100)
138
+ */
139
+ export declare function getFiscalYearProgress(date: Date, config?: Partial<FiscalConfig>): number;
140
+ /**
141
+ * Get the fiscal week number (1-53) within the fiscal year
142
+ * @param date - The date to check
143
+ * @param config - Fiscal year configuration
144
+ * @returns The fiscal week number
145
+ */
146
+ export declare function getFiscalWeek(date: Date, config?: Partial<FiscalConfig>): number;
147
+ /**
148
+ * Common fiscal year configurations
149
+ */
150
+ export declare const FISCAL_PRESETS: {
151
+ /** Calendar year (January start) - Default */
152
+ readonly CALENDAR: FiscalConfig;
153
+ /** UK/India government fiscal year (April start) */
154
+ readonly UK_INDIA: FiscalConfig;
155
+ /** Australian fiscal year (July start) */
156
+ readonly AUSTRALIA: FiscalConfig;
157
+ /** US federal government fiscal year (October start) */
158
+ readonly US_FEDERAL: FiscalConfig;
159
+ };
160
+ /**
161
+ * Format fiscal year as string (e.g., "FY2024" or "FY2023/24")
162
+ * @param fiscalYear - The fiscal year
163
+ * @param config - Fiscal year configuration
164
+ * @param format - Format style: 'short' (FY2024) or 'long' (FY2023/24)
165
+ * @returns Formatted fiscal year string
166
+ */
167
+ export declare function formatFiscalYear(fiscalYear: number, config?: Partial<FiscalConfig>, format?: 'short' | 'long'): string;
168
+ /**
169
+ * Format fiscal quarter as string (e.g., "Q1 FY2024")
170
+ * @param fiscalYear - The fiscal year
171
+ * @param quarter - The quarter (1-4)
172
+ * @param config - Fiscal year configuration
173
+ * @returns Formatted fiscal quarter string
174
+ */
175
+ export declare function formatFiscalQuarter(fiscalYear: number, quarter: number, config?: Partial<FiscalConfig>): string;
176
+ /**
177
+ * Get fiscal period info for a date
178
+ * @param date - The date to analyze
179
+ * @param config - Fiscal year configuration
180
+ * @returns Object with fiscal period information
181
+ */
182
+ export declare function getFiscalPeriodInfo(date: Date, config?: Partial<FiscalConfig>): {
183
+ fiscalYear: number;
184
+ fiscalQuarter: number;
185
+ fiscalMonth: number;
186
+ fiscalWeek: number;
187
+ daysElapsed: number;
188
+ daysRemaining: number;
189
+ progress: number;
190
+ quarterStart: Date;
191
+ quarterEnd: Date;
192
+ yearStart: Date;
193
+ yearEnd: Date;
194
+ };
195
+ //# sourceMappingURL=fiscal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiscal.d.ts","sourceRoot":"","sources":["../src/fiscal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,MAAM,GAAE,OAAO,CAAC,YAAY,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