ts-time-utils 0.0.1

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 (80) hide show
  1. package/README.md +343 -0
  2. package/dist/age.d.ts +49 -0
  3. package/dist/age.d.ts.map +1 -0
  4. package/dist/age.js +106 -0
  5. package/dist/calculate.d.ts +49 -0
  6. package/dist/calculate.d.ts.map +1 -0
  7. package/dist/calculate.js +179 -0
  8. package/dist/calendar.d.ts +82 -0
  9. package/dist/calendar.d.ts.map +1 -0
  10. package/dist/calendar.js +154 -0
  11. package/dist/constants.d.ts +35 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/constants.js +17 -0
  14. package/dist/esm/age.d.ts +49 -0
  15. package/dist/esm/age.d.ts.map +1 -0
  16. package/dist/esm/age.js +106 -0
  17. package/dist/esm/calculate.d.ts +49 -0
  18. package/dist/esm/calculate.d.ts.map +1 -0
  19. package/dist/esm/calculate.js +179 -0
  20. package/dist/esm/calendar.d.ts +82 -0
  21. package/dist/esm/calendar.d.ts.map +1 -0
  22. package/dist/esm/calendar.js +154 -0
  23. package/dist/esm/constants.d.ts +35 -0
  24. package/dist/esm/constants.d.ts.map +1 -0
  25. package/dist/esm/constants.js +17 -0
  26. package/dist/esm/format.d.ts +25 -0
  27. package/dist/esm/format.d.ts.map +1 -0
  28. package/dist/esm/format.js +189 -0
  29. package/dist/esm/index.d.ts +17 -0
  30. package/dist/esm/index.d.ts.map +1 -0
  31. package/dist/esm/index.js +28 -0
  32. package/dist/esm/interval.d.ts +30 -0
  33. package/dist/esm/interval.d.ts.map +1 -0
  34. package/dist/esm/interval.js +86 -0
  35. package/dist/esm/parse.d.ts +31 -0
  36. package/dist/esm/parse.d.ts.map +1 -0
  37. package/dist/esm/parse.js +217 -0
  38. package/dist/esm/performance.d.ts +110 -0
  39. package/dist/esm/performance.d.ts.map +1 -0
  40. package/dist/esm/performance.js +222 -0
  41. package/dist/esm/rangePresets.d.ts +45 -0
  42. package/dist/esm/rangePresets.d.ts.map +1 -0
  43. package/dist/esm/rangePresets.js +124 -0
  44. package/dist/esm/timezone.d.ts +38 -0
  45. package/dist/esm/timezone.d.ts.map +1 -0
  46. package/dist/esm/timezone.js +99 -0
  47. package/dist/esm/validate.d.ts +62 -0
  48. package/dist/esm/validate.d.ts.map +1 -0
  49. package/dist/esm/validate.js +108 -0
  50. package/dist/esm/workingHours.d.ts +25 -0
  51. package/dist/esm/workingHours.d.ts.map +1 -0
  52. package/dist/esm/workingHours.js +107 -0
  53. package/dist/format.d.ts +25 -0
  54. package/dist/format.d.ts.map +1 -0
  55. package/dist/format.js +189 -0
  56. package/dist/index.d.ts +17 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +28 -0
  59. package/dist/interval.d.ts +30 -0
  60. package/dist/interval.d.ts.map +1 -0
  61. package/dist/interval.js +86 -0
  62. package/dist/parse.d.ts +31 -0
  63. package/dist/parse.d.ts.map +1 -0
  64. package/dist/parse.js +217 -0
  65. package/dist/performance.d.ts +110 -0
  66. package/dist/performance.d.ts.map +1 -0
  67. package/dist/performance.js +222 -0
  68. package/dist/rangePresets.d.ts +45 -0
  69. package/dist/rangePresets.d.ts.map +1 -0
  70. package/dist/rangePresets.js +124 -0
  71. package/dist/timezone.d.ts +38 -0
  72. package/dist/timezone.d.ts.map +1 -0
  73. package/dist/timezone.js +99 -0
  74. package/dist/validate.d.ts +62 -0
  75. package/dist/validate.d.ts.map +1 -0
  76. package/dist/validate.js +108 -0
  77. package/dist/workingHours.d.ts +25 -0
  78. package/dist/workingHours.d.ts.map +1 -0
  79. package/dist/workingHours.js +107 -0
  80. package/package.json +102 -0
@@ -0,0 +1,179 @@
1
+ import { MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_MONTH, MILLISECONDS_PER_YEAR } from './constants.js';
2
+ /**
3
+ * Calculate difference between two dates in specified unit
4
+ * @param date1 - first date
5
+ * @param date2 - second date
6
+ * @param unit - unit to return the difference in
7
+ * @param precise - if true, returns decimal values; if false, returns integers
8
+ */
9
+ export function differenceInUnits(date1, date2, unit = 'milliseconds', precise = true) {
10
+ const diffMs = Math.abs(date1.getTime() - date2.getTime());
11
+ let result;
12
+ switch (unit) {
13
+ case 'years':
14
+ result = diffMs / MILLISECONDS_PER_YEAR;
15
+ break;
16
+ case 'months':
17
+ result = diffMs / MILLISECONDS_PER_MONTH;
18
+ break;
19
+ case 'weeks':
20
+ result = diffMs / MILLISECONDS_PER_WEEK;
21
+ break;
22
+ case 'days':
23
+ result = diffMs / MILLISECONDS_PER_DAY;
24
+ break;
25
+ case 'hours':
26
+ result = diffMs / MILLISECONDS_PER_HOUR;
27
+ break;
28
+ case 'minutes':
29
+ result = diffMs / MILLISECONDS_PER_MINUTE;
30
+ break;
31
+ case 'seconds':
32
+ result = diffMs / MILLISECONDS_PER_SECOND;
33
+ break;
34
+ case 'milliseconds':
35
+ default:
36
+ result = diffMs;
37
+ break;
38
+ }
39
+ return precise ? result : Math.floor(result);
40
+ }
41
+ /**
42
+ * Add time to a date
43
+ * @param date - base date
44
+ * @param amount - amount to add
45
+ * @param unit - unit of the amount
46
+ */
47
+ export function addTime(date, amount, unit) {
48
+ const result = new Date(date);
49
+ let milliseconds;
50
+ switch (unit) {
51
+ case 'years':
52
+ milliseconds = amount * MILLISECONDS_PER_YEAR;
53
+ break;
54
+ case 'months':
55
+ milliseconds = amount * MILLISECONDS_PER_MONTH;
56
+ break;
57
+ case 'weeks':
58
+ milliseconds = amount * MILLISECONDS_PER_WEEK;
59
+ break;
60
+ case 'days':
61
+ milliseconds = amount * MILLISECONDS_PER_DAY;
62
+ break;
63
+ case 'hours':
64
+ milliseconds = amount * MILLISECONDS_PER_HOUR;
65
+ break;
66
+ case 'minutes':
67
+ milliseconds = amount * MILLISECONDS_PER_MINUTE;
68
+ break;
69
+ case 'seconds':
70
+ milliseconds = amount * MILLISECONDS_PER_SECOND;
71
+ break;
72
+ case 'milliseconds':
73
+ default:
74
+ milliseconds = amount;
75
+ break;
76
+ }
77
+ result.setTime(result.getTime() + milliseconds);
78
+ return result;
79
+ }
80
+ /**
81
+ * Subtract time from a date
82
+ * @param date - base date
83
+ * @param amount - amount to subtract
84
+ * @param unit - unit of the amount
85
+ */
86
+ export function subtractTime(date, amount, unit) {
87
+ return addTime(date, -amount, unit);
88
+ }
89
+ /**
90
+ * Get the start of a time period for a given date
91
+ * @param date - input date
92
+ * @param unit - time unit to get the start of
93
+ */
94
+ export function startOf(date, unit) {
95
+ const result = new Date(date);
96
+ switch (unit) {
97
+ case 'minute':
98
+ result.setSeconds(0, 0);
99
+ break;
100
+ case 'hour':
101
+ result.setMinutes(0, 0, 0);
102
+ break;
103
+ case 'day':
104
+ result.setHours(0, 0, 0, 0);
105
+ break;
106
+ case 'week':
107
+ result.setHours(0, 0, 0, 0);
108
+ result.setDate(result.getDate() - result.getDay());
109
+ break;
110
+ case 'month':
111
+ result.setHours(0, 0, 0, 0);
112
+ result.setDate(1);
113
+ break;
114
+ case 'year':
115
+ result.setHours(0, 0, 0, 0);
116
+ result.setMonth(0, 1);
117
+ break;
118
+ }
119
+ return result;
120
+ }
121
+ /**
122
+ * Get the end of a time period for a given date
123
+ * @param date - input date
124
+ * @param unit - time unit to get the end of
125
+ */
126
+ export function endOf(date, unit) {
127
+ const result = new Date(date);
128
+ switch (unit) {
129
+ case 'minute':
130
+ result.setSeconds(59, 999);
131
+ break;
132
+ case 'hour':
133
+ result.setMinutes(59, 59, 999);
134
+ break;
135
+ case 'day':
136
+ result.setHours(23, 59, 59, 999);
137
+ break;
138
+ case 'week':
139
+ result.setHours(23, 59, 59, 999);
140
+ result.setDate(result.getDate() + (6 - result.getDay()));
141
+ break;
142
+ case 'month':
143
+ result.setHours(23, 59, 59, 999);
144
+ result.setMonth(result.getMonth() + 1, 0);
145
+ break;
146
+ case 'year':
147
+ result.setHours(23, 59, 59, 999);
148
+ result.setMonth(11, 31);
149
+ break;
150
+ }
151
+ return result;
152
+ }
153
+ /**
154
+ * Check if a date is between two other dates
155
+ * @param date - date to check
156
+ * @param start - start date (inclusive)
157
+ * @param end - end date (inclusive)
158
+ */
159
+ export function isBetween(date, start, end) {
160
+ const time = date.getTime();
161
+ return time >= start.getTime() && time <= end.getTime();
162
+ }
163
+ /**
164
+ * Get the number of business days between two dates (excludes weekends)
165
+ * @param startDate - start date
166
+ * @param endDate - end date
167
+ */
168
+ export function businessDaysBetween(startDate, endDate) {
169
+ let count = 0;
170
+ const current = new Date(startDate);
171
+ while (current <= endDate) {
172
+ const dayOfWeek = current.getDay();
173
+ if (dayOfWeek !== 0 && dayOfWeek !== 6) { // Not Sunday (0) or Saturday (6)
174
+ count++;
175
+ }
176
+ current.setDate(current.getDate() + 1);
177
+ }
178
+ return count;
179
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Calendar and holiday utilities
3
+ */
4
+ /**
5
+ * Get the week number of the year (ISO 8601)
6
+ * @param date - date to get week number for
7
+ */
8
+ export declare function getWeekNumber(date: Date): number;
9
+ /**
10
+ * Get the week of the month (1-6)
11
+ * @param date - date to get week of month for
12
+ */
13
+ export declare function getWeekOfMonth(date: Date): number;
14
+ /**
15
+ * Get the quarter of the year (1-4)
16
+ * @param date - date to get quarter for
17
+ */
18
+ export declare function getQuarter(date: Date): number;
19
+ /**
20
+ * Get the day of the year (1-366)
21
+ * @param date - date to get day of year for
22
+ */
23
+ export declare function getDayOfYear(date: Date): number;
24
+ /**
25
+ * Get the number of weeks in a year
26
+ * @param year - year to check
27
+ */
28
+ export declare function getWeeksInYear(year: number): number;
29
+ /**
30
+ * Get the number of days in a month
31
+ * @param year - year
32
+ * @param month - month (0-11)
33
+ */
34
+ export declare function getDaysInMonth(year: number, month: number): number;
35
+ /**
36
+ * Get the number of days in a year
37
+ * @param year - year to check
38
+ */
39
+ export declare function getDaysInYear(year: number): number;
40
+ /**
41
+ * Calculate Easter Sunday for a given year (Western/Gregorian calendar)
42
+ * @param year - year to calculate Easter for
43
+ */
44
+ export declare function getEaster(year: number): Date;
45
+ /**
46
+ * Get all months in a year
47
+ * @param year - year to get months for
48
+ */
49
+ export declare function getMonthsInYear(year: number): Date[];
50
+ /**
51
+ * Get all days in a month
52
+ * @param year - year
53
+ * @param month - month (0-11)
54
+ */
55
+ export declare function getDaysInMonthArray(year: number, month: number): Date[];
56
+ /**
57
+ * Get all weekdays in a month
58
+ * @param year - year
59
+ * @param month - month (0-11)
60
+ */
61
+ export declare function getWeekdaysInMonth(year: number, month: number): Date[];
62
+ /**
63
+ * Get the first day of the month
64
+ * @param date - any date in the month
65
+ */
66
+ export declare function getFirstDayOfMonth(date: Date): Date;
67
+ /**
68
+ * Get the last day of the month
69
+ * @param date - any date in the month
70
+ */
71
+ export declare function getLastDayOfMonth(date: Date): Date;
72
+ /**
73
+ * Get the first day of the year
74
+ * @param year - year
75
+ */
76
+ export declare function getFirstDayOfYear(year: number): Date;
77
+ /**
78
+ * Get the last day of the year
79
+ * @param year - year
80
+ */
81
+ export declare function getLastDayOfYear(year: number): Date;
82
+ //# sourceMappingURL=calendar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../../src/calendar.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAMhD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAKjD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAI/C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAUD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAkB5C;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,CAGvE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,CAKtE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAEnD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAElD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEpD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEnD"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Calendar and holiday utilities
3
+ */
4
+ /**
5
+ * Get the week number of the year (ISO 8601)
6
+ * @param date - date to get week number for
7
+ */
8
+ export function getWeekNumber(date) {
9
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
10
+ const dayNum = d.getUTCDay() || 7;
11
+ d.setUTCDate(d.getUTCDate() + 4 - dayNum);
12
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
13
+ return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);
14
+ }
15
+ /**
16
+ * Get the week of the month (1-6)
17
+ * @param date - date to get week of month for
18
+ */
19
+ export function getWeekOfMonth(date) {
20
+ const firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
21
+ const firstWeekday = firstDay.getDay();
22
+ const offsetDate = date.getDate() + firstWeekday - 1;
23
+ return Math.floor(offsetDate / 7) + 1;
24
+ }
25
+ /**
26
+ * Get the quarter of the year (1-4)
27
+ * @param date - date to get quarter for
28
+ */
29
+ export function getQuarter(date) {
30
+ return Math.floor(date.getMonth() / 3) + 1;
31
+ }
32
+ /**
33
+ * Get the day of the year (1-366)
34
+ * @param date - date to get day of year for
35
+ */
36
+ export function getDayOfYear(date) {
37
+ const start = new Date(date.getFullYear(), 0, 0);
38
+ const diff = date.getTime() - start.getTime();
39
+ return Math.floor(diff / (1000 * 60 * 60 * 24));
40
+ }
41
+ /**
42
+ * Get the number of weeks in a year
43
+ * @param year - year to check
44
+ */
45
+ export function getWeeksInYear(year) {
46
+ const jan1 = new Date(year, 0, 1);
47
+ const dec31 = new Date(year, 11, 31);
48
+ // If Jan 1 is Thu-Sun or Dec 31 is Mon-Wed, there are 53 weeks
49
+ const jan1Day = jan1.getDay();
50
+ const dec31Day = dec31.getDay();
51
+ if (jan1Day === 4 || (jan1Day === 3 && dec31Day === 4)) {
52
+ return 53;
53
+ }
54
+ return 52;
55
+ }
56
+ /**
57
+ * Get the number of days in a month
58
+ * @param year - year
59
+ * @param month - month (0-11)
60
+ */
61
+ export function getDaysInMonth(year, month) {
62
+ return new Date(year, month + 1, 0).getDate();
63
+ }
64
+ /**
65
+ * Get the number of days in a year
66
+ * @param year - year to check
67
+ */
68
+ export function getDaysInYear(year) {
69
+ return isLeapYear(year) ? 366 : 365;
70
+ }
71
+ /**
72
+ * Check if a year is a leap year
73
+ * @param year - year to check
74
+ */
75
+ function isLeapYear(year) {
76
+ return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
77
+ }
78
+ /**
79
+ * Calculate Easter Sunday for a given year (Western/Gregorian calendar)
80
+ * @param year - year to calculate Easter for
81
+ */
82
+ export function getEaster(year) {
83
+ // Anonymous Gregorian algorithm
84
+ const a = year % 19;
85
+ const b = Math.floor(year / 100);
86
+ const c = year % 100;
87
+ const d = Math.floor(b / 4);
88
+ const e = b % 4;
89
+ const f = Math.floor((b + 8) / 25);
90
+ const g = Math.floor((b - f + 1) / 3);
91
+ const h = (19 * a + b - d - g + 15) % 30;
92
+ const i = Math.floor(c / 4);
93
+ const k = c % 4;
94
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
95
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
96
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
97
+ const day = ((h + l - 7 * m + 114) % 31) + 1;
98
+ return new Date(year, month - 1, day);
99
+ }
100
+ /**
101
+ * Get all months in a year
102
+ * @param year - year to get months for
103
+ */
104
+ export function getMonthsInYear(year) {
105
+ return Array.from({ length: 12 }, (_, i) => new Date(year, i, 1));
106
+ }
107
+ /**
108
+ * Get all days in a month
109
+ * @param year - year
110
+ * @param month - month (0-11)
111
+ */
112
+ export function getDaysInMonthArray(year, month) {
113
+ const daysCount = getDaysInMonth(year, month);
114
+ return Array.from({ length: daysCount }, (_, i) => new Date(year, month, i + 1));
115
+ }
116
+ /**
117
+ * Get all weekdays in a month
118
+ * @param year - year
119
+ * @param month - month (0-11)
120
+ */
121
+ export function getWeekdaysInMonth(year, month) {
122
+ return getDaysInMonthArray(year, month).filter(date => {
123
+ const day = date.getDay();
124
+ return day !== 0 && day !== 6; // Not Sunday or Saturday
125
+ });
126
+ }
127
+ /**
128
+ * Get the first day of the month
129
+ * @param date - any date in the month
130
+ */
131
+ export function getFirstDayOfMonth(date) {
132
+ return new Date(date.getFullYear(), date.getMonth(), 1);
133
+ }
134
+ /**
135
+ * Get the last day of the month
136
+ * @param date - any date in the month
137
+ */
138
+ export function getLastDayOfMonth(date) {
139
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0);
140
+ }
141
+ /**
142
+ * Get the first day of the year
143
+ * @param year - year
144
+ */
145
+ export function getFirstDayOfYear(year) {
146
+ return new Date(year, 0, 1);
147
+ }
148
+ /**
149
+ * Get the last day of the year
150
+ * @param year - year
151
+ */
152
+ export function getLastDayOfYear(year) {
153
+ return new Date(year, 11, 31);
154
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Time constants for millisecond conversions
3
+ */
4
+ export declare const MILLISECONDS_PER_SECOND = 1000;
5
+ export declare const MILLISECONDS_PER_MINUTE: number;
6
+ export declare const MILLISECONDS_PER_HOUR: number;
7
+ export declare const MILLISECONDS_PER_DAY: number;
8
+ export declare const MILLISECONDS_PER_WEEK: number;
9
+ export declare const MILLISECONDS_PER_MONTH: number;
10
+ export declare const MILLISECONDS_PER_YEAR: number;
11
+ /**
12
+ * Second-based constants
13
+ */
14
+ export declare const SECONDS_PER_MINUTE = 60;
15
+ export declare const SECONDS_PER_HOUR: number;
16
+ export declare const SECONDS_PER_DAY: number;
17
+ export declare const SECONDS_PER_WEEK: number;
18
+ /**
19
+ * Common time units
20
+ */
21
+ export type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years';
22
+ /**
23
+ * Formatting options
24
+ */
25
+ export interface FormatOptions {
26
+ /** Include milliseconds in output */
27
+ includeMs?: boolean;
28
+ /** Use short format (e.g., "1h" vs "1 hour") */
29
+ short?: boolean;
30
+ /** Maximum number of units to show */
31
+ maxUnits?: number;
32
+ /** Round to nearest unit instead of floor */
33
+ round?: boolean;
34
+ }
35
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,uBAAuB,QAA+B,CAAC;AACpE,eAAO,MAAM,qBAAqB,QAA+B,CAAC;AAClE,eAAO,MAAM,oBAAoB,QAA6B,CAAC;AAC/D,eAAO,MAAM,qBAAqB,QAA2B,CAAC;AAC9D,eAAO,MAAM,sBAAsB,QAA4B,CAAC;AAChE,eAAO,MAAM,qBAAqB,QAA6B,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,gBAAgB,QAA0B,CAAC;AACxD,eAAO,MAAM,eAAe,QAAwB,CAAC;AACrD,eAAO,MAAM,gBAAgB,QAAsB,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEhH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gDAAgD;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Time constants for millisecond conversions
3
+ */
4
+ export const MILLISECONDS_PER_SECOND = 1000;
5
+ export const MILLISECONDS_PER_MINUTE = 60 * MILLISECONDS_PER_SECOND;
6
+ export const MILLISECONDS_PER_HOUR = 60 * MILLISECONDS_PER_MINUTE;
7
+ export const MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
8
+ export const MILLISECONDS_PER_WEEK = 7 * MILLISECONDS_PER_DAY;
9
+ export const MILLISECONDS_PER_MONTH = 30 * MILLISECONDS_PER_DAY; // Approximate
10
+ export const MILLISECONDS_PER_YEAR = 365 * MILLISECONDS_PER_DAY; // Approximate
11
+ /**
12
+ * Second-based constants
13
+ */
14
+ export const SECONDS_PER_MINUTE = 60;
15
+ export const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
16
+ export const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
17
+ export const SECONDS_PER_WEEK = 7 * SECONDS_PER_DAY;
@@ -0,0 +1,25 @@
1
+ import { FormatOptions } from './constants.js';
2
+ /**
3
+ * Convert milliseconds to a human-readable duration.
4
+ * @param ms - milliseconds
5
+ * @param options - formatting options
6
+ */
7
+ export declare function formatDuration(ms: number, options?: FormatOptions): string;
8
+ /**
9
+ * Return a human-readable "time ago" string.
10
+ * @param date - past or future date
11
+ * @param options - formatting options
12
+ */
13
+ export declare function timeAgo(date: Date, options?: FormatOptions): string;
14
+ /**
15
+ * Format a date to a human-readable time string
16
+ * @param date - date to format
17
+ * @param format - format type
18
+ */
19
+ export declare function formatTime(date: Date, format?: '12h' | '24h' | 'iso'): string;
20
+ /**
21
+ * Parse a duration string like "1h 30m" into milliseconds
22
+ * @param duration - duration string (e.g., "1h 30m", "2d", "45s")
23
+ */
24
+ export declare function parseDuration(duration: string): number;
25
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA2E9E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA+CvE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,KAAK,GAAG,KAAK,GAAG,KAAa,GAAG,MAAM,CAcpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAyDtD"}