@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/dist/diffDays.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { DateInput } from './types.js';
|
|
1
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
2
2
|
import { DiffRoundingMethod } from './diffRound.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the difference between 2 dates in days.
|
|
6
|
-
* @param dateA A date to compare with the right date
|
|
7
|
-
* @param dateB A date to compare with the left date
|
|
8
|
-
* @param roundingMethod the rounding method to use, default: trunc
|
|
6
|
+
* @param dateA - A date to compare with the right date
|
|
7
|
+
* @param [dateB] - A date to compare with the left date or nothing to compare with the current time
|
|
8
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
9
9
|
*/
|
|
10
|
-
declare function diffDays(dateA: DateInput, dateB
|
|
10
|
+
declare function diffDays(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the difference between 2 dates in days.
|
|
13
|
+
* @param [dateA] - A date to compare with the right date or null to compare with the current time
|
|
14
|
+
* @param dateB - A date to compare with the left date
|
|
15
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
16
|
+
*/
|
|
17
|
+
declare function diffDays(dateA: MaybeDateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
18
|
|
|
12
19
|
export { diffDays };
|
package/dist/diffDays.mjs
CHANGED
package/dist/diffDays.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffDays.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DateInput } from \"./types\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in days.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date\n * @param roundingMethod the rounding method to use, default: trunc\n */\nexport function diffDays(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n) {\n return diffRound(\n diffMilliseconds(dateA, dateB) / 86_400_000, // hour * 24\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,iBAA0C;
|
|
1
|
+
{"version":3,"sources":["../src/diffDays.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in days.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffDays(\n dateA: DateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n/**\n * Returns the difference between 2 dates in days.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffDays(\n dateA: MaybeDateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffDays(\n dateA: MaybeDateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n // @ts-ignore\n diffMilliseconds(dateA, dateB) / 86_400_000, // hour * 24\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,iBAA0C;AAyB5C,SAAS,SACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA;AAAA,IAEL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
package/dist/diffHours.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { DiffRoundingMethod } from './diffRound.js';
|
|
2
|
-
import { DateInput } from './types.js';
|
|
2
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the difference between 2 dates in hours.
|
|
6
|
-
* @param dateA A date to compare with the right date
|
|
7
|
-
* @param dateB A date to compare with the left date
|
|
8
|
-
* @param roundingMethod the rounding method to use, default: trunc
|
|
6
|
+
* @param dateA - A date to compare with the right date
|
|
7
|
+
* @param [dateB] - A date to compare with the left date or nothing to compare with the current time
|
|
8
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
9
9
|
*/
|
|
10
|
-
declare function diffHours(dateA: DateInput, dateB
|
|
10
|
+
declare function diffHours(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the difference between 2 dates in hours.
|
|
13
|
+
* @param [dateA] - A date to compare with the right date or null to compare with the current time
|
|
14
|
+
* @param dateB - A date to compare with the left date
|
|
15
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
16
|
+
*/
|
|
17
|
+
declare function diffHours(dateA: MaybeDateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
18
|
|
|
12
19
|
export { diffHours };
|
package/dist/diffHours.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
|
3
3
|
import { diffRound } from "./diffRound.mjs";
|
|
4
4
|
function diffHours(dateA, dateB, roundingMethod) {
|
|
5
5
|
return diffRound(
|
|
6
|
+
//@ts-ignore
|
|
6
7
|
diffMilliseconds(dateA, dateB) / 36e5,
|
|
7
8
|
// 1000 * 60 * 60
|
|
8
9
|
roundingMethod
|
package/dist/diffHours.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffHours.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\nimport { DateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in hours.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date\n * @param roundingMethod the rounding method to use, default: trunc\n */\nexport function diffHours(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n) {\n return diffRound(\n diffMilliseconds(dateA, dateB) / 3_600_000, // 1000 * 60 * 60\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,iBAA0C;
|
|
1
|
+
{"version":3,"sources":["../src/diffHours.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in hours.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffHours(\n dateA: DateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\n/**\n * Returns the difference between 2 dates in hours.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffHours(\n dateA: MaybeDateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffHours(\n dateA: MaybeDateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n //@ts-ignore\n diffMilliseconds(dateA, dateB) / 3_600_000, // 1000 * 60 * 60\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,iBAA0C;AA2B5C,SAAS,UACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA;AAAA,IAEL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { DateInput } from './types.js';
|
|
1
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns the difference between 2 dates in milliseconds.
|
|
5
|
-
* @param dateA A date to compare with the right date
|
|
6
|
-
* @param dateB A date to compare with the left date
|
|
5
|
+
* @param dateA - A date to compare with the right date
|
|
6
|
+
* @param [dateB] - A date to compare with the left date or nothing to compare with the current time
|
|
7
7
|
*/
|
|
8
|
-
declare function diffMilliseconds(dateA: DateInput, dateB
|
|
8
|
+
declare function diffMilliseconds(dateA: DateInput, dateB?: MaybeDateInput): number;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the difference between 2 dates in milliseconds.
|
|
11
|
+
* @param [dateA] - A date to compare with the right date or null to compare with the current time
|
|
12
|
+
* @param dateB - A date to compare with the left date
|
|
13
|
+
*/
|
|
14
|
+
declare function diffMilliseconds(dateA: MaybeDateInput, dateB: DateInput): number;
|
|
9
15
|
|
|
10
16
|
export { diffMilliseconds };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffMilliseconds.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { DateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in milliseconds.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date\n */\nexport function diffMilliseconds(dateA: DateInput, dateB: DateInput) {\n const left = date(dateA)\n const right = date(dateB)\n return +left - +right\n}\n"],"mappings":";AAAA,SAAS,YAAY;
|
|
1
|
+
{"version":3,"sources":["../src/diffMilliseconds.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in milliseconds.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time\n */\nexport function diffMilliseconds(dateA: DateInput, dateB?: MaybeDateInput): number\n\n/**\n * Returns the difference between 2 dates in milliseconds.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n */\nexport function diffMilliseconds(dateA: MaybeDateInput, dateB: DateInput): number\n\nexport function diffMilliseconds(dateA: MaybeDateInput, dateB?: MaybeDateInput): number {\n const left = date(dateA)\n const right = date(dateB)\n return +left - +right\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAiBd,SAAS,iBAAiB,OAAuB,OAAgC;AACtF,QAAM,OAAO,KAAK,KAAK;AACvB,QAAM,QAAQ,KAAK,KAAK;AACxB,SAAO,CAAC,OAAO,CAAC;AAClB;","names":[]}
|
package/dist/diffMinutes.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { DateInput } from './types.js';
|
|
1
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
2
2
|
import { DiffRoundingMethod } from './diffRound.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the difference between 2 dates in minutes.
|
|
6
|
-
* @param dateA A date to compare with the right date
|
|
7
|
-
* @param
|
|
6
|
+
* @param dateA - A date to compare with the right date
|
|
7
|
+
* @param [dateB] - A Date to compare with the left date or nothing to compare with the current time
|
|
8
|
+
* @param [roundingMethod] the rounding method to use, default: trunc
|
|
9
|
+
*/
|
|
10
|
+
declare function diffMinutes(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the difference between 2 dates in minutes.
|
|
13
|
+
* @param [dateA] - A date to compare with the right date or null to compare with the current time
|
|
14
|
+
* @param dateB - A Date to compare with the left date
|
|
15
|
+
* @param [roundingMethod] the rounding method to use, default: trunc
|
|
8
16
|
*/
|
|
9
17
|
declare function diffMinutes(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
10
18
|
|
package/dist/diffMinutes.mjs
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
3
|
import { diffRound } from "./diffRound.mjs";
|
|
4
4
|
function diffMinutes(dateA, dateB, roundingMethod) {
|
|
5
|
-
return diffRound(
|
|
5
|
+
return diffRound(
|
|
6
|
+
//@ts-ignore
|
|
7
|
+
diffMilliseconds(dateA, dateB) / 6e4,
|
|
8
|
+
roundingMethod
|
|
9
|
+
);
|
|
6
10
|
}
|
|
7
11
|
export {
|
|
8
12
|
diffMinutes
|
package/dist/diffMinutes.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffMinutes.ts"],"sourcesContent":["import { DateInput } from \"./types\"\nimport { diffMilliseconds } from \"./diffMilliseconds\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in minutes.\n * @param dateA A date to compare with the right date\n * @param roundingMethod the rounding method to use, default: trunc\n */\nexport function diffMinutes(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n) {\n return diffRound(diffMilliseconds(dateA, dateB) / 60_000
|
|
1
|
+
{"version":3,"sources":["../src/diffMinutes.ts"],"sourcesContent":["import type { DateInput, MaybeDateInput } from \"./types\"\nimport { diffMilliseconds } from \"./diffMilliseconds\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in minutes.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A Date to compare with the left date or nothing to compare with the current time\n * @param [roundingMethod] the rounding method to use, default: trunc\n */\nexport function diffMinutes(\n dateA: DateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\n/**\n * Returns the difference between 2 dates in minutes.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A Date to compare with the left date\n * @param [roundingMethod] the rounding method to use, default: trunc\n */\nexport function diffMinutes(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffMinutes(\n dateA: MaybeDateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n //@ts-ignore\n diffMilliseconds(dateA, dateB) / 60_000,\n roundingMethod\n )\n}\n"],"mappings":";AACA,SAAS,wBAAwB;AACjC,SAAS,iBAA0C;AA0B5C,SAAS,YACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA;AAAA,IAEL,iBAAiB,OAAO,KAAK,IAAI;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
package/dist/diffMonths.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { DateInput } from './types.js';
|
|
1
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns the difference between 2 dates in months.
|
|
5
|
-
* @param dateA A date to compare with the dateB date
|
|
6
|
-
* @param dateB A date to compare with the dateA date
|
|
5
|
+
* @param dateA - A date to compare with the dateB date
|
|
6
|
+
* @param [dateB] - A date to compare with the dateA date or nothing to compare with the current time
|
|
7
7
|
*/
|
|
8
|
-
declare function diffMonths(dateA: DateInput, dateB
|
|
8
|
+
declare function diffMonths(dateA: DateInput, dateB?: MaybeDateInput): number;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the difference between 2 dates in months.
|
|
11
|
+
* @param [dateA] - A date to compare with the dateB date or null to compare with the current time
|
|
12
|
+
* @param dateB - A date to compare with the dateA date
|
|
13
|
+
*/
|
|
14
|
+
declare function diffMonths(dateA: MaybeDateInput, dateB: DateInput): number;
|
|
9
15
|
|
|
10
16
|
export { diffMonths };
|
package/dist/diffMonths.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffMonths.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { DateInput } from \"./types\"\nimport { monthDays } from \"./monthDays\"\n\n/**\n * Returns the difference between 2 dates in months.\n * @param dateA A date to compare with the dateB date\n * @param dateB A date to compare with the dateA date\n */\nexport function diffMonths(dateA: DateInput, dateB: DateInput): number {\n const l = date(dateA)\n const r = date(dateB)\n // if the dateB one is bigger, we switch them around as it's easier to do\n if (l < r) {\n const rs = diffMonths(r, l)\n return rs == 0 ? 0 : -rs\n }\n\n // we first get the amount of calendar months\n let months
|
|
1
|
+
{"version":3,"sources":["../src/diffMonths.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\nimport { monthDays } from \"./monthDays\"\n\n/**\n * Returns the difference between 2 dates in months.\n * @param dateA - A date to compare with the dateB date\n * @param [dateB] - A date to compare with the dateA date or nothing to compare with the current time\n */\nexport function diffMonths(dateA: DateInput, dateB?: MaybeDateInput): number\n/**\n * Returns the difference between 2 dates in months.\n * @param [dateA] - A date to compare with the dateB date or null to compare with the current time\n * @param dateB - A date to compare with the dateA date\n */\nexport function diffMonths(dateA: MaybeDateInput, dateB: DateInput): number\n\nexport function diffMonths(dateA: MaybeDateInput, dateB?: MaybeDateInput): number {\n const l = date(dateA)\n const r = date(dateB)\n // if the dateB one is bigger, we switch them around as it's easier to do\n if (l < r) {\n const rs = diffMonths(r, l)\n return rs == 0 ? 0 : -rs\n }\n\n // we first get the amount of calendar months\n let months = (l.getFullYear() - r.getFullYear()) * 12 + (l.getMonth() - r.getMonth())\n\n const ld = l.getDate()\n const rd = r.getDate()\n\n // if no full month has passed we may subtract a month from the calendar months so we get the amount of full months\n if (ld < rd) {\n // in case dateA date is the last day of the month & the dateB date is higher, we don't subtract as a full month did actually pass\n const lm = monthDays(l)\n if (!(lm == ld && lm < rd)) {\n months--\n }\n }\n //ensures we don't give back -0\n return months == 0 ? 0 : months\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,SAAS,iBAAiB;AAenB,SAAS,WAAW,OAAuB,OAAgC;AAChF,QAAM,IAAI,KAAK,KAAK;AACpB,QAAM,IAAI,KAAK,KAAK;AAEpB,MAAI,IAAI,GAAG;AACT,UAAM,KAAK,WAAW,GAAG,CAAC;AAC1B,WAAO,MAAM,IAAI,IAAI,CAAC;AAAA,EACxB;AAGA,MAAI,UAAU,EAAE,YAAY,IAAI,EAAE,YAAY,KAAK,MAAM,EAAE,SAAS,IAAI,EAAE,SAAS;AAEnF,QAAM,KAAK,EAAE,QAAQ;AACrB,QAAM,KAAK,EAAE,QAAQ;AAGrB,MAAI,KAAK,IAAI;AAEX,UAAM,KAAK,UAAU,CAAC;AACtB,QAAI,EAAE,MAAM,MAAM,KAAK,KAAK;AAC1B;AAAA,IACF;AAAA,EACF;AAEA,SAAO,UAAU,IAAI,IAAI;AAC3B;","names":[]}
|
package/dist/diffSeconds.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { DiffRoundingMethod } from './diffRound.js';
|
|
2
|
-
import { DateInput } from './types.js';
|
|
2
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the difference between 2 dates in seconds.
|
|
6
|
-
* @param dateA A date to compare with the right date
|
|
7
|
-
* @param dateB A date to compare with the left date
|
|
8
|
-
* @param roundingMethod the rounding method to use, default: trunc
|
|
6
|
+
* @param dateA - A date to compare with the right date
|
|
7
|
+
* @param [dateB] - A date to compare with the left date or nothing to compare with the current time.
|
|
8
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
9
9
|
*/
|
|
10
|
-
declare function diffSeconds(dateA: DateInput, dateB
|
|
10
|
+
declare function diffSeconds(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the difference between 2 dates in seconds.
|
|
13
|
+
* @param [dateA] - A date to compare with the right date or null to compare with the current time
|
|
14
|
+
* @param dateB - A date to compare with the left date
|
|
15
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
16
|
+
*/
|
|
17
|
+
declare function diffSeconds(dateA: MaybeDateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
18
|
|
|
12
19
|
export { diffSeconds };
|
package/dist/diffSeconds.mjs
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
3
|
import { diffRound } from "./diffRound.mjs";
|
|
4
4
|
function diffSeconds(dateA, dateB, roundingMethod) {
|
|
5
|
-
return diffRound(
|
|
5
|
+
return diffRound(
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
diffMilliseconds(dateA, dateB) / 1e3,
|
|
8
|
+
roundingMethod
|
|
9
|
+
);
|
|
6
10
|
}
|
|
7
11
|
export {
|
|
8
12
|
diffSeconds
|
package/dist/diffSeconds.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffSeconds.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DiffRoundingMethod, diffRound } from \"./diffRound\"\nimport { DateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in seconds.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date
|
|
1
|
+
{"version":3,"sources":["../src/diffSeconds.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DiffRoundingMethod, diffRound } from \"./diffRound\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in seconds.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time.\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffSeconds(\n dateA: DateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\n/**\n * Returns the difference between 2 dates in seconds.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffSeconds(\n dateA: MaybeDateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffSeconds(\n dateA: MaybeDateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n // @ts-ignore\n diffMilliseconds(dateA, dateB) / 1000,\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAA6B,iBAAiB;AA2BvC,SAAS,YACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA;AAAA,IAEL,iBAAiB,OAAO,KAAK,IAAI;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
package/dist/diffWeeks.d.ts
CHANGED
|
@@ -3,9 +3,16 @@ import { DiffRoundingMethod } from './diffRound.js';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the difference between 2 dates in days.
|
|
6
|
-
* @param dateA A date to compare with the right date
|
|
7
|
-
* @param dateB A date to compare with the left date
|
|
8
|
-
* @param roundingMethod the rounding method to use, default: trunc
|
|
6
|
+
* @param dateA - A date to compare with the right date
|
|
7
|
+
* @param [dateB] - A date to compare with the left date or nothing to compare with the current time
|
|
8
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
9
|
+
*/
|
|
10
|
+
declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the difference between 2 dates in days.
|
|
13
|
+
* @param [dateA] - A date to compare with the right date or null to compare with the current time
|
|
14
|
+
* @param dateB - A date to compare with the left date
|
|
15
|
+
* @param [roundingMethod] - the rounding method to use, default: trunc
|
|
9
16
|
*/
|
|
10
17
|
declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
18
|
|
package/dist/diffWeeks.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffWeeks.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DateInput } from \"./types\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in days.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date\n * @param roundingMethod the rounding method to use, default: trunc\n */\nexport function diffWeeks(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n) {\n return diffRound(\n diffMilliseconds(dateA, dateB) / 604800000, // day * 7\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,iBAA0C;
|
|
1
|
+
{"version":3,"sources":["../src/diffWeeks.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DateInput, MaybeDateInput } from \"./types\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in days.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffWeeks(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\n/**\n * Returns the difference between 2 dates in days.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffWeeks(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffWeeks(\n dateA: MaybeDateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n diffMilliseconds(dateA, dateB) / 604800000, // day * 7\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,iBAA0C;AA0B5C,SAAS,UACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
package/dist/diffYears.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { DateInput } from './types.js';
|
|
1
|
+
import { DateInput, MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns the difference between 2 dates in years.
|
|
5
|
-
* @param dateA A date to compare with the dateB date
|
|
6
|
-
* @param dateB A date to compare with the dateA date
|
|
5
|
+
* @param dateA - A date to compare with the dateB date
|
|
6
|
+
* @param [dateB] - A date to compare with the dateA date or nothing to compare with the current time
|
|
7
7
|
*/
|
|
8
|
-
declare function diffYears(dateA: DateInput, dateB
|
|
8
|
+
declare function diffYears(dateA: DateInput, dateB?: MaybeDateInput): number;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the difference between 2 dates in years.
|
|
11
|
+
* @param [dateA] - A date to compare with the dateB date or null to compare with the current time
|
|
12
|
+
* @param dateB - A date to compare with the dateA date
|
|
13
|
+
*/
|
|
14
|
+
declare function diffYears(dateA: MaybeDateInput, dateB: DateInput): number;
|
|
9
15
|
|
|
10
16
|
export { diffYears };
|
package/dist/diffYears.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// src/diffYears.ts
|
|
2
2
|
import { diffMonths } from "./diffMonths.mjs";
|
|
3
3
|
function diffYears(dateA, dateB) {
|
|
4
|
-
const r = Math.trunc(
|
|
4
|
+
const r = Math.trunc(
|
|
5
|
+
//@ts-ignore
|
|
6
|
+
diffMonths(dateA, dateB) / 12
|
|
7
|
+
);
|
|
5
8
|
return r == 0 ? 0 : r;
|
|
6
9
|
}
|
|
7
10
|
export {
|
package/dist/diffYears.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diffYears.ts"],"sourcesContent":["import { diffMonths } from \"./diffMonths\"\nimport { DateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in years.\n * @param dateA A date to compare with the dateB date\n * @param dateB A date to compare with the dateA date\n */\nexport function diffYears(dateA: DateInput, dateB: DateInput): number {\n const r = Math.trunc(diffMonths(dateA, dateB) / 12)\n //ensures we don't give back -0\n return r == 0 ? 0 : r\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;
|
|
1
|
+
{"version":3,"sources":["../src/diffYears.ts"],"sourcesContent":["import { diffMonths } from \"./diffMonths\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in years.\n * @param dateA - A date to compare with the dateB date\n * @param [dateB] - A date to compare with the dateA date or nothing to compare with the current time\n */\nexport function diffYears(dateA: DateInput, dateB?: MaybeDateInput): number\n\n/**\n * Returns the difference between 2 dates in years.\n * @param [dateA] - A date to compare with the dateB date or null to compare with the current time\n * @param dateB - A date to compare with the dateA date\n */\nexport function diffYears(dateA: MaybeDateInput, dateB: DateInput): number\nexport function diffYears(dateA: MaybeDateInput, dateB?: MaybeDateInput): number {\n const r = Math.trunc(\n //@ts-ignore\n diffMonths(dateA, dateB) / 12\n )\n //ensures we don't give back -0\n return r == 0 ? 0 : r\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAgBpB,SAAS,UAAU,OAAuB,OAAgC;AAC/E,QAAM,IAAI,KAAK;AAAA;AAAA,IAEb,WAAW,OAAO,KAAK,IAAI;AAAA,EAC7B;AAEA,SAAO,KAAK,IAAI,IAAI;AACtB;","names":[]}
|
package/dist/format.mjs
CHANGED
|
@@ -19,8 +19,7 @@ function format(inputDateOrOptions, format2 = "long", locale = "device", genitiv
|
|
|
19
19
|
tz
|
|
20
20
|
} = inputDateOrOptions);
|
|
21
21
|
}
|
|
22
|
-
if (format2 === "ISO8601")
|
|
23
|
-
return date(inputDateOrOptions).toISOString();
|
|
22
|
+
if (format2 === "ISO8601") return date(inputDateOrOptions).toISOString();
|
|
24
23
|
if (tz) {
|
|
25
24
|
forceOffset = offset(inputDateOrOptions, "utc", tz, getOffsetFormat(format2));
|
|
26
25
|
}
|
|
@@ -36,7 +35,7 @@ function format(inputDateOrOptions, format2 = "long", locale = "device", genitiv
|
|
|
36
35
|
}
|
|
37
36
|
return fill(
|
|
38
37
|
inputDateOrOptions,
|
|
39
|
-
parts(format2, locale).filter(partFilter != null ? partFilter : () => true),
|
|
38
|
+
parts(format2, locale).filter(partFilter != null ? partFilter : (() => true)),
|
|
40
39
|
locale,
|
|
41
40
|
genitive,
|
|
42
41
|
forceOffset
|
package/dist/format.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/format.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { parts } from \"./parts\"\nimport { fill, getOffsetFormat } from \"./common\"\nimport type {\n DateInput,\n Format,\n FormatOptions,\n FormatStyle,\n Part,\n} from \"./types\"\nimport { offset } from \"./offset\"\nimport { removeOffset } from \"./removeOffset\"\nimport { deviceLocale } from \"./deviceLocale\"\nimport { deviceTZ } from \"./deviceTZ\"\n\n/**\n * Produce a formatted string. Available strings:\n * token | description\n * ------|------------\n * YY | 2 digit year\n * YYYY | 4 digit year\n * M | The month 1-12\n * MM | The month 01-12\n * MMM | Short name Jan-Dec\n * MMMM | Full name January | December\n * D | The day of the month 1-31\n * DD | The day of the month 01-31\n * d | Single digit day \"T\"\n * ddd | Short day name Thu\n * dddd | Full day name Wednesday\n * H | Minimum hour digits, 24 hour, 0-23\n * HH | 2 hour digits, 24 hour, 00-23\n * h | Minimum hour digits, 12 hour clock, 1-12\n * hh | 2 hour digits, 12 hour clock, 01-12\n * m | The minute 0-59\n * mm | The minute 00-59\n * s | The second 0-59\n * ss | The second 00-59\n * a | am/pm\n * A | AM/PM\n * Z | +0800, +0530, -1345\n *\n * @param inputDate - A date object or ISO 8601 string\n * @param format - A format\n */\nexport function format(options: FormatOptions): string\nexport function format(\n inputDate: DateInput,\n format?: Format,\n locale?: string,\n genitive?: boolean,\n partFilter?: (part: Part) => boolean\n): string\nexport function format(\n inputDateOrOptions: DateInput | FormatOptions,\n format: Format = \"long\",\n locale: string | undefined = \"device\",\n genitive: boolean | undefined = false,\n partFilter?: (part: Part) => boolean\n): string {\n let tz: string | undefined, forceOffset: string | undefined\n\n if (\n typeof inputDateOrOptions === \"object\" &&\n !(inputDateOrOptions instanceof Date)\n ) {\n // Extract options from the object.\n ;({\n date: inputDateOrOptions,\n format,\n locale,\n genitive,\n partFilter,\n tz,\n } = inputDateOrOptions)\n }\n // ISO 8601 is a special case because it doesn't require a format.\n if (format === \"ISO8601\") return date(inputDateOrOptions).toISOString()\n\n if (tz) {\n forceOffset = offset(inputDateOrOptions, \"utc\", tz, getOffsetFormat(format))\n }\n\n // We need to apply an offset to the date so that it can be formatted as UTC.\n tz ??= deviceTZ()\n if (tz?.toLowerCase() !== \"utc\") {\n inputDateOrOptions = removeOffset(\n inputDateOrOptions,\n offset(inputDateOrOptions, tz, \"utc\")\n )\n }\n\n if (!locale || locale === \"device\") {\n locale = deviceLocale()\n }\n\n return fill(\n inputDateOrOptions,\n parts(format, locale).filter(partFilter ?? (() => true)),\n locale,\n genitive,\n forceOffset\n )\n .map((p) => p.value)\n .join(\"\")\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,MAAM,uBAAuB;AAQtC,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AAwClB,SAAS,OACd,oBACAA,UAAiB,QACjB,SAA6B,UAC7B,WAAgC,OAChC,YACQ;AACR,MAAI,IAAwB;AAE5B,MACE,OAAO,uBAAuB,YAC9B,EAAE,8BAA8B,OAChC;AAEA;AAAC,KAAC;AAAA,MACA,MAAM;AAAA,MACN,QAAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAAA,EACN;AAEA,MAAIA,YAAW
|
|
1
|
+
{"version":3,"sources":["../src/format.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { parts } from \"./parts\"\nimport { fill, getOffsetFormat } from \"./common\"\nimport type {\n DateInput,\n Format,\n FormatOptions,\n FormatStyle,\n Part,\n} from \"./types\"\nimport { offset } from \"./offset\"\nimport { removeOffset } from \"./removeOffset\"\nimport { deviceLocale } from \"./deviceLocale\"\nimport { deviceTZ } from \"./deviceTZ\"\n\n/**\n * Produce a formatted string. Available strings:\n * token | description\n * ------|------------\n * YY | 2 digit year\n * YYYY | 4 digit year\n * M | The month 1-12\n * MM | The month 01-12\n * MMM | Short name Jan-Dec\n * MMMM | Full name January | December\n * D | The day of the month 1-31\n * DD | The day of the month 01-31\n * d | Single digit day \"T\"\n * ddd | Short day name Thu\n * dddd | Full day name Wednesday\n * H | Minimum hour digits, 24 hour, 0-23\n * HH | 2 hour digits, 24 hour, 00-23\n * h | Minimum hour digits, 12 hour clock, 1-12\n * hh | 2 hour digits, 12 hour clock, 01-12\n * m | The minute 0-59\n * mm | The minute 00-59\n * s | The second 0-59\n * ss | The second 00-59\n * a | am/pm\n * A | AM/PM\n * Z | +0800, +0530, -1345\n *\n * @param inputDate - A date object or ISO 8601 string\n * @param format - A format\n */\nexport function format(options: FormatOptions): string\nexport function format(\n inputDate: DateInput,\n format?: Format,\n locale?: string,\n genitive?: boolean,\n partFilter?: (part: Part) => boolean\n): string\nexport function format(\n inputDateOrOptions: DateInput | FormatOptions,\n format: Format = \"long\",\n locale: string | undefined = \"device\",\n genitive: boolean | undefined = false,\n partFilter?: (part: Part) => boolean\n): string {\n let tz: string | undefined, forceOffset: string | undefined\n\n if (\n typeof inputDateOrOptions === \"object\" &&\n !(inputDateOrOptions instanceof Date)\n ) {\n // Extract options from the object.\n ;({\n date: inputDateOrOptions,\n format,\n locale,\n genitive,\n partFilter,\n tz,\n } = inputDateOrOptions)\n }\n // ISO 8601 is a special case because it doesn't require a format.\n if (format === \"ISO8601\") return date(inputDateOrOptions).toISOString()\n\n if (tz) {\n forceOffset = offset(inputDateOrOptions, \"utc\", tz, getOffsetFormat(format))\n }\n\n // We need to apply an offset to the date so that it can be formatted as UTC.\n tz ??= deviceTZ()\n if (tz?.toLowerCase() !== \"utc\") {\n inputDateOrOptions = removeOffset(\n inputDateOrOptions,\n offset(inputDateOrOptions, tz, \"utc\")\n )\n }\n\n if (!locale || locale === \"device\") {\n locale = deviceLocale()\n }\n\n return fill(\n inputDateOrOptions,\n parts(format, locale).filter(partFilter ?? (() => true)),\n locale,\n genitive,\n forceOffset\n )\n .map((p) => p.value)\n .join(\"\")\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,MAAM,uBAAuB;AAQtC,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AAwClB,SAAS,OACd,oBACAA,UAAiB,QACjB,SAA6B,UAC7B,WAAgC,OAChC,YACQ;AACR,MAAI,IAAwB;AAE5B,MACE,OAAO,uBAAuB,YAC9B,EAAE,8BAA8B,OAChC;AAEA;AAAC,KAAC;AAAA,MACA,MAAM;AAAA,MACN,QAAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAAA,EACN;AAEA,MAAIA,YAAW,UAAW,QAAO,KAAK,kBAAkB,EAAE,YAAY;AAEtE,MAAI,IAAI;AACN,kBAAc,OAAO,oBAAoB,OAAO,IAAI,gBAAgBA,OAAM,CAAC;AAAA,EAC7E;AAGA,yBAAO,SAAS;AAChB,OAAI,yBAAI,mBAAkB,OAAO;AAC/B,yBAAqB;AAAA,MACnB;AAAA,MACA,OAAO,oBAAoB,IAAI,KAAK;AAAA,IACtC;AAAA,EACF;AAEA,MAAI,CAAC,UAAU,WAAW,UAAU;AAClC,aAAS,aAAa;AAAA,EACxB;AAEA,SAAO;AAAA,IACL;AAAA,IACA,MAAMA,SAAQ,MAAM,EAAE,OAAO,mCAAe,MAAM,KAAK;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,EACF,EACG,IAAI,CAAC,MAAM,EAAE,KAAK,EAClB,KAAK,EAAE;AACZ;","names":["format"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles date overflow when changing month or year.
|
|
5
|
+
* @param [inputDate] - A string, Date object or null for the current time
|
|
6
|
+
* @param action - The action that changes the month/year
|
|
7
|
+
* @param [dateOverflow] - Whether to allow the date to overflow into another month.
|
|
8
|
+
* @returns A new Date object with the month/year change applied.
|
|
9
|
+
*/
|
|
10
|
+
declare function handleOverflow(inputDate: MaybeDateInput | undefined, action: (d: Date) => void, dateOverflow?: boolean): Date;
|
|
11
|
+
|
|
12
|
+
export { handleOverflow };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/handleDateOverflow.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
import { monthDays } from "./monthDays.mjs";
|
|
4
|
+
function handleOverflow(inputDate, action, dateOverflow = false) {
|
|
5
|
+
const d = date(inputDate);
|
|
6
|
+
const dayOfMonth = d.getDate();
|
|
7
|
+
if (!dateOverflow) d.setDate(1);
|
|
8
|
+
action(d);
|
|
9
|
+
if (!dateOverflow) {
|
|
10
|
+
const daysInMonth = monthDays(d);
|
|
11
|
+
d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth);
|
|
12
|
+
}
|
|
13
|
+
return d;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
handleOverflow
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=handleDateOverflow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handleDateOverflow.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Handles date overflow when changing month or year.\n * @param [inputDate] - A string, Date object or null for the current time\n * @param action - The action that changes the month/year\n * @param [dateOverflow] - Whether to allow the date to overflow into another month.\n * @returns A new Date object with the month/year change applied.\n */\nexport function handleOverflow(\n inputDate: MaybeDateInput | undefined,\n action: (d: Date) => void,\n dateOverflow = false\n): Date {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n\n action(d)\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAUnB,SAAS,eACd,WACA,QACA,eAAe,OACT;AACN,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC,aAAc,GAAE,QAAQ,CAAC;AAE9B,SAAO,CAAC;AAGR,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
|
package/dist/hourEnd.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a Date object for end of the given hour.
|
|
5
|
-
* @param inputDate - A string or
|
|
5
|
+
* @param [inputDate] - A string, Date object or nothing for the current time
|
|
6
6
|
*/
|
|
7
|
-
declare function hourEnd(inputDate
|
|
7
|
+
declare function hourEnd(inputDate?: MaybeDateInput): Date;
|
|
8
8
|
|
|
9
9
|
export { hourEnd };
|
package/dist/hourEnd.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hourEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/hourEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given hour.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function hourEnd(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setMinutes(59, 59, 999)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,QAAQ,WAAkC;AACxD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,IAAI,IAAI,GAAG;AACxB,SAAO;AACT;","names":[]}
|
package/dist/hourStart.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeDateInput } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a Date object for start of the given hour.
|
|
5
|
-
* @param inputDate - A string or
|
|
5
|
+
* @param [inputDate] - A string, Date object or nothing for the current time
|
|
6
6
|
*/
|
|
7
|
-
declare function hourStart(inputDate
|
|
7
|
+
declare function hourStart(inputDate?: MaybeDateInput): Date;
|
|
8
8
|
|
|
9
9
|
export { hourStart };
|
package/dist/hourStart.mjs
CHANGED
package/dist/hourStart.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hourStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/hourStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given hour.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function hourStart(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setMinutes(0, 0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAkC;AAC1D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,GAAG,GAAG,CAAC;AACpB,SAAO;AACT;","names":[]}
|