@formkit/tempo 0.1.2 → 1.1.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.
- package/README.md +22 -1
- package/dist/add.d.ts +11 -0
- package/dist/add.mjs +50 -0
- package/dist/add.mjs.map +1 -0
- package/dist/addDay.d.ts +4 -3
- package/dist/addDay.mjs.map +1 -1
- package/dist/addHour.d.ts +4 -3
- package/dist/addHour.mjs.map +1 -1
- package/dist/addMillisecond.d.ts +10 -0
- package/dist/addMillisecond.mjs +11 -0
- package/dist/addMillisecond.mjs.map +1 -0
- package/dist/addMinute.d.ts +5 -4
- package/dist/addMinute.mjs.map +1 -1
- package/dist/addMonth.d.ts +5 -5
- package/dist/addMonth.mjs +2 -12
- package/dist/addMonth.mjs.map +1 -1
- package/dist/addSecond.d.ts +4 -3
- package/dist/addSecond.mjs.map +1 -1
- package/dist/addYear.d.ts +5 -5
- package/dist/addYear.mjs +6 -12
- package/dist/addYear.mjs.map +1 -1
- package/dist/ap.mjs +1 -2
- package/dist/ap.mjs.map +1 -1
- package/dist/applyOffset.d.ts +5 -5
- package/dist/applyOffset.mjs +5 -11
- package/dist/applyOffset.mjs.map +1 -1
- package/dist/bundle.d.ts +365 -115
- package/dist/bundle.mjs +364 -180
- package/dist/bundle.mjs.map +1 -1
- package/dist/common.d.ts +27 -7
- package/dist/common.mjs +47 -42
- package/dist/common.mjs.map +1 -1
- package/dist/date.d.ts +2 -2
- package/dist/date.mjs +1 -3
- package/dist/date.mjs.map +1 -1
- package/dist/dayEnd.d.ts +3 -3
- package/dist/dayEnd.mjs.map +1 -1
- package/dist/dayOfYear.d.ts +3 -3
- package/dist/dayOfYear.mjs.map +1 -1
- package/dist/dayStart.d.ts +3 -3
- package/dist/dayStart.mjs +1 -1
- package/dist/dayStart.mjs.map +1 -1
- package/dist/diff.d.ts +38 -0
- package/dist/diff.mjs +86 -0
- package/dist/diff.mjs.map +1 -0
- package/dist/diffDays.d.ts +12 -5
- package/dist/diffDays.mjs +1 -0
- package/dist/diffDays.mjs.map +1 -1
- package/dist/diffHours.d.ts +12 -5
- package/dist/diffHours.mjs +1 -0
- package/dist/diffHours.mjs.map +1 -1
- package/dist/diffMilliseconds.d.ts +10 -4
- package/dist/diffMilliseconds.mjs.map +1 -1
- package/dist/diffMinutes.d.ts +11 -3
- package/dist/diffMinutes.mjs +5 -1
- package/dist/diffMinutes.mjs.map +1 -1
- package/dist/diffMonths.d.ts +10 -4
- package/dist/diffMonths.mjs.map +1 -1
- package/dist/diffSeconds.d.ts +12 -5
- package/dist/diffSeconds.mjs +5 -1
- package/dist/diffSeconds.mjs.map +1 -1
- package/dist/diffWeeks.d.ts +10 -3
- package/dist/diffWeeks.mjs.map +1 -1
- package/dist/diffYears.d.ts +10 -4
- package/dist/diffYears.mjs +4 -1
- package/dist/diffYears.mjs.map +1 -1
- package/dist/format.mjs +2 -3
- package/dist/format.mjs.map +1 -1
- package/dist/handleDateOverflow.d.ts +12 -0
- package/dist/handleDateOverflow.mjs +18 -0
- package/dist/handleDateOverflow.mjs.map +1 -0
- package/dist/hourEnd.d.ts +3 -3
- package/dist/hourEnd.mjs.map +1 -1
- package/dist/hourStart.d.ts +3 -3
- package/dist/hourStart.mjs +1 -1
- package/dist/hourStart.mjs.map +1 -1
- package/dist/index.cjs +380 -183
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +365 -115
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -1
- package/dist/isAfter.d.ts +6 -6
- package/dist/isAfter.mjs.map +1 -1
- package/dist/isBefore.d.ts +5 -5
- package/dist/isBefore.mjs.map +1 -1
- package/dist/isEqual.d.ts +13 -4
- package/dist/isEqual.mjs.map +1 -1
- package/dist/isFuture.d.ts +10 -0
- package/dist/isFuture.mjs +9 -0
- package/dist/isFuture.mjs.map +1 -0
- package/dist/isPast.d.ts +10 -0
- package/dist/isPast.mjs +9 -0
- package/dist/isPast.mjs.map +1 -0
- package/dist/iso8601.d.ts +1 -1
- package/dist/iso8601.mjs +4 -7
- package/dist/iso8601.mjs.map +1 -1
- package/dist/minuteEnd.d.ts +3 -3
- package/dist/minuteEnd.mjs.map +1 -1
- package/dist/minuteStart.d.ts +3 -3
- package/dist/minuteStart.mjs +1 -1
- package/dist/minuteStart.mjs.map +1 -1
- package/dist/monthDays.d.ts +3 -3
- package/dist/monthDays.mjs.map +1 -1
- package/dist/monthEnd.d.ts +3 -3
- package/dist/monthEnd.mjs.map +1 -1
- package/dist/monthStart.d.ts +3 -3
- package/dist/monthStart.mjs +1 -1
- package/dist/monthStart.mjs.map +1 -1
- package/dist/nearestDay.d.ts +3 -3
- package/dist/nearestDay.mjs +2 -4
- package/dist/nearestDay.mjs.map +1 -1
- package/dist/offset.d.ts +5 -5
- package/dist/offset.mjs +16 -16
- package/dist/offset.mjs.map +1 -1
- package/dist/parse.mjs +33 -23
- package/dist/parse.mjs.map +1 -1
- package/dist/parts.mjs +14 -24
- package/dist/parts.mjs.map +1 -1
- package/dist/range.mjs +1 -2
- package/dist/range.mjs.map +1 -1
- package/dist/removeOffset.d.ts +4 -4
- package/dist/removeOffset.mjs.map +1 -1
- package/dist/sameDay.d.ts +8 -2
- package/dist/sameDay.mjs.map +1 -1
- package/dist/sameHour.d.ts +8 -2
- package/dist/sameHour.mjs.map +1 -1
- package/dist/sameMillisecond.d.ts +16 -0
- package/dist/sameMillisecond.mjs +11 -0
- package/dist/sameMillisecond.mjs.map +1 -0
- package/dist/sameMinute.d.ts +8 -2
- package/dist/sameMinute.mjs.map +1 -1
- package/dist/sameMonth.d.ts +16 -0
- package/dist/sameMonth.mjs +11 -0
- package/dist/sameMonth.mjs.map +1 -0
- package/dist/sameSecond.d.ts +8 -2
- package/dist/sameSecond.mjs.map +1 -1
- package/dist/sameYear.d.ts +8 -2
- package/dist/sameYear.mjs.map +1 -1
- package/dist/setDayOfMonth.d.ts +11 -0
- package/dist/setDayOfMonth.mjs +16 -0
- package/dist/setDayOfMonth.mjs.map +1 -0
- package/dist/setHour.d.ts +10 -0
- package/dist/setHour.mjs +11 -0
- package/dist/setHour.mjs.map +1 -0
- package/dist/setMilliseconds.d.ts +10 -0
- package/dist/setMilliseconds.mjs +11 -0
- package/dist/setMilliseconds.mjs.map +1 -0
- package/dist/setMinutes.d.ts +10 -0
- package/dist/setMinutes.mjs +11 -0
- package/dist/setMinutes.mjs.map +1 -0
- package/dist/setMonth.d.ts +11 -0
- package/dist/setMonth.mjs +9 -0
- package/dist/setMonth.mjs.map +1 -0
- package/dist/setSeconds.d.ts +10 -0
- package/dist/setSeconds.mjs +11 -0
- package/dist/setSeconds.mjs.map +1 -0
- package/dist/setYear.d.ts +11 -0
- package/dist/setYear.mjs +9 -0
- package/dist/setYear.mjs.map +1 -0
- package/dist/types.d.ts +29 -7
- package/dist/tzDate.d.ts +5 -3
- package/dist/tzDate.mjs.map +1 -1
- package/dist/weekEnd.d.ts +4 -4
- package/dist/weekEnd.mjs +1 -1
- package/dist/weekEnd.mjs.map +1 -1
- package/dist/weekStart.d.ts +4 -4
- package/dist/weekStart.mjs +2 -3
- package/dist/weekStart.mjs.map +1 -1
- package/dist/yearDays.d.ts +3 -3
- package/dist/yearDays.mjs.map +1 -1
- package/dist/yearEnd.d.ts +3 -3
- package/dist/yearEnd.mjs +1 -2
- package/dist/yearEnd.mjs.map +1 -1
- package/dist/yearStart.d.ts +3 -3
- package/dist/yearStart.mjs +2 -3
- package/dist/yearStart.mjs.map +1 -1
- package/package.json +32 -23
package/README.md
CHANGED
|
@@ -10,7 +10,28 @@ Tempo is a new library in a proud tradition of JavaScript date and time librarie
|
|
|
10
10
|
|
|
11
11
|
Tempo is best thought of as a collection of utilities for working with `Date` objects — an important distinction from other libraries that provide custom date primitives. Under the hood, Tempo mines JavaScript's `Intl.DateTimeFormat` to extract complex data like timezones offsets and locale aware date formats giving you a simple API to format, parse, and manipulates dates.
|
|
12
12
|
|
|
13
|
-
Tempo is tiny tree-shakable framework, you can only take what you need.
|
|
13
|
+
Tempo is tiny tree-shakable framework, you can only take what you need. You can work with timezones with only a few bytes of library code, or perform full international date formatting for ~2Kb (minified and brotlied). [Size Limit](https://github.com/ai/size-limit) controls the size.
|
|
14
|
+
|
|
15
|
+
## Development
|
|
16
|
+
|
|
17
|
+
Install from the repository root with `pnpm`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
corepack enable
|
|
21
|
+
pnpm install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Build the library:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm build
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Build the docs app:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm docs-build
|
|
34
|
+
```
|
|
14
35
|
|
|
15
36
|
<a href="https://tempo.formkit.com">
|
|
16
37
|
<img src="docs/public/read-the-docs.png" alt="Read the docs" width="200" height="43">
|
package/dist/add.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MaybeDateInput, Duration } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new Date object with the duration applied.
|
|
5
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
6
|
+
* @param duration - An object with values for the amount of time to add to the original date.
|
|
7
|
+
* @param [dateOverflow] - Whether to allow month/year changes to overflow into a later month.
|
|
8
|
+
*/
|
|
9
|
+
declare function add(inputDate: MaybeDateInput, duration: Duration, dateOverflow?: boolean): Date;
|
|
10
|
+
|
|
11
|
+
export { add };
|
package/dist/add.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/add.ts
|
|
2
|
+
import { addDay } from "./addDay.mjs";
|
|
3
|
+
import { addHour } from "./addHour.mjs";
|
|
4
|
+
import { addMillisecond } from "./addMillisecond.mjs";
|
|
5
|
+
import { addMinute } from "./addMinute.mjs";
|
|
6
|
+
import { addMonth } from "./addMonth.mjs";
|
|
7
|
+
import { addSecond } from "./addSecond.mjs";
|
|
8
|
+
import { addYear } from "./addYear.mjs";
|
|
9
|
+
import { date } from "./date.mjs";
|
|
10
|
+
function add(inputDate, duration, dateOverflow = false) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
let d = date(inputDate);
|
|
13
|
+
const applyFixedUnits = () => {
|
|
14
|
+
if (duration.weeks) {
|
|
15
|
+
d = addDay(d, duration.weeks * 7);
|
|
16
|
+
}
|
|
17
|
+
if (duration.days) {
|
|
18
|
+
d = addDay(d, duration.days);
|
|
19
|
+
}
|
|
20
|
+
if (duration.hours) {
|
|
21
|
+
d = addHour(d, duration.hours);
|
|
22
|
+
}
|
|
23
|
+
if (duration.minutes) {
|
|
24
|
+
d = addMinute(d, duration.minutes);
|
|
25
|
+
}
|
|
26
|
+
if (duration.seconds) {
|
|
27
|
+
d = addSecond(d, duration.seconds);
|
|
28
|
+
}
|
|
29
|
+
if (duration.milliseconds) {
|
|
30
|
+
d = addMillisecond(d, duration.milliseconds);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const applyCalendarUnits = () => {
|
|
34
|
+
if (duration.months) {
|
|
35
|
+
d = addMonth(d, duration.months, dateOverflow);
|
|
36
|
+
}
|
|
37
|
+
if (duration.years) {
|
|
38
|
+
d = addYear(d, duration.years, dateOverflow);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const calendarFirst = ((_a = duration.months) != null ? _a : 0) < 0 || ((_b = duration.years) != null ? _b : 0) < 0;
|
|
42
|
+
if (calendarFirst) applyCalendarUnits();
|
|
43
|
+
applyFixedUnits();
|
|
44
|
+
if (!calendarFirst) applyCalendarUnits();
|
|
45
|
+
return d;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
add
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=add.mjs.map
|
package/dist/add.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/add.ts"],"sourcesContent":["import { addDay } from \"./addDay\"\nimport { addHour } from \"./addHour\"\nimport { addMillisecond } from \"./addMillisecond\"\nimport { addMinute } from \"./addMinute\"\nimport { addMonth } from \"./addMonth\"\nimport { addSecond } from \"./addSecond\"\nimport { addYear } from \"./addYear\"\nimport { date } from \"./date\"\nimport type { Duration, MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new Date object with the duration applied.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param duration - An object with values for the amount of time to add to the original date.\n * @param [dateOverflow] - Whether to allow month/year changes to overflow into a later month.\n */\nexport function add(\n inputDate: MaybeDateInput,\n duration: Duration,\n dateOverflow = false\n) {\n let d = date(inputDate)\n const applyFixedUnits = () => {\n if (duration.weeks) {\n d = addDay(d, duration.weeks * 7)\n }\n if (duration.days) {\n d = addDay(d, duration.days)\n }\n if (duration.hours) {\n d = addHour(d, duration.hours)\n }\n if (duration.minutes) {\n d = addMinute(d, duration.minutes)\n }\n if (duration.seconds) {\n d = addSecond(d, duration.seconds)\n }\n if (duration.milliseconds) {\n d = addMillisecond(d, duration.milliseconds)\n }\n }\n const applyCalendarUnits = () => {\n if (duration.months) {\n d = addMonth(d, duration.months, dateOverflow)\n }\n if (duration.years) {\n d = addYear(d, duration.years, dateOverflow)\n }\n }\n const calendarFirst = (duration.months ?? 0) < 0 || (duration.years ?? 0) < 0\n\n if (calendarFirst) applyCalendarUnits()\n applyFixedUnits()\n if (!calendarFirst) applyCalendarUnits()\n\n return d\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,YAAY;AASd,SAAS,IACd,WACA,UACA,eAAe,OACf;AApBF;AAqBE,MAAI,IAAI,KAAK,SAAS;AACtB,QAAM,kBAAkB,MAAM;AAC5B,QAAI,SAAS,OAAO;AAClB,UAAI,OAAO,GAAG,SAAS,QAAQ,CAAC;AAAA,IAClC;AACA,QAAI,SAAS,MAAM;AACjB,UAAI,OAAO,GAAG,SAAS,IAAI;AAAA,IAC7B;AACA,QAAI,SAAS,OAAO;AAClB,UAAI,QAAQ,GAAG,SAAS,KAAK;AAAA,IAC/B;AACA,QAAI,SAAS,SAAS;AACpB,UAAI,UAAU,GAAG,SAAS,OAAO;AAAA,IACnC;AACA,QAAI,SAAS,SAAS;AACpB,UAAI,UAAU,GAAG,SAAS,OAAO;AAAA,IACnC;AACA,QAAI,SAAS,cAAc;AACzB,UAAI,eAAe,GAAG,SAAS,YAAY;AAAA,IAC7C;AAAA,EACF;AACA,QAAM,qBAAqB,MAAM;AAC/B,QAAI,SAAS,QAAQ;AACnB,UAAI,SAAS,GAAG,SAAS,QAAQ,YAAY;AAAA,IAC/C;AACA,QAAI,SAAS,OAAO;AAClB,UAAI,QAAQ,GAAG,SAAS,OAAO,YAAY;AAAA,IAC7C;AAAA,EACF;AACA,QAAM,kBAAiB,cAAS,WAAT,YAAmB,KAAK,OAAM,cAAS,UAAT,YAAkB,KAAK;AAE5E,MAAI,cAAe,oBAAmB;AACtC,kBAAgB;AAChB,MAAI,CAAC,cAAe,oBAAmB;AAEvC,SAAO;AACT;","names":[]}
|
package/dist/addDay.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a new date object 1/n days after the original one.
|
|
5
|
-
* @param inputDate - A date to increment
|
|
5
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
6
|
+
* @param [count] - The quantity to add.
|
|
6
7
|
*/
|
|
7
|
-
declare function addDay(inputDate
|
|
8
|
+
declare function addDay(inputDate?: MaybeDateInput, count?: number): Date;
|
|
8
9
|
|
|
9
10
|
export { addDay };
|
package/dist/addDay.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/addDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n days after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addDay(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setDate(d.getDate() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,OAAO,WAA4B,QAAQ,GAAG;AAC5D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,QAAQ,EAAE,QAAQ,IAAI,KAAK;AAC7B,SAAO;AACT;","names":[]}
|
package/dist/addHour.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a new date object 1/n hours after the original one.
|
|
5
|
-
* @param inputDate - A date to increment
|
|
5
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
6
|
+
* @param [count] - The quantity to add.
|
|
6
7
|
*/
|
|
7
|
-
declare function addHour(inputDate
|
|
8
|
+
declare function addHour(inputDate?: MaybeDateInput, count?: number): Date;
|
|
8
9
|
|
|
9
10
|
export { addHour };
|
package/dist/addHour.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addHour.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/addHour.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n hours after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addHour(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setHours(d.getHours() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,QAAQ,WAA4B,QAAQ,GAAG;AAC7D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAC/B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new date object 1/n milliseconds after the original one.
|
|
5
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
6
|
+
* @param [count] - The quantity to add.
|
|
7
|
+
*/
|
|
8
|
+
declare function addMillisecond(inputDate?: MaybeDateInput, count?: number): Date;
|
|
9
|
+
|
|
10
|
+
export { addMillisecond };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/addMillisecond.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function addMillisecond(inputDate, count = 1) {
|
|
4
|
+
const d = date(inputDate);
|
|
5
|
+
d.setMilliseconds(d.getMilliseconds() + count);
|
|
6
|
+
return d;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
addMillisecond
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=addMillisecond.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addMillisecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n milliseconds after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addMillisecond(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setMilliseconds(d.getMilliseconds() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,eAAe,WAA4B,QAAQ,GAAG;AACpE,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,gBAAgB,EAAE,gBAAgB,IAAI,KAAK;AAC7C,SAAO;AACT;","names":[]}
|
package/dist/addMinute.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Returns a new date object 1/n
|
|
5
|
-
* @param inputDate - A date to increment
|
|
4
|
+
* Returns a new date object 1/n minutes after the original one.
|
|
5
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
6
|
+
* @param [count] - The quantity to add.
|
|
6
7
|
*/
|
|
7
|
-
declare function addMinute(inputDate
|
|
8
|
+
declare function addMinute(inputDate?: MaybeDateInput, count?: number): Date;
|
|
8
9
|
|
|
9
10
|
export { addMinute };
|
package/dist/addMinute.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addMinute.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n
|
|
1
|
+
{"version":3,"sources":["../src/addMinute.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n minutes after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addMinute(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setMinutes(d.getMinutes() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,UAAU,WAA4B,QAAQ,GAAG;AAC/D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
|
package/dist/addMonth.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a new date object 1/n months after the original one. Keep in mind if you
|
|
5
5
|
* start with a date late in a given month you could get a date after the next
|
|
6
6
|
* month.
|
|
7
|
-
* @param inputDate - A date to increment
|
|
8
|
-
* @param count - The quantity to add.
|
|
9
|
-
* @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
|
|
7
|
+
* @param [inputDate] - A date to increment or null to increment from the current time
|
|
8
|
+
* @param [count] - The quantity to add.
|
|
9
|
+
* @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
|
|
10
10
|
*/
|
|
11
|
-
declare function addMonth(inputDate
|
|
11
|
+
declare function addMonth(inputDate?: MaybeDateInput, count?: number, dateOverflow?: boolean): Date;
|
|
12
12
|
|
|
13
13
|
export { addMonth };
|
package/dist/addMonth.mjs
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
// src/addMonth.ts
|
|
2
|
-
import {
|
|
3
|
-
import { monthDays } from "./monthDays.mjs";
|
|
2
|
+
import { handleOverflow } from "./handleDateOverflow.mjs";
|
|
4
3
|
function addMonth(inputDate, count = 1, dateOverflow = false) {
|
|
5
|
-
|
|
6
|
-
const dayOfMonth = d.getDate();
|
|
7
|
-
if (!dateOverflow)
|
|
8
|
-
d.setDate(1);
|
|
9
|
-
d.setMonth(d.getMonth() + count);
|
|
10
|
-
if (!dateOverflow) {
|
|
11
|
-
const daysInMonth = monthDays(d);
|
|
12
|
-
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
13
|
-
}
|
|
14
|
-
return d;
|
|
4
|
+
return handleOverflow(inputDate, (d) => d.setMonth(d.getMonth() + count), dateOverflow);
|
|
15
5
|
}
|
|
16
6
|
export {
|
|
17
7
|
addMonth
|
package/dist/addMonth.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addMonth.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/addMonth.ts"],"sourcesContent":["import { handleOverflow } from \"./handleDateOverflow\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n months after the original one. Keep in mind if you\n * start with a date late in a given month you could get a date after the next\n * month.\n * @param [inputDate] - A date to increment or null to increment from the current time\n * @param [count] - The quantity to add.\n * @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addMonth(inputDate?: MaybeDateInput, count = 1, dateOverflow = false) {\n return handleOverflow(inputDate, (d) => d.setMonth(d.getMonth() + count), dateOverflow)\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAWxB,SAAS,SAAS,WAA4B,QAAQ,GAAG,eAAe,OAAO;AACpF,SAAO,eAAe,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,IAAI,KAAK,GAAG,YAAY;AACxF;","names":[]}
|
package/dist/addSecond.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a new date object 1/n seconds after the original one.
|
|
5
|
-
* @param inputDate - A date to increment
|
|
5
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
6
|
+
* @param [count] - The quantity to add.
|
|
6
7
|
*/
|
|
7
|
-
declare function addSecond(inputDate
|
|
8
|
+
declare function addSecond(inputDate?: MaybeDateInput, count?: number): Date;
|
|
8
9
|
|
|
9
10
|
export { addSecond };
|
package/dist/addSecond.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addSecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/addSecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n seconds after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addSecond(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setSeconds(d.getSeconds() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,UAAU,WAA4B,QAAQ,GAAG;AAC/D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
|
package/dist/addYear.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a new date object 1/n years after the original one. Keep in mind if
|
|
5
5
|
* you start with a date late in a given month you could get a date after the
|
|
6
6
|
* next month.
|
|
7
|
-
* @param inputDate - A date to increment
|
|
8
|
-
* @param count - The quantity of years add.
|
|
9
|
-
* @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
|
|
7
|
+
* @param [inputDate] - A date to increment or null to increment from the current time.
|
|
8
|
+
* @param [count] - The quantity of years add.
|
|
9
|
+
* @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
|
|
10
10
|
*/
|
|
11
|
-
declare function addYear(inputDate
|
|
11
|
+
declare function addYear(inputDate?: MaybeDateInput, count?: number, dateOverflow?: boolean): Date;
|
|
12
12
|
|
|
13
13
|
export { addYear };
|
package/dist/addYear.mjs
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
// src/addYear.ts
|
|
2
|
-
import {
|
|
3
|
-
import { monthDays } from "./monthDays.mjs";
|
|
2
|
+
import { handleOverflow } from "./handleDateOverflow.mjs";
|
|
4
3
|
function addYear(inputDate, count = 1, dateOverflow = false) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!dateOverflow) {
|
|
11
|
-
const daysInMonth = monthDays(d);
|
|
12
|
-
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
13
|
-
}
|
|
14
|
-
return d;
|
|
4
|
+
return handleOverflow(
|
|
5
|
+
inputDate,
|
|
6
|
+
(d) => d.setFullYear(d.getFullYear() + count),
|
|
7
|
+
dateOverflow
|
|
8
|
+
);
|
|
15
9
|
}
|
|
16
10
|
export {
|
|
17
11
|
addYear
|
package/dist/addYear.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addYear.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/addYear.ts"],"sourcesContent":["import { handleOverflow } from \"./handleDateOverflow\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n years after the original one. Keep in mind if\n * you start with a date late in a given month you could get a date after the\n * next month.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity of years add.\n * @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addYear(inputDate?: MaybeDateInput, count = 1, dateOverflow = false) {\n return handleOverflow(\n inputDate,\n (d) => d.setFullYear(d.getFullYear() + count),\n dateOverflow\n )\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAWxB,SAAS,QAAQ,WAA4B,QAAQ,GAAG,eAAe,OAAO;AACnF,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,IAAI,KAAK;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
package/dist/ap.mjs
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import { dayPeriodMap, specDate, normStr } from "./common.mjs";
|
|
3
3
|
function ap(ampm, locale) {
|
|
4
4
|
const l = dayPeriodMap.get(locale);
|
|
5
|
-
if (l && l[ampm])
|
|
6
|
-
return l[ampm];
|
|
5
|
+
if (l && l[ampm]) return l[ampm];
|
|
7
6
|
const specimen = new Date(specDate);
|
|
8
7
|
specimen.setUTCHours(ampm === "am" ? 5 : 20);
|
|
9
8
|
const subparts = new Intl.DateTimeFormat(locale, {
|
package/dist/ap.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ap.ts"],"sourcesContent":["import { dayPeriodMap, specDate, normStr } from \"./common\"\n\n/**\n * Determines the correct value for am/pm by locale and memoizes it.\n * @param ampm - am or pm\n * @param locale - The locale to fetch.\n */\nexport function ap(ampm: \"am\" | \"pm\", locale: string): string {\n const l = dayPeriodMap.get(locale)\n if (l && l[ampm]) return l[ampm] as string\n const specimen = new Date(specDate)\n specimen.setUTCHours(ampm === \"am\" ? 5 : 20)\n const subparts = new Intl.DateTimeFormat(locale, {\n timeStyle: \"full\",\n timeZone: \"UTC\",\n hour12: true,\n })\n .formatToParts(specimen)\n .map(normStr)\n const period = subparts.find((part) => part.type === \"dayPeriod\")\n if (period) {\n const localePeriods: { am?: string; pm?: string } = l || {}\n dayPeriodMap.set(\n locale,\n Object.assign(localePeriods, { [ampm]: period.value })\n )\n return period.value\n }\n return ampm\n}\n"],"mappings":";AAAA,SAAS,cAAc,UAAU,eAAe;AAOzC,SAAS,GAAG,MAAmB,QAAwB;AAC5D,QAAM,IAAI,aAAa,IAAI,MAAM;AACjC,MAAI,KAAK,EAAE,IAAI
|
|
1
|
+
{"version":3,"sources":["../src/ap.ts"],"sourcesContent":["import { dayPeriodMap, specDate, normStr } from \"./common\"\n\n/**\n * Determines the correct value for am/pm by locale and memoizes it.\n * @param ampm - am or pm\n * @param locale - The locale to fetch.\n */\nexport function ap(ampm: \"am\" | \"pm\", locale: string): string {\n const l = dayPeriodMap.get(locale)\n if (l && l[ampm]) return l[ampm] as string\n const specimen = new Date(specDate)\n specimen.setUTCHours(ampm === \"am\" ? 5 : 20)\n const subparts = new Intl.DateTimeFormat(locale, {\n timeStyle: \"full\",\n timeZone: \"UTC\",\n hour12: true,\n })\n .formatToParts(specimen)\n .map(normStr)\n const period = subparts.find((part) => part.type === \"dayPeriod\")\n if (period) {\n const localePeriods: { am?: string; pm?: string } = l || {}\n dayPeriodMap.set(\n locale,\n Object.assign(localePeriods, { [ampm]: period.value })\n )\n return period.value\n }\n return ampm\n}\n"],"mappings":";AAAA,SAAS,cAAc,UAAU,eAAe;AAOzC,SAAS,GAAG,MAAmB,QAAwB;AAC5D,QAAM,IAAI,aAAa,IAAI,MAAM;AACjC,MAAI,KAAK,EAAE,IAAI,EAAG,QAAO,EAAE,IAAI;AAC/B,QAAM,WAAW,IAAI,KAAK,QAAQ;AAClC,WAAS,YAAY,SAAS,OAAO,IAAI,EAAE;AAC3C,QAAM,WAAW,IAAI,KAAK,eAAe,QAAQ;AAAA,IAC/C,WAAW;AAAA,IACX,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC,EACE,cAAc,QAAQ,EACtB,IAAI,OAAO;AACd,QAAM,SAAS,SAAS,KAAK,CAAC,SAAS,KAAK,SAAS,WAAW;AAChE,MAAI,QAAQ;AACV,UAAM,gBAA8C,KAAK,CAAC;AAC1D,iBAAa;AAAA,MACX;AAAA,MACA,OAAO,OAAO,eAAe,EAAE,CAAC,IAAI,GAAG,OAAO,MAAM,CAAC;AAAA,IACvD;AACA,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;","names":[]}
|
package/dist/applyOffset.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Apply a given offset to a date, returning a new date with the offset
|
|
5
|
-
* applied by adding or subtracting the given number of
|
|
6
|
-
* @param dateInput - The date to apply the offset to.
|
|
7
|
-
* @param offset - The offset to apply in the +-HHmm or +-HH:mm format.
|
|
5
|
+
* applied by adding or subtracting the given number of seconds.
|
|
6
|
+
* @param [dateInput] - The date to apply the offset to. (default: current time)
|
|
7
|
+
* @param [offset] - The offset to apply in the +-HHmm, +-HH:mm, +-HHmmss, or +-HH:mm:ss format.
|
|
8
8
|
*/
|
|
9
|
-
declare function applyOffset(dateInput
|
|
9
|
+
declare function applyOffset(dateInput?: MaybeDateInput, offset?: string): Date;
|
|
10
10
|
|
|
11
11
|
export { applyOffset };
|
package/dist/applyOffset.mjs
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
// src/applyOffset.ts
|
|
2
2
|
import { date } from "./date.mjs";
|
|
3
|
-
import { fixedLengthByOffset,
|
|
3
|
+
import { fixedLengthByOffset, offsetToSecs } from "./common.mjs";
|
|
4
4
|
function applyOffset(dateInput, offset = "+00:00") {
|
|
5
5
|
const d = date(dateInput);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
case 6:
|
|
11
|
-
return "Z";
|
|
12
|
-
}
|
|
13
|
-
})();
|
|
14
|
-
const timeDiffInMins = offsetToMins(offset, token);
|
|
15
|
-
return new Date(d.getTime() + timeDiffInMins * 1e3 * 60);
|
|
6
|
+
const len = fixedLengthByOffset(offset);
|
|
7
|
+
const token = len === 5 || len === 8 ? "ZZ" : "Z";
|
|
8
|
+
const timeDiffInSecs = offsetToSecs(offset, token);
|
|
9
|
+
return new Date(d.getTime() + timeDiffInSecs * 1e3);
|
|
16
10
|
}
|
|
17
11
|
export {
|
|
18
12
|
applyOffset
|
package/dist/applyOffset.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/applyOffset.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { TimezoneToken, fixedLengthByOffset,
|
|
1
|
+
{"version":3,"sources":["../src/applyOffset.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { TimezoneToken, fixedLengthByOffset, offsetToSecs } from \"./common\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Apply a given offset to a date, returning a new date with the offset\n * applied by adding or subtracting the given number of seconds.\n * @param [dateInput] - The date to apply the offset to. (default: current time)\n * @param [offset] - The offset to apply in the +-HHmm, +-HH:mm, +-HHmmss, or +-HH:mm:ss format.\n */\nexport function applyOffset(dateInput?: MaybeDateInput, offset = \"+00:00\"): Date {\n const d = date(dateInput)\n const len = fixedLengthByOffset(offset)\n // 5 or 8 chars = no colons (ZZ format), 6 or 9 chars = with colons (Z format)\n const token: TimezoneToken = len === 5 || len === 8 ? \"ZZ\" : \"Z\"\n const timeDiffInSecs = offsetToSecs(offset, token)\n return new Date(d.getTime() + timeDiffInSecs * 1000)\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAwB,qBAAqB,oBAAoB;AAS1D,SAAS,YAAY,WAA4B,SAAS,UAAgB;AAC/E,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,MAAM,oBAAoB,MAAM;AAEtC,QAAM,QAAuB,QAAQ,KAAK,QAAQ,IAAI,OAAO;AAC7D,QAAM,iBAAiB,aAAa,QAAQ,KAAK;AACjD,SAAO,IAAI,KAAK,EAAE,QAAQ,IAAI,iBAAiB,GAAI;AACrD;","names":[]}
|