one-second 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,369 @@
1
+ # one-second
2
+
3
+ > Ultra-lightweight date library using native Intl API - 2KB, zero dependencies, immutable
4
+
5
+ [![npm version](https://img.shields.io/npm/v/one-second.svg)](https://www.npmjs.com/package/one-second)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Why one-second?
9
+
10
+ - **Tiny**: ~3KB minified (vs Moment.js 300KB, Luxon 29KB, Day.js 6KB)
11
+ - **Zero dependencies**: Uses native `Intl.DateTimeFormat` and `Intl.RelativeTimeFormat`
12
+ - **Immutable**: All operations return new Date objects
13
+ - **Tree-shakeable**: Import only what you need
14
+ - **TypeScript**: Full type definitions included
15
+ - **Fast**: Caches formatters for optimal performance
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install one-second
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { format, relative, addDays, isToday } from 'one-second';
27
+
28
+ // Format dates using native Intl
29
+ format(new Date(), { month: 'long', day: 'numeric', year: 'numeric' });
30
+ // → "January 15, 2024"
31
+
32
+ // Relative time
33
+ relative(new Date(Date.now() - 3600000)); // 1 hour ago
34
+ // → "1 hour ago"
35
+
36
+ // Date arithmetic (immutable)
37
+ const tomorrow = addDays(new Date(), 1);
38
+
39
+ // Comparisons
40
+ isToday(new Date()); // → true
41
+ ```
42
+
43
+ ## Comparison with Alternatives
44
+
45
+ | Feature | one-second | Day.js | date-fns | Luxon | Moment.js |
46
+ |---------|-----------|--------|----------|-------|-----------|
47
+ | Size (gzip) | **~3KB** | 6KB | 18KB+ | 29KB | 72KB+ |
48
+ | Dependencies | **0** | 0 | 0 | 0 | 0 |
49
+ | Immutable | **Yes** | Yes | Yes | Yes | No |
50
+ | Tree-shakeable | **Yes** | Plugin | Yes | Partial | No |
51
+ | Native Intl | **Yes** | Partial | Partial | Yes | No |
52
+ | i18n (built-in) | **Yes** | Plugin | Yes | Yes | Plugin |
53
+ | Format strings | **Yes** | Yes | No | No | Yes |
54
+ | Parse w/ format | **Yes** | Plugin | Yes | No | Yes |
55
+ | Duration | **Yes** | Plugin | Yes | Yes | Yes |
56
+ | TypeScript | **Yes** | Yes | Yes | Yes | @types |
57
+ | Zero config | **Yes** | Yes | Yes | Yes | Yes |
58
+
59
+ ## API Reference
60
+
61
+ ### Parsing
62
+
63
+ ```typescript
64
+ import { toDate, isValid, parse } from 'one-second';
65
+
66
+ toDate('2024-01-15'); // Date from string
67
+ toDate(1705276800000); // Date from timestamp
68
+ toDate(new Date()); // Clone date
69
+
70
+ isValid('2024-01-15'); // true
71
+ isValid('invalid'); // false
72
+
73
+ // Parse with custom format (like dayjs/moment)
74
+ parse('2024-06-15', 'YYYY-MM-DD'); // Date
75
+ parse('15/06/2024', 'DD/MM/YYYY'); // Date
76
+ parse('2024-06-15 14:30', 'YYYY-MM-DD HH:mm'); // Date with time
77
+ ```
78
+
79
+ ### Formatting
80
+
81
+ ```typescript
82
+ import { format, formatStr, formatDate, formatDateTime, toISO, toTime } from 'one-second';
83
+
84
+ // Format with template string (like dayjs/moment)
85
+ formatStr(date, 'YYYY-MM-DD'); // "2024-01-15"
86
+ formatStr(date, 'DD/MM/YYYY HH:mm'); // "15/01/2024 10:30"
87
+ formatStr(date, 'MMMM D, YYYY'); // "January 15, 2024"
88
+ formatStr(date, 'ddd, MMM D'); // "Mon, Jan 15"
89
+ formatStr(date, 'hh:mm A'); // "10:30 AM"
90
+
91
+ // Supported tokens: YYYY, YY, MMMM, MMM, MM, M, DD, D, dddd, ddd,
92
+ // HH, H, hh, h, mm, m, ss, s, SSS, A, a
93
+
94
+ // Custom format using Intl options
95
+ format(date, {
96
+ locale: 'en-US',
97
+ weekday: 'long',
98
+ year: 'numeric',
99
+ month: 'long',
100
+ day: 'numeric'
101
+ });
102
+ // → "Monday, January 15, 2024"
103
+
104
+ // Preset formats
105
+ formatDate(date); // "Jan 15, 2024"
106
+ formatDateTime(date); // "Jan 15, 2024, 10:30 AM"
107
+ formatTime(date); // "10:30 AM"
108
+
109
+ // ISO formats
110
+ toISO(date); // "2024-01-15"
111
+ toTime(date); // "10:30:00"
112
+ toISOString(date); // "2024-01-15T10:30:00.000Z"
113
+ ```
114
+
115
+ ### Relative Time
116
+
117
+ ```typescript
118
+ import { relative, timeAgo } from 'one-second';
119
+
120
+ relative(new Date(Date.now() - 60000)); // "1 minute ago"
121
+ relative(new Date(Date.now() + 86400000)); // "in 1 day"
122
+
123
+ // With locale
124
+ relative(date, { locale: 'es' }); // "hace 1 minuto"
125
+ relative(date, { locale: 'zh' }); // "1 分钟前"
126
+
127
+ // Short style
128
+ relative(date, { style: 'short' }); // "1 min. ago"
129
+
130
+ // Convenience function
131
+ timeAgo(date); // "2 hours ago"
132
+ ```
133
+
134
+ ### Date Arithmetic
135
+
136
+ All operations are **immutable** - they return a new Date.
137
+
138
+ ```typescript
139
+ import { add, subtract, addDays, addMonths, subWeeks } from 'one-second';
140
+
141
+ // Generic add/subtract
142
+ add(date, 5, 'day');
143
+ subtract(date, 2, 'hour');
144
+
145
+ // Convenience functions
146
+ addDays(date, 7);
147
+ addMonths(date, 1);
148
+ addYears(date, 1);
149
+ addHours(date, 3);
150
+ addMinutes(date, 30);
151
+
152
+ subDays(date, 7);
153
+ subMonths(date, 1);
154
+ subWeeks(date, 2);
155
+ ```
156
+
157
+ ### Comparisons
158
+
159
+ ```typescript
160
+ import {
161
+ isBefore, isAfter, isBetween,
162
+ isSameDay, isSameMonth, isSameYear,
163
+ isToday, isYesterday, isTomorrow,
164
+ isPast, isFuture
165
+ } from 'one-second';
166
+
167
+ isBefore(date1, date2); // true/false
168
+ isAfter(date1, date2); // true/false
169
+ isBetween(date, start, end); // true/false
170
+
171
+ isSameDay(date1, date2); // true/false
172
+ isSameMonth(date1, date2); // true/false
173
+ isSameYear(date1, date2); // true/false
174
+
175
+ isToday(date); // true/false
176
+ isYesterday(date); // true/false
177
+ isTomorrow(date); // true/false
178
+
179
+ isPast(date); // true/false
180
+ isFuture(date); // true/false
181
+ ```
182
+
183
+ ### Difference
184
+
185
+ ```typescript
186
+ import { diff, diffInDays, diffInHours, diffInMinutes } from 'one-second';
187
+
188
+ // Generic diff
189
+ diff(date1, date2, 'day');
190
+ diff(date1, date2, 'hour');
191
+
192
+ // Convenience functions
193
+ diffInDays(date1, date2);
194
+ diffInHours(date1, date2);
195
+ diffInMinutes(date1, date2);
196
+ diffInMonths(date1, date2);
197
+ diffInYears(date1, date2);
198
+ ```
199
+
200
+ ### Start/End of Period
201
+
202
+ ```typescript
203
+ import { startOf, endOf } from 'one-second';
204
+
205
+ startOf(date, 'day'); // Start of day (00:00:00)
206
+ startOf(date, 'month'); // First day of month
207
+ startOf(date, 'year'); // January 1st
208
+ startOf(date, 'week'); // Sunday of the week
209
+
210
+ endOf(date, 'day'); // End of day (23:59:59.999)
211
+ endOf(date, 'month'); // Last day of month
212
+ endOf(date, 'year'); // December 31st
213
+ ```
214
+
215
+ ### Getters
216
+
217
+ ```typescript
218
+ import {
219
+ getYear, getMonth, getDate, getDay,
220
+ getHours, getMinutes, getSeconds, getTime
221
+ } from 'one-second';
222
+
223
+ getYear(date); // 2024
224
+ getMonth(date); // 0-11 (January = 0)
225
+ getDate(date); // 1-31
226
+ getDay(date); // 0-6 (Sunday = 0)
227
+ getHours(date); // 0-23
228
+ getMinutes(date); // 0-59
229
+ getSeconds(date); // 0-59
230
+ getTime(date); // Unix timestamp
231
+ ```
232
+
233
+ ### Duration
234
+
235
+ ```typescript
236
+ import { duration, durationBetween } from 'one-second';
237
+
238
+ // Create duration from milliseconds
239
+ const dur = duration(3661000); // 1 hour, 1 min, 1 sec
240
+ dur.hours; // 1
241
+ dur.minutes; // 1
242
+ dur.seconds; // 1
243
+
244
+ // Create duration from unit
245
+ const week = duration(1, 'week');
246
+ week.asDays(); // 7
247
+
248
+ // Duration between dates
249
+ const diff = durationBetween(date1, date2);
250
+ diff.humanize(); // "2 days"
251
+
252
+ // Convert to different units
253
+ dur.asMilliseconds(); // 3661000
254
+ dur.asSeconds(); // 3661
255
+ dur.asMinutes(); // 61.01...
256
+ dur.asHours(); // 1.01...
257
+ dur.asDays(); // 0.04...
258
+ ```
259
+
260
+ ### Utilities
261
+
262
+ ```typescript
263
+ import {
264
+ daysInMonth, isLeapYear, dayOfYear, weekOfYear, quarter,
265
+ create, now, today, clone, min, max,
266
+ isWeekend, isWeekday, dayName, monthName
267
+ } from 'one-second';
268
+
269
+ daysInMonth(date); // 28, 29, 30, or 31
270
+ isLeapYear(date); // true/false
271
+ dayOfYear(date); // 1-366
272
+ weekOfYear(date); // 1-53
273
+ quarter(date); // 1-4
274
+
275
+ create(2024, 0, 15); // January 15, 2024
276
+ now(); // Current timestamp
277
+ today(); // Start of today
278
+ clone(date); // Clone a date
279
+
280
+ min(date1, date2, date3); // Earliest date
281
+ max(date1, date2, date3); // Latest date
282
+
283
+ isWeekend(date); // true if Sat/Sun
284
+ isWeekday(date); // true if Mon-Fri
285
+ dayName(date); // "Monday"
286
+ monthName(date); // "January"
287
+ ```
288
+
289
+ ## Internationalization
290
+
291
+ one-second uses native `Intl` APIs, so all locales supported by your environment work automatically:
292
+
293
+ ```typescript
294
+ import { format, relative } from 'one-second';
295
+
296
+ // Format in different locales
297
+ format(date, { locale: 'ja-JP', dateStyle: 'full' });
298
+ // → "2024年1月15日月曜日"
299
+
300
+ format(date, { locale: 'de-DE', dateStyle: 'long' });
301
+ // → "15. Januar 2024"
302
+
303
+ // Relative time in different locales
304
+ relative(date, { locale: 'fr' }); // "il y a 2 heures"
305
+ relative(date, { locale: 'ko' }); // "2시간 전"
306
+ ```
307
+
308
+ **No locale files needed!** Intl uses the operating system's locale data.
309
+
310
+ ## Performance
311
+
312
+ one-second caches `Intl.DateTimeFormat` and `Intl.RelativeTimeFormat` instances for optimal performance:
313
+
314
+ ```typescript
315
+ // Formatting 1000 dates:
316
+ // toLocaleDateString(): ~217ms (creates new formatter each time)
317
+ // one-second format(): ~4ms (reuses cached formatter)
318
+ ```
319
+
320
+ ## Migration from Moment.js
321
+
322
+ ```typescript
323
+ // Moment.js // one-second
324
+ moment() // new Date()
325
+ moment('2024-01-15') // toDate('2024-01-15')
326
+ moment().format('YYYY-MM-DD') // toISO(new Date())
327
+ moment().add(7, 'days') // addDays(new Date(), 7)
328
+ moment().subtract(1, 'month') // subMonths(new Date(), 1)
329
+ moment().fromNow() // timeAgo(new Date())
330
+ moment().isBefore(other) // isBefore(date, other)
331
+ moment().startOf('day') // startOf(date, 'day')
332
+ moment().diff(other, 'days') // diffInDays(date, other)
333
+ ```
334
+
335
+ ## Migration from Day.js
336
+
337
+ ```typescript
338
+ // Day.js // one-second
339
+ dayjs() // new Date()
340
+ dayjs().format('YYYY-MM-DD') // toISO(new Date())
341
+ dayjs().add(7, 'day') // addDays(new Date(), 7)
342
+ dayjs().fromNow() // timeAgo(new Date())
343
+ dayjs().isBefore(other) // isBefore(date, other)
344
+ ```
345
+
346
+ ## Browser Support
347
+
348
+ Works in all modern browsers and Node.js 18+. Uses:
349
+ - `Intl.DateTimeFormat` (96%+ browser support)
350
+ - `Intl.RelativeTimeFormat` (94%+ browser support)
351
+
352
+ ## Support
353
+
354
+ This project is maintained in my free time. If it saved you some kilobytes and made your dates easier to handle, I'd really appreciate your support:
355
+
356
+ - ⭐ Star the repo—it helps others discover this tool
357
+ - 📢 Share with your team or on social media
358
+ - 🐛 [Report bugs or suggest features](https://github.com/willzhangfly/one-second/issues)
359
+ - ☕ [Buy me a coffee](https://buymeacoffee.com/willzhangfly) if you'd like to support development
360
+
361
+ Thank you to everyone who has contributed, shared feedback, or helped spread the word!
362
+
363
+ ## License
364
+
365
+ MIT
366
+
367
+ ---
368
+
369
+ **Made with care for smaller bundles and simpler dates**
@@ -0,0 +1,257 @@
1
+ /**
2
+ * date-lite - Ultra-lightweight date library using native Intl API
3
+ * Zero dependencies, ~2KB, immutable, tree-shakeable
4
+ */
5
+ export type DateInput = Date | string | number;
6
+ export interface FormatOptions {
7
+ locale?: string;
8
+ weekday?: 'long' | 'short' | 'narrow';
9
+ year?: 'numeric' | '2-digit';
10
+ month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
11
+ day?: 'numeric' | '2-digit';
12
+ hour?: 'numeric' | '2-digit';
13
+ minute?: 'numeric' | '2-digit';
14
+ second?: 'numeric' | '2-digit';
15
+ hour12?: boolean;
16
+ timeZone?: string;
17
+ }
18
+ export interface RelativeTimeOptions {
19
+ locale?: string;
20
+ style?: 'long' | 'short' | 'narrow';
21
+ numeric?: 'always' | 'auto';
22
+ }
23
+ export type Unit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
24
+ /**
25
+ * Convert any input to a Date object
26
+ */
27
+ export declare function toDate(input: DateInput): Date;
28
+ /**
29
+ * Check if input is a valid date
30
+ */
31
+ export declare function isValid(input: DateInput): boolean;
32
+ /**
33
+ * Format date using Intl.DateTimeFormat
34
+ */
35
+ export declare function format(input: DateInput, options?: FormatOptions): string;
36
+ /**
37
+ * Format date to ISO string (YYYY-MM-DD)
38
+ */
39
+ export declare function toISO(input: DateInput): string;
40
+ /**
41
+ * Format time to HH:MM:SS
42
+ */
43
+ export declare function toTime(input: DateInput): string;
44
+ /**
45
+ * Format to full ISO datetime string
46
+ */
47
+ export declare function toISOString(input: DateInput): string;
48
+ /**
49
+ * Format date using format string (like dayjs/moment)
50
+ * Tokens: YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s, SSS, ddd, dddd, MMM, MMMM, A, a
51
+ */
52
+ export declare function formatStr(input: DateInput, template: string, locale?: string): string;
53
+ /**
54
+ * Parse date from string with format
55
+ * Tokens: YYYY, MM, DD, HH, mm, ss
56
+ */
57
+ export declare function parse(dateStr: string, template: string): Date;
58
+ export declare function formatDate(input: DateInput, locale?: string): string;
59
+ export declare function formatDateTime(input: DateInput, locale?: string): string;
60
+ export declare function formatTime(input: DateInput, locale?: string): string;
61
+ /**
62
+ * Get relative time string (e.g., "2 hours ago", "in 3 days")
63
+ */
64
+ export declare function relative(input: DateInput, options?: RelativeTimeOptions): string;
65
+ /**
66
+ * Get human-readable time ago string
67
+ */
68
+ export declare function timeAgo(input: DateInput, locale?: string): string;
69
+ /**
70
+ * Add time to a date (returns new Date)
71
+ */
72
+ export declare function add(input: DateInput, amount: number, unit: Unit): Date;
73
+ /**
74
+ * Subtract time from a date (returns new Date)
75
+ */
76
+ export declare function subtract(input: DateInput, amount: number, unit: Unit): Date;
77
+ export declare const addYears: (input: DateInput, n: number) => Date;
78
+ export declare const addMonths: (input: DateInput, n: number) => Date;
79
+ export declare const addWeeks: (input: DateInput, n: number) => Date;
80
+ export declare const addDays: (input: DateInput, n: number) => Date;
81
+ export declare const addHours: (input: DateInput, n: number) => Date;
82
+ export declare const addMinutes: (input: DateInput, n: number) => Date;
83
+ export declare const addSeconds: (input: DateInput, n: number) => Date;
84
+ export declare const subYears: (input: DateInput, n: number) => Date;
85
+ export declare const subMonths: (input: DateInput, n: number) => Date;
86
+ export declare const subWeeks: (input: DateInput, n: number) => Date;
87
+ export declare const subDays: (input: DateInput, n: number) => Date;
88
+ export declare const subHours: (input: DateInput, n: number) => Date;
89
+ export declare const subMinutes: (input: DateInput, n: number) => Date;
90
+ export declare const subSeconds: (input: DateInput, n: number) => Date;
91
+ /**
92
+ * Check if two dates are the same day
93
+ */
94
+ export declare function isSameDay(a: DateInput, b: DateInput): boolean;
95
+ /**
96
+ * Check if two dates are the same month
97
+ */
98
+ export declare function isSameMonth(a: DateInput, b: DateInput): boolean;
99
+ /**
100
+ * Check if two dates are the same year
101
+ */
102
+ export declare function isSameYear(a: DateInput, b: DateInput): boolean;
103
+ /**
104
+ * Check if date is before another
105
+ */
106
+ export declare function isBefore(a: DateInput, b: DateInput): boolean;
107
+ /**
108
+ * Check if date is after another
109
+ */
110
+ export declare function isAfter(a: DateInput, b: DateInput): boolean;
111
+ /**
112
+ * Check if date is between two dates
113
+ */
114
+ export declare function isBetween(input: DateInput, start: DateInput, end: DateInput): boolean;
115
+ /**
116
+ * Check if date is today
117
+ */
118
+ export declare function isToday(input: DateInput): boolean;
119
+ /**
120
+ * Check if date is yesterday
121
+ */
122
+ export declare function isYesterday(input: DateInput): boolean;
123
+ /**
124
+ * Check if date is tomorrow
125
+ */
126
+ export declare function isTomorrow(input: DateInput): boolean;
127
+ /**
128
+ * Check if date is in the past
129
+ */
130
+ export declare function isPast(input: DateInput): boolean;
131
+ /**
132
+ * Check if date is in the future
133
+ */
134
+ export declare function isFuture(input: DateInput): boolean;
135
+ /**
136
+ * Get difference between two dates in specified unit
137
+ */
138
+ export declare function diff(a: DateInput, b: DateInput, unit: Unit): number;
139
+ export declare const diffInYears: (a: DateInput, b: DateInput) => number;
140
+ export declare const diffInMonths: (a: DateInput, b: DateInput) => number;
141
+ export declare const diffInWeeks: (a: DateInput, b: DateInput) => number;
142
+ export declare const diffInDays: (a: DateInput, b: DateInput) => number;
143
+ export declare const diffInHours: (a: DateInput, b: DateInput) => number;
144
+ export declare const diffInMinutes: (a: DateInput, b: DateInput) => number;
145
+ export declare const diffInSeconds: (a: DateInput, b: DateInput) => number;
146
+ export declare const getYear: (input: DateInput) => number;
147
+ export declare const getMonth: (input: DateInput) => number;
148
+ export declare const getDate: (input: DateInput) => number;
149
+ export declare const getDay: (input: DateInput) => number;
150
+ export declare const getHours: (input: DateInput) => number;
151
+ export declare const getMinutes: (input: DateInput) => number;
152
+ export declare const getSeconds: (input: DateInput) => number;
153
+ export declare const getMilliseconds: (input: DateInput) => number;
154
+ export declare const getTime: (input: DateInput) => number;
155
+ /**
156
+ * Get start of a time period
157
+ */
158
+ export declare function startOf(input: DateInput, unit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute'): Date;
159
+ /**
160
+ * Get end of a time period
161
+ */
162
+ export declare function endOf(input: DateInput, unit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute'): Date;
163
+ /**
164
+ * Get days in month
165
+ */
166
+ export declare function daysInMonth(input: DateInput): number;
167
+ /**
168
+ * Check if year is a leap year
169
+ */
170
+ export declare function isLeapYear(input: DateInput): boolean;
171
+ /**
172
+ * Get day of year (1-366)
173
+ */
174
+ export declare function dayOfYear(input: DateInput): number;
175
+ /**
176
+ * Get week of year
177
+ */
178
+ export declare function weekOfYear(input: DateInput): number;
179
+ /**
180
+ * Get quarter (1-4)
181
+ */
182
+ export declare function quarter(input: DateInput): number;
183
+ /**
184
+ * Create a date from components
185
+ */
186
+ export declare function create(year: number, month?: number, day?: number, hour?: number, minute?: number, second?: number, ms?: number): Date;
187
+ /**
188
+ * Get current timestamp
189
+ */
190
+ export declare function now(): number;
191
+ /**
192
+ * Get current date (start of today)
193
+ */
194
+ export declare function today(): Date;
195
+ /**
196
+ * Clone a date
197
+ */
198
+ export declare function clone(input: DateInput): Date;
199
+ /**
200
+ * Get min date from array
201
+ */
202
+ export declare function min(...dates: DateInput[]): Date;
203
+ /**
204
+ * Get max date from array
205
+ */
206
+ export declare function max(...dates: DateInput[]): Date;
207
+ export interface Duration {
208
+ years: number;
209
+ months: number;
210
+ weeks: number;
211
+ days: number;
212
+ hours: number;
213
+ minutes: number;
214
+ seconds: number;
215
+ milliseconds: number;
216
+ asMilliseconds: () => number;
217
+ asSeconds: () => number;
218
+ asMinutes: () => number;
219
+ asHours: () => number;
220
+ asDays: () => number;
221
+ asWeeks: () => number;
222
+ humanize: (locale?: string) => string;
223
+ }
224
+ /**
225
+ * Create a duration from milliseconds
226
+ */
227
+ export declare function duration(ms: number): Duration;
228
+ export declare function duration(amount: number, unit: Unit): Duration;
229
+ /**
230
+ * Get duration between two dates
231
+ */
232
+ export declare function durationBetween(a: DateInput, b: DateInput): Duration;
233
+ /**
234
+ * Create a UTC date
235
+ */
236
+ export declare function utc(input?: DateInput): Date;
237
+ /**
238
+ * Get UTC offset in minutes
239
+ */
240
+ export declare function utcOffset(input: DateInput): number;
241
+ /**
242
+ * Check if date is a weekend (Saturday or Sunday)
243
+ */
244
+ export declare function isWeekend(input: DateInput): boolean;
245
+ /**
246
+ * Check if date is a weekday (Monday-Friday)
247
+ */
248
+ export declare function isWeekday(input: DateInput): boolean;
249
+ /**
250
+ * Get the name of the day
251
+ */
252
+ export declare function dayName(input: DateInput, locale?: string, style?: 'long' | 'short' | 'narrow'): string;
253
+ /**
254
+ * Get the name of the month
255
+ */
256
+ export declare function monthName(input: DateInput, locale?: string, style?: 'long' | 'short' | 'narrow'): string;
257
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG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