chronal 0.0.4 → 0.0.6
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/README.md +23 -23
- package/esm/chainable/chronal.d.ts +12 -6
- package/esm/chainable/chronal.d.ts.map +1 -1
- package/esm/chainable/chronal.js +20 -32
- package/esm/chainable/{date-range.d.ts → dates-until.d.ts} +6 -6
- package/esm/chainable/dates-until.d.ts.map +1 -0
- package/esm/chainable/{date-range.js → dates-until.js} +6 -6
- package/esm/chainable/end-of.d.ts +3 -3
- package/esm/chainable/end-of.d.ts.map +1 -1
- package/esm/chainable/end-of.js +10 -5
- package/esm/chainable/start-of.d.ts +3 -3
- package/esm/chainable/start-of.d.ts.map +1 -1
- package/esm/chainable/start-of.js +10 -5
- package/{script/chainable/sub-time.d.ts → esm/chainable/subtract.d.ts} +4 -4
- package/esm/chainable/subtract.d.ts.map +1 -0
- package/esm/chainable/{sub-time.js → subtract.js} +4 -4
- package/esm/lib/config.d.ts +1 -1
- package/esm/lib/config.d.ts.map +1 -1
- package/esm/lib/config.js +1 -1
- package/{script/lib/date-range.d.ts → esm/lib/dates-until.d.ts} +5 -5
- package/esm/lib/dates-until.d.ts.map +1 -0
- package/esm/lib/{date-range.js → dates-until.js} +4 -4
- package/esm/lib/parse-date.d.ts +12 -5
- package/esm/lib/parse-date.d.ts.map +1 -1
- package/esm/lib/parse-date.js +59 -5
- package/esm/lib/{sub-time.d.ts → subtract.d.ts} +3 -3
- package/esm/lib/{sub-time.d.ts.map → subtract.d.ts.map} +1 -1
- package/esm/lib/{sub-time.js → subtract.js} +2 -2
- package/esm/mod.d.ts +3 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +3 -3
- package/package.json +1 -1
- package/script/chainable/chronal.d.ts +12 -6
- package/script/chainable/chronal.d.ts.map +1 -1
- package/script/chainable/chronal.js +20 -32
- package/script/chainable/{date-range.d.ts → dates-until.d.ts} +6 -6
- package/script/chainable/dates-until.d.ts.map +1 -0
- package/script/chainable/{date-range.js → dates-until.js} +7 -7
- package/script/chainable/end-of.d.ts +3 -3
- package/script/chainable/end-of.d.ts.map +1 -1
- package/script/chainable/end-of.js +10 -5
- package/script/chainable/start-of.d.ts +3 -3
- package/script/chainable/start-of.d.ts.map +1 -1
- package/script/chainable/start-of.js +10 -5
- package/{esm/chainable/sub-time.d.ts → script/chainable/subtract.d.ts} +4 -4
- package/script/chainable/subtract.d.ts.map +1 -0
- package/script/chainable/{sub-time.js → subtract.js} +5 -5
- package/script/lib/config.d.ts +1 -1
- package/script/lib/config.d.ts.map +1 -1
- package/script/lib/config.js +2 -2
- package/{esm/lib/date-range.d.ts → script/lib/dates-until.d.ts} +5 -5
- package/script/lib/dates-until.d.ts.map +1 -0
- package/script/lib/{date-range.js → dates-until.js} +5 -5
- package/script/lib/parse-date.d.ts +12 -5
- package/script/lib/parse-date.d.ts.map +1 -1
- package/script/lib/parse-date.js +59 -5
- package/script/lib/{sub-time.d.ts → subtract.d.ts} +3 -3
- package/script/lib/{sub-time.d.ts.map → subtract.d.ts.map} +1 -1
- package/script/lib/{sub-time.js → subtract.js} +3 -3
- package/script/mod.d.ts +3 -3
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +6 -6
- package/esm/chainable/date-range.d.ts.map +0 -1
- package/esm/chainable/sub-time.d.ts.map +0 -1
- package/esm/lib/date-range.d.ts.map +0 -1
- package/script/chainable/date-range.d.ts.map +0 -1
- package/script/chainable/sub-time.d.ts.map +0 -1
- package/script/lib/date-range.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ npm install chronal
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
```javascript
|
|
62
|
-
import { addTime, formatDate,
|
|
62
|
+
import { addTime, formatDate, subtract } from "chronal";
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
## Quick Start
|
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
isToday,
|
|
80
80
|
parseDate,
|
|
81
81
|
startOf,
|
|
82
|
-
|
|
82
|
+
subtract,
|
|
83
83
|
} from "chronal";
|
|
84
84
|
|
|
85
85
|
const date = new Date("2024-06-15T14:35:22Z");
|
|
@@ -94,7 +94,7 @@ parseDate("15/06/2024", "DD/MM/YYYY"); // Date object for June 15, 2024
|
|
|
94
94
|
|
|
95
95
|
// Add/subtract time
|
|
96
96
|
addTime(date, { days: 5, hours: 2 }); // 2024-06-20T16:35:22Z
|
|
97
|
-
|
|
97
|
+
subtract(date, { months: 1, days: 10 }); // 2024-05-05T14:35:22Z
|
|
98
98
|
|
|
99
99
|
// Start/End of period
|
|
100
100
|
startOf(date, "month"); // 2024-06-01T00:00:00.000Z
|
|
@@ -107,7 +107,7 @@ fromNow(new Date(Date.now() - 300000)); // "5 minutes ago"
|
|
|
107
107
|
isToday(new Date()); // true
|
|
108
108
|
|
|
109
109
|
// Generate date ranges
|
|
110
|
-
|
|
110
|
+
datesUntil(new Date("2024-01-01"), new Date("2024-01-05"));
|
|
111
111
|
// [2024-01-01, 2024-01-02, 2024-01-03, 2024-01-04, 2024-01-05]
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -129,7 +129,7 @@ console.log(date); // "2024-07-01"
|
|
|
129
129
|
// All methods available
|
|
130
130
|
const result = chronal("2024-01-15")
|
|
131
131
|
.add({ days: 10 })
|
|
132
|
-
.
|
|
132
|
+
.subtract({ hours: 2 })
|
|
133
133
|
.format("MMMM DD, YYYY"); // "January 25, 2024"
|
|
134
134
|
|
|
135
135
|
// Query methods
|
|
@@ -144,7 +144,7 @@ chronal("2024-06-15").daysInMonth(); // 30
|
|
|
144
144
|
|
|
145
145
|
// Generate date ranges
|
|
146
146
|
chronal("2024-01-01")
|
|
147
|
-
.
|
|
147
|
+
.until(new Date("2024-01-31"), { weeks: 1 })
|
|
148
148
|
.map((c) => c.format("YYYY-MM-DD"));
|
|
149
149
|
// ["2024-01-01", "2024-01-08", "2024-01-15", "2024-01-22", "2024-01-29"]
|
|
150
150
|
```
|
|
@@ -157,7 +157,7 @@ chronal("2024-01-01")
|
|
|
157
157
|
|
|
158
158
|
## Configuration
|
|
159
159
|
|
|
160
|
-
### `
|
|
160
|
+
### `setChronalConfig(config)`
|
|
161
161
|
|
|
162
162
|
Set the default configuration for all date operations.
|
|
163
163
|
|
|
@@ -169,18 +169,18 @@ Set the default configuration for all date operations.
|
|
|
169
169
|
**Example:**
|
|
170
170
|
|
|
171
171
|
```typescript
|
|
172
|
-
import { formatDate, months,
|
|
172
|
+
import { formatDate, months, setChronalConfig } from "chronal";
|
|
173
173
|
|
|
174
174
|
// Default is 'en-US' and 'UTC'
|
|
175
175
|
formatDate(new Date("2024-06-15"), "MMMM"); // 'June'
|
|
176
176
|
|
|
177
177
|
// Change default locale
|
|
178
|
-
|
|
178
|
+
setChronalConfig({ locale: "pt-BR" });
|
|
179
179
|
formatDate(new Date("2024-06-15"), "MMMM"); // 'junho'
|
|
180
180
|
months(); // ['janeiro', 'fevereiro', 'março', ...]
|
|
181
181
|
|
|
182
182
|
// Change default timezone
|
|
183
|
-
|
|
183
|
+
setChronalConfig({ timezone: "America/Sao_Paulo" });
|
|
184
184
|
|
|
185
185
|
// You can still override per call
|
|
186
186
|
formatDate(new Date("2024-06-15"), "MMMM", { locale: "fr-FR" }); // 'juin'
|
|
@@ -210,7 +210,7 @@ All chainable methods correspond to functional API functions:
|
|
|
210
210
|
| Chainable Method | Functional API | Description |
|
|
211
211
|
| ------------------------- | ------------------------------------- | ------------------------ |
|
|
212
212
|
| `.add(options)` | `addTime(date, options)` | Add time units |
|
|
213
|
-
| `.subtract(options)` | `
|
|
213
|
+
| `.subtract(options)` | `subtract(date, options)` | Subtract time units |
|
|
214
214
|
| `.startOf(unit)` | `startOf(date, unit)` | Start of time unit |
|
|
215
215
|
| `.endOf(unit)` | `endOf(date, unit)` | End of time unit |
|
|
216
216
|
| `.set(options)` | `setUnit(date, options)` | Set specific units |
|
|
@@ -233,7 +233,7 @@ All chainable methods correspond to functional API functions:
|
|
|
233
233
|
| `.quarter()` | `getQuarter(date)` | Get quarter (1-4) |
|
|
234
234
|
| `.daysInMonth()` | `daysInMonth(date)` | Days in month |
|
|
235
235
|
| `.week()` | `weekOfYear(date)` | Week of year |
|
|
236
|
-
| `.
|
|
236
|
+
| `.until(end, step?)` | `datesUntil(start, end, step?)` | Generate date array |
|
|
237
237
|
|
|
238
238
|
**Example:**
|
|
239
239
|
|
|
@@ -379,7 +379,7 @@ addTime(date, { months: 1 }); // 2024-02-29T12:00:00.000Z (handles leap year)
|
|
|
379
379
|
addTime(date, { years: 1, months: 2, days: 3 }); // 2025-04-03T12:00:00.000Z
|
|
380
380
|
```
|
|
381
381
|
|
|
382
|
-
#### `
|
|
382
|
+
#### `subtract(date, options)`
|
|
383
383
|
|
|
384
384
|
Subtracts specified time units from a date.
|
|
385
385
|
|
|
@@ -390,8 +390,8 @@ Subtracts specified time units from a date.
|
|
|
390
390
|
```typescript
|
|
391
391
|
const date = new Date("2024-03-31T12:00:00Z");
|
|
392
392
|
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
subtract(date, { days: 5 }); // 2024-03-26T12:00:00.000Z
|
|
394
|
+
subtract(date, { months: 1 }); // 2024-02-29T12:00:00.000Z (handles month overflow)
|
|
395
395
|
```
|
|
396
396
|
|
|
397
397
|
#### `getUnit(date, unit)`
|
|
@@ -682,7 +682,7 @@ clampDate(new Date("2024-05-15"), min, max); // June 1 (clamped to min)
|
|
|
682
682
|
clampDate(new Date("2024-07-15"), min, max); // June 30 (clamped to max)
|
|
683
683
|
```
|
|
684
684
|
|
|
685
|
-
#### `
|
|
685
|
+
#### `datesUntil(start, end, step?)`
|
|
686
686
|
|
|
687
687
|
Generates an array of dates between start and end dates with a specified step.
|
|
688
688
|
|
|
@@ -709,29 +709,29 @@ const start = new Date("2024-01-01");
|
|
|
709
709
|
const end = new Date("2024-01-05");
|
|
710
710
|
|
|
711
711
|
// Daily range (default)
|
|
712
|
-
|
|
712
|
+
datesUntil(start, end);
|
|
713
713
|
// [2024-01-01, 2024-01-02, 2024-01-03, 2024-01-04, 2024-01-05]
|
|
714
714
|
|
|
715
|
-
// Chainable: chronal("2024-01-01").
|
|
715
|
+
// Chainable: chronal("2024-01-01").until(new Date("2024-01-05"))
|
|
716
716
|
|
|
717
717
|
// Weekly range
|
|
718
718
|
const weekEnd = new Date("2024-01-31");
|
|
719
|
-
|
|
719
|
+
datesUntil(start, weekEnd, { weeks: 1 });
|
|
720
720
|
// [2024-01-01, 2024-01-08, 2024-01-15, 2024-01-22, 2024-01-29]
|
|
721
721
|
|
|
722
|
-
// Chainable: chronal(start).
|
|
722
|
+
// Chainable: chronal(start).until(weekEnd, { weeks: 1 })
|
|
723
723
|
|
|
724
724
|
// Monthly range
|
|
725
725
|
const monthEnd = new Date("2024-06-15");
|
|
726
|
-
|
|
726
|
+
datesUntil(new Date("2024-01-15"), monthEnd, { months: 1 });
|
|
727
727
|
// [2024-01-15, 2024-02-15, 2024-03-15, 2024-04-15, 2024-05-15, 2024-06-15]
|
|
728
728
|
|
|
729
729
|
// Every 3 days
|
|
730
|
-
|
|
730
|
+
datesUntil(start, new Date("2024-01-10"), { days: 3 });
|
|
731
731
|
// [2024-01-01, 2024-01-04, 2024-01-07, 2024-01-10]
|
|
732
732
|
|
|
733
733
|
// Hourly range
|
|
734
|
-
|
|
734
|
+
datesUntil(
|
|
735
735
|
new Date("2024-01-01T09:00:00Z"),
|
|
736
736
|
new Date("2024-01-01T17:00:00Z"),
|
|
737
737
|
{ hours: 2 },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { add } from "./add.js";
|
|
2
|
-
import {
|
|
2
|
+
import { subtract } from "./subtract.js";
|
|
3
3
|
import { format } from "./format.js";
|
|
4
4
|
import { startOf } from "./start-of.js";
|
|
5
5
|
import { endOf } from "./end-of.js";
|
|
@@ -22,7 +22,8 @@ import { getQuarter } from "./get-quarter.js";
|
|
|
22
22
|
import { daysInMonth } from "./days-in-month.js";
|
|
23
23
|
import { weekOfYear } from "./week-of-year.js";
|
|
24
24
|
import { clamp } from "./clamp.js";
|
|
25
|
-
import {
|
|
25
|
+
import { until } from "./dates-until.js";
|
|
26
|
+
import { setChronalConfig } from "../lib/config.js";
|
|
26
27
|
/**
|
|
27
28
|
* Chronal object that wraps a Date and provides chainable date manipulation methods.
|
|
28
29
|
* Similar to Day.js API but built on native Date objects with immutable operations.
|
|
@@ -33,7 +34,7 @@ export type Chronal = {
|
|
|
33
34
|
/** Adds time units to this date */
|
|
34
35
|
add: typeof add;
|
|
35
36
|
/** Subtracts time units from this date */
|
|
36
|
-
|
|
37
|
+
subtract: typeof subtract;
|
|
37
38
|
/** Returns the start of a time unit */
|
|
38
39
|
startOf: typeof startOf;
|
|
39
40
|
/** Returns the end of a time unit */
|
|
@@ -79,7 +80,7 @@ export type Chronal = {
|
|
|
79
80
|
/** Gets the week number of the year */
|
|
80
81
|
week: typeof weekOfYear;
|
|
81
82
|
/** Generates an array of dates between this date and end date */
|
|
82
|
-
|
|
83
|
+
until: typeof until;
|
|
83
84
|
};
|
|
84
85
|
/**
|
|
85
86
|
* Creates a Chronal object with chainable date manipulation methods.
|
|
@@ -96,7 +97,7 @@ export type Chronal = {
|
|
|
96
97
|
* // Create from Date
|
|
97
98
|
* const c = chronal(new Date('2024-06-15'));
|
|
98
99
|
*
|
|
99
|
-
* // Create from string
|
|
100
|
+
* // Create from string (respects config.timezone)
|
|
100
101
|
* const c2 = chronal('2024-06-15T12:00:00Z');
|
|
101
102
|
*
|
|
102
103
|
* // Chain operations
|
|
@@ -106,5 +107,10 @@ export type Chronal = {
|
|
|
106
107
|
* .format('YYYY-MM-DD'); // '2024-03-25'
|
|
107
108
|
* ```
|
|
108
109
|
*/
|
|
109
|
-
|
|
110
|
+
type ChronalFactory = {
|
|
111
|
+
(date?: Date | string | number | null): Chronal;
|
|
112
|
+
config: typeof setChronalConfig;
|
|
113
|
+
};
|
|
114
|
+
export declare const chronal: ChronalFactory;
|
|
115
|
+
export {};
|
|
110
116
|
//# sourceMappingURL=chronal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chronal.d.ts","sourceRoot":"","sources":["../../src/chainable/chronal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"chronal.d.ts","sourceRoot":"","sources":["../../src/chainable/chronal.ts"],"names":[],"mappings":"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"}
|
package/esm/chainable/chronal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { add } from "./add.js";
|
|
2
|
-
import {
|
|
2
|
+
import { subtract } from "./subtract.js";
|
|
3
3
|
import { format } from "./format.js";
|
|
4
4
|
import { startOf } from "./start-of.js";
|
|
5
5
|
import { endOf } from "./end-of.js";
|
|
@@ -22,42 +22,29 @@ import { getQuarter } from "./get-quarter.js";
|
|
|
22
22
|
import { daysInMonth } from "./days-in-month.js";
|
|
23
23
|
import { weekOfYear } from "./week-of-year.js";
|
|
24
24
|
import { clamp } from "./clamp.js";
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* All methods return new instances, preserving immutability.
|
|
29
|
-
*
|
|
30
|
-
* @param date - Optional Date, string, or timestamp. Defaults to current date/time
|
|
31
|
-
* @returns A Chronal object with the date and chainable methods
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* // Create from current time
|
|
36
|
-
* const now = chronal();
|
|
37
|
-
*
|
|
38
|
-
* // Create from Date
|
|
39
|
-
* const c = chronal(new Date('2024-06-15'));
|
|
40
|
-
*
|
|
41
|
-
* // Create from string
|
|
42
|
-
* const c2 = chronal('2024-06-15T12:00:00Z');
|
|
43
|
-
*
|
|
44
|
-
* // Chain operations
|
|
45
|
-
* chronal('2024-01-15')
|
|
46
|
-
* .add({ months: 2, days: 10 })
|
|
47
|
-
* .startOf('day')
|
|
48
|
-
* .format('YYYY-MM-DD'); // '2024-03-25'
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
25
|
+
import { until } from "./dates-until.js";
|
|
26
|
+
import { parseDate } from "../lib/parse-date.js";
|
|
27
|
+
import { setChronalConfig } from "../lib/config.js";
|
|
51
28
|
export const chronal = (date) => {
|
|
52
|
-
|
|
29
|
+
let d;
|
|
30
|
+
if (date === null || date === undefined) {
|
|
31
|
+
d = new Date();
|
|
32
|
+
}
|
|
33
|
+
else if (typeof date === "string") {
|
|
34
|
+
// Parse string with timezone awareness from config
|
|
35
|
+
d = parseDate(date);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
d = new Date(date);
|
|
39
|
+
}
|
|
53
40
|
return {
|
|
54
41
|
date: d,
|
|
55
42
|
// Manipulation
|
|
56
43
|
add: function (opt) {
|
|
57
44
|
return add.call(this, opt);
|
|
58
45
|
},
|
|
59
|
-
|
|
60
|
-
return
|
|
46
|
+
subtract: function (opt) {
|
|
47
|
+
return subtract.call(this, opt);
|
|
61
48
|
},
|
|
62
49
|
startOf: function (unit) {
|
|
63
50
|
return startOf.call(this, unit);
|
|
@@ -129,8 +116,9 @@ export const chronal = (date) => {
|
|
|
129
116
|
return weekOfYear.call(this);
|
|
130
117
|
},
|
|
131
118
|
// Utilities
|
|
132
|
-
|
|
133
|
-
return
|
|
119
|
+
until: function (end, step) {
|
|
120
|
+
return until.call(this, end, step);
|
|
134
121
|
},
|
|
135
122
|
};
|
|
136
123
|
};
|
|
124
|
+
chronal.config = setChronalConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { datesUntil as _datesUntil } from "../lib/dates-until.js";
|
|
2
2
|
import { type Chronal } from "./chronal.js";
|
|
3
3
|
/**
|
|
4
4
|
* Generates an array of Chronal objects between this date and an end date with a specified step.
|
|
@@ -12,12 +12,12 @@ import { type Chronal } from "./chronal.js";
|
|
|
12
12
|
* const start = chronal("2024-01-01");
|
|
13
13
|
* const end = new Date("2024-01-05");
|
|
14
14
|
*
|
|
15
|
-
* start.
|
|
16
|
-
* start.
|
|
15
|
+
* start.until(end); // Array of 5 Chronal objects (Jan 1-5)
|
|
16
|
+
* start.until(end, { days: 2 }); // Array of 3 Chronal objects (Jan 1, 3, 5)
|
|
17
17
|
*
|
|
18
18
|
* // Weekly range
|
|
19
|
-
* chronal("2024-01-01").
|
|
19
|
+
* chronal("2024-01-01").until(new Date("2024-01-31"), { weeks: 1 });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export declare function
|
|
23
|
-
//# sourceMappingURL=
|
|
22
|
+
export declare function until(this: Chronal, end: Date | Chronal, step?: Parameters<typeof _datesUntil>[2]): Chronal[];
|
|
23
|
+
//# sourceMappingURL=dates-until.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates-until.d.ts","sourceRoot":"","sources":["../../src/chainable/dates-until.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;AAErD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,IAAI,GAAG,OAAO,EACnB,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,GACvC,OAAO,EAAE,CAIX"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { datesUntil as _datesUntil } from "../lib/dates-until.js";
|
|
2
2
|
import { chronal } from "./chronal.js";
|
|
3
3
|
/**
|
|
4
4
|
* Generates an array of Chronal objects between this date and an end date with a specified step.
|
|
@@ -12,15 +12,15 @@ import { chronal } from "./chronal.js";
|
|
|
12
12
|
* const start = chronal("2024-01-01");
|
|
13
13
|
* const end = new Date("2024-01-05");
|
|
14
14
|
*
|
|
15
|
-
* start.
|
|
16
|
-
* start.
|
|
15
|
+
* start.until(end); // Array of 5 Chronal objects (Jan 1-5)
|
|
16
|
+
* start.until(end, { days: 2 }); // Array of 3 Chronal objects (Jan 1, 3, 5)
|
|
17
17
|
*
|
|
18
18
|
* // Weekly range
|
|
19
|
-
* chronal("2024-01-01").
|
|
19
|
+
* chronal("2024-01-01").until(new Date("2024-01-31"), { weeks: 1 });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export function
|
|
22
|
+
export function until(end, step) {
|
|
23
23
|
const endDate = end instanceof Date ? end : end.date;
|
|
24
|
-
const dates =
|
|
24
|
+
const dates = _datesUntil(this.date, endDate, step);
|
|
25
25
|
return dates.map((date) => chronal(date));
|
|
26
26
|
}
|
|
@@ -4,13 +4,13 @@ import { type Chronal } from "./chronal.js";
|
|
|
4
4
|
* Returns the end of the specified time unit.
|
|
5
5
|
*
|
|
6
6
|
* @param unit - The time unit ('year' | 'month' | 'day' | 'hour' | 'minute' | 'second')
|
|
7
|
-
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to
|
|
7
|
+
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to config.timezone.
|
|
8
8
|
* @returns A new Chronal instance set to the end of the specified unit (last millisecond)
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
11
|
* const c = chronal('2024-06-15T14:35:22.500Z');
|
|
12
|
-
* c.endOf('day'); //
|
|
13
|
-
* c.endOf('day', 'America/Sao_Paulo'); // '2024-06-16T02:59:59.999Z'
|
|
12
|
+
* c.endOf('day'); // Uses config.timezone
|
|
13
|
+
* c.endOf('day', { tz: 'America/Sao_Paulo' }); // '2024-06-16T02:59:59.999Z'
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export declare function endOf(this: Chronal, unit: Parameters<typeof _endOf>[1], opt?: Parameters<typeof _endOf>[2]): Chronal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"end-of.d.ts","sourceRoot":"","sources":["../../src/chainable/end-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"end-of.d.ts","sourceRoot":"","sources":["../../src/chainable/end-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;AAGrD;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAOpH"}
|
package/esm/chainable/end-of.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { endOf as _endOf } from "../lib/end-of.js";
|
|
2
2
|
import { chronal } from "./chronal.js";
|
|
3
|
+
import { config } from "../lib/config.js";
|
|
3
4
|
/**
|
|
4
5
|
* Returns the end of the specified time unit.
|
|
5
6
|
*
|
|
6
7
|
* @param unit - The time unit ('year' | 'month' | 'day' | 'hour' | 'minute' | 'second')
|
|
7
|
-
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to
|
|
8
|
+
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to config.timezone.
|
|
8
9
|
* @returns A new Chronal instance set to the end of the specified unit (last millisecond)
|
|
9
10
|
* @example
|
|
10
11
|
* ```typescript
|
|
11
12
|
* const c = chronal('2024-06-15T14:35:22.500Z');
|
|
12
|
-
* c.endOf('day'); //
|
|
13
|
-
* c.endOf('day', 'America/Sao_Paulo'); // '2024-06-16T02:59:59.999Z'
|
|
13
|
+
* c.endOf('day'); // Uses config.timezone
|
|
14
|
+
* c.endOf('day', { tz: 'America/Sao_Paulo' }); // '2024-06-16T02:59:59.999Z'
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
export function endOf(unit, opt
|
|
17
|
-
const
|
|
17
|
+
export function endOf(unit, opt) {
|
|
18
|
+
const options = opt || {};
|
|
19
|
+
if (!options.tz) {
|
|
20
|
+
options.tz = config.timezone;
|
|
21
|
+
}
|
|
22
|
+
const newDate = _endOf(this.date, unit, options);
|
|
18
23
|
return chronal(newDate);
|
|
19
24
|
}
|
|
@@ -4,13 +4,13 @@ import { type Chronal } from "./chronal.js";
|
|
|
4
4
|
* Returns the start of the specified time unit.
|
|
5
5
|
*
|
|
6
6
|
* @param unit - The time unit ('year' | 'month' | 'day' | 'hour' | 'minute' | 'second')
|
|
7
|
-
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to
|
|
7
|
+
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to config.timezone.
|
|
8
8
|
* @returns A new Chronal instance set to the start of the specified unit
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
11
|
* const c = chronal('2024-06-15T14:35:22.500Z');
|
|
12
|
-
* c.startOf('day'); //
|
|
13
|
-
* c.startOf('day', 'America/Sao_Paulo'); // '2024-06-15T03:00:00.000Z'
|
|
12
|
+
* c.startOf('day'); // Uses config.timezone
|
|
13
|
+
* c.startOf('day', { tz: 'America/Sao_Paulo' }); // '2024-06-15T03:00:00.000Z'
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export declare function startOf(this: Chronal, unit: Parameters<typeof _startOf>[1], opt?: Parameters<typeof _startOf>[2]): Chronal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-of.d.ts","sourceRoot":"","sources":["../../src/chainable/start-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"start-of.d.ts","sourceRoot":"","sources":["../../src/chainable/start-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;AAGrD;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,EACpC,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,GACnC,OAAO,CAOT"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { startOf as _startOf } from "../lib/start-of.js";
|
|
2
2
|
import { chronal } from "./chronal.js";
|
|
3
|
+
import { config } from "../lib/config.js";
|
|
3
4
|
/**
|
|
4
5
|
* Returns the start of the specified time unit.
|
|
5
6
|
*
|
|
6
7
|
* @param unit - The time unit ('year' | 'month' | 'day' | 'hour' | 'minute' | 'second')
|
|
7
|
-
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to
|
|
8
|
+
* @param timezone - Optional IANA timezone string (e.g., 'America/Sao_Paulo'). Defaults to config.timezone.
|
|
8
9
|
* @returns A new Chronal instance set to the start of the specified unit
|
|
9
10
|
* @example
|
|
10
11
|
* ```typescript
|
|
11
12
|
* const c = chronal('2024-06-15T14:35:22.500Z');
|
|
12
|
-
* c.startOf('day'); //
|
|
13
|
-
* c.startOf('day', 'America/Sao_Paulo'); // '2024-06-15T03:00:00.000Z'
|
|
13
|
+
* c.startOf('day'); // Uses config.timezone
|
|
14
|
+
* c.startOf('day', { tz: 'America/Sao_Paulo' }); // '2024-06-15T03:00:00.000Z'
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
export function startOf(unit, opt
|
|
17
|
-
const
|
|
17
|
+
export function startOf(unit, opt) {
|
|
18
|
+
const options = opt || {};
|
|
19
|
+
if (!options.tz) {
|
|
20
|
+
options.tz = config.timezone;
|
|
21
|
+
}
|
|
22
|
+
const newDate = _startOf(this.date, unit, options);
|
|
18
23
|
return chronal(newDate);
|
|
19
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subtract as _subtract } from "../lib/subtract.js";
|
|
2
2
|
import { type Chronal } from "./chronal.js";
|
|
3
3
|
/**
|
|
4
4
|
* Subtracts specified time units from the date.
|
|
@@ -8,8 +8,8 @@ import { type Chronal } from "./chronal.js";
|
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
10
|
* const c = chronal('2024-03-31T12:00:00Z');
|
|
11
|
-
* c.
|
|
11
|
+
* c.subtract({ years: 1, months: 1 }); // '2023-02-28T12:00:00.000Z'
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
//# sourceMappingURL=
|
|
14
|
+
export declare function subtract(this: Chronal, opt: Parameters<typeof _subtract>[1]): Chronal;
|
|
15
|
+
//# sourceMappingURL=subtract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtract.d.ts","sourceRoot":"","sources":["../../src/chainable/subtract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;AAErD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,GACnC,OAAO,CAGT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subtract as _subtract } from "../lib/subtract.js";
|
|
2
2
|
import { chronal } from "./chronal.js";
|
|
3
3
|
/**
|
|
4
4
|
* Subtracts specified time units from the date.
|
|
@@ -8,10 +8,10 @@ import { chronal } from "./chronal.js";
|
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
10
|
* const c = chronal('2024-03-31T12:00:00Z');
|
|
11
|
-
* c.
|
|
11
|
+
* c.subtract({ years: 1, months: 1 }); // '2023-02-28T12:00:00.000Z'
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
15
|
-
const newDate =
|
|
14
|
+
export function subtract(opt) {
|
|
15
|
+
const newDate = _subtract(this.date, opt);
|
|
16
16
|
return chronal(newDate);
|
|
17
17
|
}
|
package/esm/lib/config.d.ts
CHANGED
package/esm/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAGA,KAAK,MAAM,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAGpB,CAAA;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAGA,KAAK,MAAM,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAGpB,CAAA;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,QAQlD"}
|
package/esm/lib/config.js
CHANGED
|
@@ -21,15 +21,15 @@ type RangeStep = {
|
|
|
21
21
|
* const start = new Date("2024-01-01");
|
|
22
22
|
* const end = new Date("2024-01-05");
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* datesUntil(start, end); // Array of 5 dates (Jan 1-5)
|
|
25
|
+
* datesUntil(start, end, { days: 2 }); // Array of 3 dates (Jan 1, 3, 5)
|
|
26
26
|
*
|
|
27
27
|
* // Weekly range
|
|
28
28
|
* const weekStart = new Date("2024-01-01");
|
|
29
29
|
* const weekEnd = new Date("2024-01-31");
|
|
30
|
-
*
|
|
30
|
+
* datesUntil(weekStart, weekEnd, { weeks: 1 }); // Array of 5 dates (every Monday)
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
export declare function
|
|
33
|
+
export declare function datesUntil(start: Date, end: Date, step?: RangeStep): Date[];
|
|
34
34
|
export {};
|
|
35
|
-
//# sourceMappingURL=
|
|
35
|
+
//# sourceMappingURL=dates-until.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates-until.d.ts","sourceRoot":"","sources":["../../src/lib/dates-until.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,IAAI,EACX,GAAG,EAAE,IAAI,EACT,IAAI,GAAE,SAAuB,GAC5B,IAAI,EAAE,CAuFR"}
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
* const start = new Date("2024-01-01");
|
|
12
12
|
* const end = new Date("2024-01-05");
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* datesUntil(start, end); // Array of 5 dates (Jan 1-5)
|
|
15
|
+
* datesUntil(start, end, { days: 2 }); // Array of 3 dates (Jan 1, 3, 5)
|
|
16
16
|
*
|
|
17
17
|
* // Weekly range
|
|
18
18
|
* const weekStart = new Date("2024-01-01");
|
|
19
19
|
* const weekEnd = new Date("2024-01-31");
|
|
20
|
-
*
|
|
20
|
+
* datesUntil(weekStart, weekEnd, { weeks: 1 }); // Array of 5 dates (every Monday)
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
export function
|
|
23
|
+
export function datesUntil(start, end, step = { days: 1 }) {
|
|
24
24
|
const result = [];
|
|
25
25
|
const startTime = start.getTime();
|
|
26
26
|
const endTime = end.getTime();
|
package/esm/lib/parse-date.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
type ParseDateOptions = {
|
|
2
|
+
format?: string;
|
|
3
|
+
tz?: string;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
6
|
* Parses a date string into a Date object using an optional format pattern.
|
|
7
|
+
* If timezone is specified, the string is interpreted as local time in that timezone.
|
|
3
8
|
*
|
|
4
9
|
* @param dateString - The date string to parse
|
|
5
|
-
* @param
|
|
10
|
+
* @param options - Optional format pattern and/or timezone
|
|
6
11
|
* @returns A Date object
|
|
7
12
|
* @throws Error if the date string is invalid or doesn't match the format
|
|
8
13
|
*
|
|
9
14
|
* @example
|
|
10
15
|
* ```typescript
|
|
11
|
-
* parseDate("2024-06-15"); // Uses native Date parser
|
|
12
|
-
* parseDate("15/06/2024", "DD/MM/YYYY"); // Parses with custom format
|
|
13
|
-
* parseDate("2024-06-15 14:30:00", "YYYY-MM-DD HH:mm:ss");
|
|
16
|
+
* parseDate("2024-06-15"); // Uses native Date parser in UTC
|
|
17
|
+
* parseDate("15/06/2024", { format: "DD/MM/YYYY" }); // Parses with custom format
|
|
18
|
+
* parseDate("2024-06-15 14:30:00", { format: "YYYY-MM-DD HH:mm:ss" });
|
|
19
|
+
* parseDate("2025-04-01", { tz: "America/Sao_Paulo" }); // Parse as São Paulo time
|
|
14
20
|
* ```
|
|
15
21
|
*/
|
|
16
|
-
export declare function parseDate(dateString: string,
|
|
22
|
+
export declare function parseDate(dateString: string, options?: string | ParseDateOptions): Date;
|
|
23
|
+
export {};
|
|
17
24
|
//# sourceMappingURL=parse-date.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-date.d.ts","sourceRoot":"","sources":["../../src/lib/parse-date.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAClC,IAAI,CA0FN"}
|