chronos-ts 1.1.0 → 2.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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Core classes barrel export
3
+ * @module core
4
+ */
5
+ export { Chronos } from './chronos';
6
+ export { ChronosInterval } from './interval';
7
+ export { ChronosPeriod } from './period';
8
+ export { ChronosPeriodCollection } from './period-collection';
9
+ export { ChronosTimezone, TIMEZONES, Timezones, type TimezoneId, } from './timezone';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Core classes barrel export
4
+ * @module core
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Timezones = exports.TIMEZONES = exports.ChronosTimezone = exports.ChronosPeriodCollection = exports.ChronosPeriod = exports.ChronosInterval = exports.Chronos = void 0;
8
+ var chronos_1 = require("./chronos");
9
+ Object.defineProperty(exports, "Chronos", { enumerable: true, get: function () { return chronos_1.Chronos; } });
10
+ var interval_1 = require("./interval");
11
+ Object.defineProperty(exports, "ChronosInterval", { enumerable: true, get: function () { return interval_1.ChronosInterval; } });
12
+ var period_1 = require("./period");
13
+ Object.defineProperty(exports, "ChronosPeriod", { enumerable: true, get: function () { return period_1.ChronosPeriod; } });
14
+ var period_collection_1 = require("./period-collection");
15
+ Object.defineProperty(exports, "ChronosPeriodCollection", { enumerable: true, get: function () { return period_collection_1.ChronosPeriodCollection; } });
16
+ var timezone_1 = require("./timezone");
17
+ Object.defineProperty(exports, "ChronosTimezone", { enumerable: true, get: function () { return timezone_1.ChronosTimezone; } });
18
+ Object.defineProperty(exports, "TIMEZONES", { enumerable: true, get: function () { return timezone_1.TIMEZONES; } });
19
+ Object.defineProperty(exports, "Timezones", { enumerable: true, get: function () { return timezone_1.Timezones; } });
@@ -0,0 +1,289 @@
1
+ /**
2
+ * ChronosInterval - Duration/Interval handling
3
+ * @module ChronosInterval
4
+ */
5
+ import { Duration, AnyTimeUnit } from '../types';
6
+ /**
7
+ * ChronosInterval - Represents a duration/interval of time
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Create intervals
12
+ * const interval = ChronosInterval.create({ days: 5, hours: 3 });
13
+ * const hours = ChronosInterval.hours(24);
14
+ * const fromISO = ChronosInterval.fromISO('P1Y2M3D');
15
+ *
16
+ * // Arithmetic
17
+ * const doubled = interval.multiply(2);
18
+ * const combined = interval.add(hours);
19
+ *
20
+ * // Formatting
21
+ * console.log(interval.forHumans()); // "5 days 3 hours"
22
+ * console.log(interval.toISO()); // "P5DT3H"
23
+ * ```
24
+ */
25
+ export declare class ChronosInterval {
26
+ private _years;
27
+ private _months;
28
+ private _weeks;
29
+ private _days;
30
+ private _hours;
31
+ private _minutes;
32
+ private _seconds;
33
+ private _milliseconds;
34
+ private _locale;
35
+ private _inverted;
36
+ private constructor();
37
+ /**
38
+ * Create an interval from a duration object
39
+ */
40
+ static create(duration: Duration): ChronosInterval;
41
+ /**
42
+ * Create an interval from years
43
+ */
44
+ static years(years: number): ChronosInterval;
45
+ /**
46
+ * Create an interval from months
47
+ */
48
+ static months(months: number): ChronosInterval;
49
+ /**
50
+ * Create an interval from weeks
51
+ */
52
+ static weeks(weeks: number): ChronosInterval;
53
+ /**
54
+ * Create an interval from days
55
+ */
56
+ static days(days: number): ChronosInterval;
57
+ /**
58
+ * Create an interval from hours
59
+ */
60
+ static hours(hours: number): ChronosInterval;
61
+ /**
62
+ * Create an interval from minutes
63
+ */
64
+ static minutes(minutes: number): ChronosInterval;
65
+ /**
66
+ * Create an interval from seconds
67
+ */
68
+ static seconds(seconds: number): ChronosInterval;
69
+ /**
70
+ * Create an interval from milliseconds
71
+ */
72
+ static milliseconds(milliseconds: number): ChronosInterval;
73
+ /**
74
+ * Create a single unit interval
75
+ */
76
+ static unit(amount: number, unit: AnyTimeUnit): ChronosInterval;
77
+ /**
78
+ * Create from ISO 8601 duration string (P1Y2M3DT4H5M6S)
79
+ */
80
+ static fromISO(iso: string): ChronosInterval;
81
+ /**
82
+ * Create from a human-readable string
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * ChronosInterval.fromString('2 days 3 hours')
87
+ * ChronosInterval.fromString('1 year, 6 months')
88
+ * ```
89
+ */
90
+ static fromString(input: string): ChronosInterval;
91
+ /**
92
+ * Create a zero-length interval
93
+ */
94
+ static zero(): ChronosInterval;
95
+ /**
96
+ * Create an interval from the difference between two dates
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const start = new Date('2024-01-01');
101
+ * const end = new Date('2024-03-15');
102
+ * const interval = ChronosInterval.between(start, end);
103
+ * ```
104
+ */
105
+ static between(start: Date | {
106
+ toDate(): Date;
107
+ }, end: Date | {
108
+ toDate(): Date;
109
+ }): ChronosInterval;
110
+ get years(): number;
111
+ get months(): number;
112
+ get weeks(): number;
113
+ get days(): number;
114
+ get hours(): number;
115
+ get minutes(): number;
116
+ get seconds(): number;
117
+ get milliseconds(): number;
118
+ get inverted(): boolean;
119
+ /**
120
+ * Get total duration in a specific unit
121
+ */
122
+ total(unit: AnyTimeUnit): number;
123
+ /**
124
+ * Get total duration in milliseconds
125
+ */
126
+ totalMilliseconds(): number;
127
+ /**
128
+ * Get total duration in seconds
129
+ */
130
+ totalSeconds(): number;
131
+ /**
132
+ * Get total duration in minutes
133
+ */
134
+ totalMinutes(): number;
135
+ /**
136
+ * Get total duration in hours
137
+ */
138
+ totalHours(): number;
139
+ /**
140
+ * Get total duration in days
141
+ */
142
+ totalDays(): number;
143
+ /**
144
+ * Get total duration in weeks
145
+ */
146
+ totalWeeks(): number;
147
+ /**
148
+ * Get total duration in months (approximate)
149
+ */
150
+ totalMonths(): number;
151
+ /**
152
+ * Get total duration in years (approximate)
153
+ */
154
+ totalYears(): number;
155
+ /**
156
+ * Add another interval to this one
157
+ */
158
+ add(other: ChronosInterval | Duration): ChronosInterval;
159
+ /**
160
+ * Subtract another interval from this one
161
+ */
162
+ subtract(other: ChronosInterval | Duration): ChronosInterval;
163
+ /**
164
+ * Multiply the interval by a factor
165
+ */
166
+ multiply(factor: number): ChronosInterval;
167
+ /**
168
+ * Divide the interval by a factor
169
+ */
170
+ divide(factor: number): ChronosInterval;
171
+ /**
172
+ * Negate the interval
173
+ */
174
+ negate(): ChronosInterval;
175
+ /**
176
+ * Get absolute value of interval
177
+ */
178
+ abs(): ChronosInterval;
179
+ /**
180
+ * Check if equal to another interval
181
+ */
182
+ equals(other: ChronosInterval): boolean;
183
+ /**
184
+ * Check if greater than another interval
185
+ */
186
+ greaterThan(other: ChronosInterval): boolean;
187
+ /**
188
+ * Check if less than another interval
189
+ */
190
+ lessThan(other: ChronosInterval): boolean;
191
+ /**
192
+ * Check if greater than or equal to another interval
193
+ */
194
+ greaterThanOrEqual(other: ChronosInterval): boolean;
195
+ /**
196
+ * Check if less than or equal to another interval
197
+ */
198
+ lessThanOrEqual(other: ChronosInterval): boolean;
199
+ /**
200
+ * Check if the interval is zero
201
+ */
202
+ isZero(): boolean;
203
+ /**
204
+ * Check if the interval is positive
205
+ */
206
+ isPositive(): boolean;
207
+ /**
208
+ * Check if the interval is negative
209
+ */
210
+ isNegative(): boolean;
211
+ /**
212
+ * Cascade units to proper values (normalize overflow)
213
+ *
214
+ * @example
215
+ * 90 seconds becomes 1 minute 30 seconds
216
+ */
217
+ cascade(): ChronosInterval;
218
+ /**
219
+ * Cascade without including weeks
220
+ */
221
+ cascadeWithoutWeeks(): ChronosInterval;
222
+ /**
223
+ * Format as ISO 8601 duration
224
+ */
225
+ toISO(): string;
226
+ /**
227
+ * Format for human reading
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * interval.forHumans() // "2 days 3 hours"
232
+ * interval.forHumans({ short: true }) // "2d 3h"
233
+ * interval.forHumans({ parts: 2 }) // "2 days 3 hours" (max 2 parts)
234
+ * ```
235
+ */
236
+ forHumans(options?: {
237
+ short?: boolean;
238
+ parts?: number;
239
+ join?: string;
240
+ conjunction?: string;
241
+ }): string;
242
+ /**
243
+ * Format using a format string
244
+ *
245
+ * Tokens:
246
+ * - %y: years
247
+ * - %m: months
248
+ * - %w: weeks
249
+ * - %d: days
250
+ * - %h: hours
251
+ * - %i: minutes
252
+ * - %s: seconds
253
+ * - %f: milliseconds
254
+ * - %R: +/- sign
255
+ * - %r: +/- or empty
256
+ */
257
+ format(formatStr: string): string;
258
+ /**
259
+ * Convert to Duration object
260
+ */
261
+ toDuration(): Duration;
262
+ /**
263
+ * Convert to array
264
+ */
265
+ toArray(): number[];
266
+ /**
267
+ * Clone this interval
268
+ */
269
+ clone(): ChronosInterval;
270
+ /**
271
+ * Set locale for this interval
272
+ */
273
+ locale(code: string): ChronosInterval;
274
+ /**
275
+ * Get primitive value (total milliseconds)
276
+ */
277
+ valueOf(): number;
278
+ /**
279
+ * Convert to string
280
+ */
281
+ toString(): string;
282
+ /**
283
+ * Convert to JSON
284
+ */
285
+ toJSON(): Duration & {
286
+ iso: string;
287
+ };
288
+ }
289
+ export default ChronosInterval;