@formkit/tempo 0.0.19 → 0.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/dist/addDay.d.ts +9 -0
- package/dist/addDay.mjs +11 -0
- package/dist/addDay.mjs.map +1 -0
- package/dist/addHour.d.ts +9 -0
- package/dist/addHour.mjs +11 -0
- package/dist/addHour.mjs.map +1 -0
- package/dist/addMinute.d.ts +9 -0
- package/dist/addMinute.mjs +11 -0
- package/dist/addMinute.mjs.map +1 -0
- package/dist/addMonth.d.ts +13 -0
- package/dist/addMonth.mjs +19 -0
- package/dist/addMonth.mjs.map +1 -0
- package/dist/addSecond.d.ts +9 -0
- package/dist/addSecond.mjs +11 -0
- package/dist/addSecond.mjs.map +1 -0
- package/dist/addYear.d.ts +13 -0
- package/dist/addYear.mjs +19 -0
- package/dist/addYear.mjs.map +1 -0
- package/dist/ap.d.ts +8 -0
- package/dist/ap.mjs +28 -0
- package/dist/ap.mjs.map +1 -0
- package/dist/applyOffset.d.ts +11 -0
- package/dist/applyOffset.mjs +20 -0
- package/dist/applyOffset.mjs.map +1 -0
- package/dist/bundle.mjs +1215 -0
- package/dist/bundle.mjs.map +1 -0
- package/dist/common.d.ts +137 -0
- package/dist/common.mjs +252 -0
- package/dist/common.mjs.map +1 -0
- package/dist/date.d.ts +9 -0
- package/dist/date.mjs +28 -0
- package/dist/date.mjs.map +1 -0
- package/dist/dayEnd.d.ts +9 -0
- package/dist/dayEnd.mjs +11 -0
- package/dist/dayEnd.mjs.map +1 -0
- package/dist/dayOfYear.d.ts +10 -0
- package/dist/dayOfYear.mjs +12 -0
- package/dist/dayOfYear.mjs.map +1 -0
- package/dist/dayStart.d.ts +9 -0
- package/dist/dayStart.mjs +11 -0
- package/dist/dayStart.mjs.map +1 -0
- package/dist/deviceLocale.d.ts +7 -0
- package/dist/deviceLocale.mjs +8 -0
- package/dist/deviceLocale.mjs.map +1 -0
- package/dist/deviceTZ.d.ts +8 -0
- package/dist/deviceTZ.mjs +8 -0
- package/dist/deviceTZ.mjs.map +1 -0
- package/dist/diffDays.d.ts +12 -0
- package/dist/diffDays.mjs +14 -0
- package/dist/diffDays.mjs.map +1 -0
- package/dist/diffHours.d.ts +12 -0
- package/dist/diffHours.mjs +14 -0
- package/dist/diffHours.mjs.map +1 -0
- package/dist/diffMilliseconds.d.ts +10 -0
- package/dist/diffMilliseconds.mjs +11 -0
- package/dist/diffMilliseconds.mjs.map +1 -0
- package/dist/diffMinutes.d.ts +11 -0
- package/dist/diffMinutes.mjs +10 -0
- package/dist/diffMinutes.mjs.map +1 -0
- package/dist/diffMonths.d.ts +10 -0
- package/dist/diffMonths.mjs +25 -0
- package/dist/diffMonths.mjs.map +1 -0
- package/dist/diffRound.d.ts +9 -0
- package/dist/diffRound.mjs +9 -0
- package/dist/diffRound.mjs.map +1 -0
- package/dist/diffSeconds.d.ts +12 -0
- package/dist/diffSeconds.mjs +10 -0
- package/dist/diffSeconds.mjs.map +1 -0
- package/dist/diffWeeks.d.ts +12 -0
- package/dist/diffWeeks.mjs +14 -0
- package/dist/diffWeeks.mjs.map +1 -0
- package/dist/diffYears.d.ts +10 -0
- package/dist/diffYears.mjs +10 -0
- package/dist/diffYears.mjs.map +1 -0
- package/dist/format.d.ts +36 -0
- package/dist/format.mjs +48 -0
- package/dist/format.mjs.map +1 -0
- package/dist/formatStr.d.ts +13 -0
- package/dist/formatStr.mjs +13 -0
- package/dist/formatStr.mjs.map +1 -0
- package/dist/fourDigitYear.d.ts +10 -0
- package/dist/fourDigitYear.mjs +12 -0
- package/dist/fourDigitYear.mjs.map +1 -0
- package/dist/hourEnd.d.ts +9 -0
- package/dist/hourEnd.mjs +11 -0
- package/dist/hourEnd.mjs.map +1 -0
- package/dist/hourStart.d.ts +9 -0
- package/dist/hourStart.mjs +11 -0
- package/dist/hourStart.mjs.map +1 -0
- package/dist/index.cjs +139 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -4
- package/dist/index.d.ts +54 -498
- package/dist/index.mjs +62 -1057
- package/dist/index.mjs.map +1 -1
- package/dist/isAfter.d.ts +18 -0
- package/dist/isAfter.mjs +11 -0
- package/dist/isAfter.mjs.map +1 -0
- package/dist/isBefore.d.ts +13 -0
- package/dist/isBefore.mjs +11 -0
- package/dist/isBefore.mjs.map +1 -0
- package/dist/isEqual.d.ts +13 -0
- package/dist/isEqual.mjs +11 -0
- package/dist/isEqual.mjs.map +1 -0
- package/dist/iso8601.d.ts +13 -0
- package/dist/iso8601.mjs +27 -0
- package/dist/iso8601.mjs.map +1 -0
- package/dist/minuteEnd.d.ts +9 -0
- package/dist/minuteEnd.mjs +11 -0
- package/dist/minuteEnd.mjs.map +1 -0
- package/dist/minuteStart.d.ts +9 -0
- package/dist/minuteStart.mjs +11 -0
- package/dist/minuteStart.mjs.map +1 -0
- package/dist/monthDays.d.ts +9 -0
- package/dist/monthDays.mjs +10 -0
- package/dist/monthDays.mjs.map +1 -0
- package/dist/monthEnd.d.ts +10 -0
- package/dist/monthEnd.mjs +13 -0
- package/dist/monthEnd.mjs.map +1 -0
- package/dist/monthStart.d.ts +9 -0
- package/dist/monthStart.mjs +12 -0
- package/dist/monthStart.mjs.map +1 -0
- package/dist/nearestDay.d.ts +12 -0
- package/dist/nearestDay.mjs +46 -0
- package/dist/nearestDay.mjs.map +1 -0
- package/dist/offset.d.ts +14 -0
- package/dist/offset.mjs +36 -0
- package/dist/offset.mjs.map +1 -0
- package/dist/parse.d.ts +13 -0
- package/dist/parse.mjs +163 -0
- package/dist/parse.mjs.map +1 -0
- package/dist/parts.d.ts +12 -0
- package/dist/parts.mjs +214 -0
- package/dist/parts.mjs.map +1 -0
- package/dist/range.d.ts +10 -0
- package/dist/range.mjs +50 -0
- package/dist/range.mjs.map +1 -0
- package/dist/removeOffset.d.ts +10 -0
- package/dist/removeOffset.mjs +13 -0
- package/dist/removeOffset.mjs.map +1 -0
- package/dist/sameDay.d.ts +10 -0
- package/dist/sameDay.mjs +11 -0
- package/dist/sameDay.mjs.map +1 -0
- package/dist/sameHour.d.ts +10 -0
- package/dist/sameHour.mjs +11 -0
- package/dist/sameHour.mjs.map +1 -0
- package/dist/sameMinute.d.ts +10 -0
- package/dist/sameMinute.mjs +11 -0
- package/dist/sameMinute.mjs.map +1 -0
- package/dist/sameSecond.d.ts +10 -0
- package/dist/sameSecond.mjs +11 -0
- package/dist/sameSecond.mjs.map +1 -0
- package/dist/sameYear.d.ts +10 -0
- package/dist/sameYear.mjs +11 -0
- package/dist/sameYear.mjs.map +1 -0
- package/dist/types.d.ts +143 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +1 -0
- package/dist/tzDate.d.ts +15 -0
- package/dist/tzDate.mjs +12 -0
- package/dist/tzDate.mjs.map +1 -0
- package/dist/weekEnd.d.ts +12 -0
- package/dist/weekEnd.mjs +12 -0
- package/dist/weekEnd.mjs.map +1 -0
- package/dist/weekStart.d.ts +12 -0
- package/dist/weekStart.mjs +15 -0
- package/dist/weekStart.mjs.map +1 -0
- package/dist/yearDays.d.ts +9 -0
- package/dist/yearDays.mjs +10 -0
- package/dist/yearDays.mjs.map +1 -0
- package/dist/yearEnd.d.ts +9 -0
- package/dist/yearEnd.mjs +13 -0
- package/dist/yearEnd.mjs.map +1 -0
- package/dist/yearStart.d.ts +9 -0
- package/dist/yearStart.mjs +13 -0
- package/dist/yearStart.mjs.map +1 -0
- package/package.json +8 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/sameHour.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function sameHour(inputDateA, inputDateB) {
|
|
4
|
+
const a = date(inputDateA);
|
|
5
|
+
const b = date(inputDateB);
|
|
6
|
+
return a.getHours() === b.getHours();
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
sameHour
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=sameHour.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sameHour.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Checks if two date objects refer to the same time hour. Ignores date.\n * @param inputDateA - First date to compare\n * @param inputDateB - Second date to compare\n */\nexport function sameHour(inputDateA: DateInput, inputDateB: DateInput) {\n const a = date(inputDateA)\n const b = date(inputDateB)\n return a.getHours() === b.getHours()\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,SAAS,YAAuB,YAAuB;AACrE,QAAM,IAAI,KAAK,UAAU;AACzB,QAAM,IAAI,KAAK,UAAU;AACzB,SAAO,EAAE,SAAS,MAAM,EAAE,SAAS;AACrC;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if two date objects refer to the same time minutes. Ignores date.
|
|
5
|
+
* @param inputDateA - First date to compare
|
|
6
|
+
* @param inputDateB - Second date to compare
|
|
7
|
+
*/
|
|
8
|
+
declare function sameMinute(inputDateA: DateInput, inputDateB: DateInput): boolean;
|
|
9
|
+
|
|
10
|
+
export { sameMinute };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/sameMinute.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function sameMinute(inputDateA, inputDateB) {
|
|
4
|
+
const a = date(inputDateA);
|
|
5
|
+
const b = date(inputDateB);
|
|
6
|
+
return a.getMinutes() === b.getMinutes();
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
sameMinute
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=sameMinute.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sameMinute.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Checks if two date objects refer to the same time minutes. Ignores date.\n * @param inputDateA - First date to compare\n * @param inputDateB - Second date to compare\n */\nexport function sameMinute(inputDateA: DateInput, inputDateB: DateInput) {\n const a = date(inputDateA)\n const b = date(inputDateB)\n return a.getMinutes() === b.getMinutes()\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,WAAW,YAAuB,YAAuB;AACvE,QAAM,IAAI,KAAK,UAAU;AACzB,QAAM,IAAI,KAAK,UAAU;AACzB,SAAO,EAAE,WAAW,MAAM,EAAE,WAAW;AACzC;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if two date objects refer to the same time seconds. Ignores date.
|
|
5
|
+
* @param inputDateA - First date to compare
|
|
6
|
+
* @param inputDateB - Second date to compare
|
|
7
|
+
*/
|
|
8
|
+
declare function sameSecond(inputDateA: DateInput, inputDateB: DateInput): boolean;
|
|
9
|
+
|
|
10
|
+
export { sameSecond };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/sameSecond.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function sameSecond(inputDateA, inputDateB) {
|
|
4
|
+
const a = date(inputDateA);
|
|
5
|
+
const b = date(inputDateB);
|
|
6
|
+
return a.getSeconds() === b.getSeconds();
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
sameSecond
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=sameSecond.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sameSecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Checks if two date objects refer to the same time seconds. Ignores date.\n * @param inputDateA - First date to compare\n * @param inputDateB - Second date to compare\n */\nexport function sameSecond(inputDateA: DateInput, inputDateB: DateInput) {\n const a = date(inputDateA)\n const b = date(inputDateB)\n return a.getSeconds() === b.getSeconds()\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,WAAW,YAAuB,YAAuB;AACvE,QAAM,IAAI,KAAK,UAAU;AACzB,QAAM,IAAI,KAAK,UAAU;AACzB,SAAO,EAAE,WAAW,MAAM,EAAE,WAAW;AACzC;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if two date objects refer to the same year.
|
|
5
|
+
* @param inputDateA - First date to compare
|
|
6
|
+
* @param inputDateB - Second date to compare
|
|
7
|
+
*/
|
|
8
|
+
declare function sameYear(inputDateA: DateInput, inputDateB: DateInput): boolean;
|
|
9
|
+
|
|
10
|
+
export { sameYear };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/sameYear.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function sameYear(inputDateA, inputDateB) {
|
|
4
|
+
const a = date(inputDateA);
|
|
5
|
+
const b = date(inputDateB);
|
|
6
|
+
return a.getFullYear() === b.getFullYear();
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
sameYear
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=sameYear.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sameYear.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Checks if two date objects refer to the same year.\n * @param inputDateA - First date to compare\n * @param inputDateB - Second date to compare\n */\nexport function sameYear(inputDateA: DateInput, inputDateB: DateInput) {\n const a = date(inputDateA)\n const b = date(inputDateB)\n return a.getFullYear() === b.getFullYear()\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,SAAS,YAAuB,YAAuB;AACrE,QAAM,IAAI,KAAK,UAAU;AACzB,QAAM,IAAI,KAAK,UAAU;AACzB,SAAO,EAAE,YAAY,MAAM,EAAE,YAAY;AAC3C;","names":[]}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The date format used as an input value. Either a date or an ISO8601 string.
|
|
3
|
+
*/
|
|
4
|
+
type DateInput = Date | string;
|
|
5
|
+
/**
|
|
6
|
+
* Format parts with text names use these descriptors:
|
|
7
|
+
*/
|
|
8
|
+
type NamedFormatOption = "long" | "short" | "narrow";
|
|
9
|
+
/**
|
|
10
|
+
* A registry of named format parts. Each type of part has every option.
|
|
11
|
+
*/
|
|
12
|
+
interface NamedFormats {
|
|
13
|
+
weekday: Record<string, NamedFormatOption>;
|
|
14
|
+
month: Record<string, NamedFormatOption>;
|
|
15
|
+
dayPeriod: Record<string, NamedFormatOption>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Internal format for "pieces" of a date form. Each part represents a single
|
|
19
|
+
* logical grouping, like "month", or "seconds".
|
|
20
|
+
*/
|
|
21
|
+
interface Part {
|
|
22
|
+
/**
|
|
23
|
+
* An object of partName to partValue For example:
|
|
24
|
+
* ```js
|
|
25
|
+
* { hour: '2-digit' }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
option: FormatPattern[1];
|
|
29
|
+
/**
|
|
30
|
+
* The name of the part, these must be valid parts of a date format as
|
|
31
|
+
* specified in Intl.DateTimeFormatPartTypes. Valid values are:
|
|
32
|
+
* day, dayPeriod, era, hour, literal, minute, month, second, timeZoneName,
|
|
33
|
+
* weekday, year
|
|
34
|
+
*/
|
|
35
|
+
partName: Intl.DateTimeFormatPartTypes;
|
|
36
|
+
/**
|
|
37
|
+
* The value of a given part. For example "2-digit", or "narrow".
|
|
38
|
+
*/
|
|
39
|
+
partValue: string;
|
|
40
|
+
/**
|
|
41
|
+
* The string token that represents the regex. For example "YYYY".
|
|
42
|
+
*/
|
|
43
|
+
token: string;
|
|
44
|
+
/**
|
|
45
|
+
* A regular expression if the above token.
|
|
46
|
+
*/
|
|
47
|
+
pattern: RegExp;
|
|
48
|
+
/**
|
|
49
|
+
* Does this part require a the hour12 clock.
|
|
50
|
+
*/
|
|
51
|
+
hour12: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A date part with an actual value applied.
|
|
55
|
+
*/
|
|
56
|
+
type FilledPart = Part & {
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A tuple describing a given formatting token.
|
|
61
|
+
*/
|
|
62
|
+
type FormatPattern = [
|
|
63
|
+
pattern: FormatToken | string,
|
|
64
|
+
option: Partial<Record<Intl.DateTimeFormatPartTypes, string>>,
|
|
65
|
+
exp?: RegExp
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* Possible options for a format style.
|
|
69
|
+
*/
|
|
70
|
+
type FormatStyle = "full" | "long" | "medium" | "short";
|
|
71
|
+
/**
|
|
72
|
+
* Possible objects for the dateStyle and timeStyle.
|
|
73
|
+
*/
|
|
74
|
+
type FormatStyleObj = {
|
|
75
|
+
date: FormatStyle;
|
|
76
|
+
time: FormatStyle;
|
|
77
|
+
} | {
|
|
78
|
+
date: FormatStyle;
|
|
79
|
+
} | {
|
|
80
|
+
time: FormatStyle;
|
|
81
|
+
};
|
|
82
|
+
type Format = FormatStyle | FormatStyleObj | string;
|
|
83
|
+
/**
|
|
84
|
+
* A union of all available formatting tokens.
|
|
85
|
+
*/
|
|
86
|
+
type FormatToken = "YYYY" | "YY" | "MMMM" | "MMM" | "MM" | "M" | "DD" | "D" | "dddd" | "ddd" | "d" | "mm" | "m" | "ss" | "s" | "HH" | "H" | "hh" | "h" | "a" | "A" | "ZZ" | "Z";
|
|
87
|
+
interface ParseOptions {
|
|
88
|
+
/**
|
|
89
|
+
* A string representing a date.
|
|
90
|
+
*/
|
|
91
|
+
date: string;
|
|
92
|
+
/**
|
|
93
|
+
* The format that should be used to parse the date. This is a string composed
|
|
94
|
+
* of tokens.
|
|
95
|
+
*/
|
|
96
|
+
format: Format;
|
|
97
|
+
/**
|
|
98
|
+
* The locale used to parse the date.
|
|
99
|
+
*/
|
|
100
|
+
locale: string;
|
|
101
|
+
/**
|
|
102
|
+
* A function that can be used to filter out parts of the format. This is
|
|
103
|
+
* useful when using the native Intl formats like
|
|
104
|
+
* `{ date: 'full', time: 'full' }` and not wanting to keep all the parts of
|
|
105
|
+
* the given format.
|
|
106
|
+
*/
|
|
107
|
+
partFilter?: (part: Part) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* The behavior to use when a date overflows a given month. For example, if
|
|
110
|
+
* the date to parse is February 29, 2023 — there is no 29th day of February.
|
|
111
|
+
* In this case overflow "forward" would result in March 1, 2023, "backward"
|
|
112
|
+
* would result in February 28, 2023, and "throw" would throw an error.
|
|
113
|
+
*/
|
|
114
|
+
dateOverflow?: "forward" | "backward" | "throw";
|
|
115
|
+
}
|
|
116
|
+
interface FormatOptions {
|
|
117
|
+
/**
|
|
118
|
+
* A date object or ISO 8601 string.
|
|
119
|
+
*/
|
|
120
|
+
date: DateInput;
|
|
121
|
+
/**
|
|
122
|
+
* A format string or object.
|
|
123
|
+
*/
|
|
124
|
+
format: Format;
|
|
125
|
+
/**
|
|
126
|
+
* A locale or en by default.
|
|
127
|
+
*/
|
|
128
|
+
locale?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Whether or not to escape literals.
|
|
131
|
+
*/
|
|
132
|
+
genitive?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* A function to filter parts.
|
|
135
|
+
*/
|
|
136
|
+
tz?: string;
|
|
137
|
+
/**
|
|
138
|
+
* A function to filter parts.
|
|
139
|
+
*/
|
|
140
|
+
partFilter?: (part: Part) => boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type { DateInput, FilledPart, Format, FormatOptions, FormatPattern, FormatStyle, FormatStyleObj, FormatToken, NamedFormatOption, NamedFormats, ParseOptions, Part };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/tzDate.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a date object for the input date at the given timezone. For example
|
|
5
|
+
* `tzDate("2017-05-06T12:00", "Europe/Amsterdam")` will return a date object
|
|
6
|
+
* for 2017-05-06T10:00:00Z since 12:00 in Amsterdam is 10:00Z.
|
|
7
|
+
*
|
|
8
|
+
* If given a Date object it will use local time and convert it to the given
|
|
9
|
+
* timezone, thus "changing" the date.
|
|
10
|
+
* @param inputDate - An iso8601 date string with no timezone
|
|
11
|
+
* @param tz - A timezone string
|
|
12
|
+
*/
|
|
13
|
+
declare function tzDate(inputDate: DateInput, tz: string): Date;
|
|
14
|
+
|
|
15
|
+
export { tzDate };
|
package/dist/tzDate.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/tzDate.ts
|
|
2
|
+
import { offset } from "./offset.mjs";
|
|
3
|
+
import { applyOffset } from "./applyOffset.mjs";
|
|
4
|
+
import { date } from "./date.mjs";
|
|
5
|
+
function tzDate(inputDate, tz) {
|
|
6
|
+
const d = date(inputDate);
|
|
7
|
+
return applyOffset(d, offset(d, tz));
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
tzDate
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=tzDate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tzDate.ts"],"sourcesContent":["import { offset } from \"./offset\"\nimport { applyOffset } from \"./applyOffset\"\nimport { date } from \"./date\"\nimport { DateInput } from \"./types\"\n\n/**\n * Creates a date object for the input date at the given timezone. For example\n * `tzDate(\"2017-05-06T12:00\", \"Europe/Amsterdam\")` will return a date object\n * for 2017-05-06T10:00:00Z since 12:00 in Amsterdam is 10:00Z.\n *\n * If given a Date object it will use local time and convert it to the given\n * timezone, thus \"changing\" the date.\n * @param inputDate - An iso8601 date string with no timezone\n * @param tz - A timezone string\n */\nexport function tzDate(inputDate: DateInput, tz: string) {\n const d = date(inputDate)\n return applyOffset(d, offset(d, tz))\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,YAAY;AAad,SAAS,OAAO,WAAsB,IAAY;AACvD,QAAM,IAAI,KAAK,SAAS;AACxB,SAAO,YAAY,GAAG,OAAO,GAAG,EAAE,CAAC;AACrC;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a Date object for the last day at the last second of the given week.
|
|
5
|
+
* Defaults to Sunday as the first day of the week:
|
|
6
|
+
* 0 = Sunday ... 6 = Saturday
|
|
7
|
+
* @param inputDate - Gets the last day of the week
|
|
8
|
+
* @param startOfWeekDay - The first day of the week
|
|
9
|
+
*/
|
|
10
|
+
declare function weekEnd(inputDate: DateInput, startOfWeekDay?: number): Date;
|
|
11
|
+
|
|
12
|
+
export { weekEnd };
|
package/dist/weekEnd.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/weekEnd.ts
|
|
2
|
+
import { weekStart } from "./weekStart.mjs";
|
|
3
|
+
function weekEnd(inputDate, startOfWeekDay = 0) {
|
|
4
|
+
const d = weekStart(inputDate, startOfWeekDay);
|
|
5
|
+
d.setDate(d.getDate() + 6);
|
|
6
|
+
d.setHours(23, 59, 59);
|
|
7
|
+
return d;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
weekEnd
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=weekEnd.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/weekEnd.ts"],"sourcesContent":["import { weekStart } from \"./weekStart\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for the last day at the last second of the given week.\n * Defaults to Sunday as the first day of the week:\n * 0 = Sunday ... 6 = Saturday\n * @param inputDate - Gets the last day of the week\n * @param startOfWeekDay - The first day of the week\n */\nexport function weekEnd(inputDate: DateInput, startOfWeekDay = 0): Date {\n const d = weekStart(inputDate, startOfWeekDay)\n d.setDate(d.getDate() + 6)\n d.setHours(23, 59, 59)\n return d\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAUnB,SAAS,QAAQ,WAAsB,iBAAiB,GAAS;AACtE,QAAM,IAAI,UAAU,WAAW,cAAc;AAC7C,IAAE,QAAQ,EAAE,QAAQ,IAAI,CAAC;AACzB,IAAE,SAAS,IAAI,IAAI,EAAE;AACrB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a Date object for start of the given week. Defaults to Sunday as the
|
|
5
|
+
* first day of the week:
|
|
6
|
+
* 0 = Sunday ... 6 = Saturday
|
|
7
|
+
* @param inputDate - A string or Date object
|
|
8
|
+
* @param startOfWeekDay - Determines which day of the week is the first
|
|
9
|
+
*/
|
|
10
|
+
declare function weekStart(inputDate: DateInput, startOfWeekDay?: number): Date;
|
|
11
|
+
|
|
12
|
+
export { weekStart };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/weekStart.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function weekStart(inputDate, startOfWeekDay = 0) {
|
|
4
|
+
const d = date(inputDate);
|
|
5
|
+
let diff = startOfWeekDay - d.getDay();
|
|
6
|
+
if (diff > 0)
|
|
7
|
+
diff = diff - 7;
|
|
8
|
+
d.setDate(d.getDate() + diff);
|
|
9
|
+
d.setHours(0, 0, 0);
|
|
10
|
+
return d;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
weekStart
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=weekStart.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/weekStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given week. Defaults to Sunday as the\n * first day of the week:\n * 0 = Sunday ... 6 = Saturday\n * @param inputDate - A string or Date object\n * @param startOfWeekDay - Determines which day of the week is the first\n */\nexport function weekStart(inputDate: DateInput, startOfWeekDay = 0): Date {\n const d = date(inputDate)\n let diff = startOfWeekDay - d.getDay()\n if (diff > 0) diff = diff - 7\n d.setDate(d.getDate() + diff)\n d.setHours(0, 0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAUd,SAAS,UAAU,WAAsB,iBAAiB,GAAS;AACxE,QAAM,IAAI,KAAK,SAAS;AACxB,MAAI,OAAO,iBAAiB,EAAE,OAAO;AACrC,MAAI,OAAO;AAAG,WAAO,OAAO;AAC5B,IAAE,QAAQ,EAAE,QAAQ,IAAI,IAAI;AAC5B,IAAE,SAAS,GAAG,GAAG,CAAC;AAClB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/yearDays.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function yearDays(inputDate) {
|
|
4
|
+
const d = date(inputDate);
|
|
5
|
+
return (new Date(d.getFullYear() + 1, 0, 0).getTime() - new Date(d.getFullYear(), 0, 0).getTime()) / 864e5;
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
yearDays
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=yearDays.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/yearDays.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Get the number of days in the given date’s year.\n * @param inputDate - A string or Date object\n */\nexport function yearDays(inputDate: DateInput): number {\n const d = date(inputDate)\n return (\n (new Date(d.getFullYear() + 1, 0, 0).getTime() -\n new Date(d.getFullYear(), 0, 0).getTime()) /\n 86400000\n )\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,SAAS,WAA8B;AACrD,QAAM,IAAI,KAAK,SAAS;AACxB,UACG,IAAI,KAAK,EAAE,YAAY,IAAI,GAAG,GAAG,CAAC,EAAE,QAAQ,IAC3C,IAAI,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,EAAE,QAAQ,KAC1C;AAEJ;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a Date object for the with the input date set to the end of the current year.
|
|
5
|
+
* @param inputDate - A string or Date object
|
|
6
|
+
*/
|
|
7
|
+
declare function yearEnd(inputDate: DateInput): Date;
|
|
8
|
+
|
|
9
|
+
export { yearEnd };
|
package/dist/yearEnd.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/yearEnd.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function yearEnd(inputDate) {
|
|
4
|
+
const d = date(inputDate);
|
|
5
|
+
d.setMonth(11);
|
|
6
|
+
d.setDate(31);
|
|
7
|
+
d.setHours(23, 59, 59, 999);
|
|
8
|
+
return d;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
yearEnd
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=yearEnd.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/yearEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for the with the input date set to the end of the current year.\n * @param inputDate - A string or Date object\n */\nexport function yearEnd(inputDate: DateInput): Date {\n const d = date(inputDate);\n\n d.setMonth(11);\n d.setDate(31);\n d.setHours(23, 59, 59, 999);\n\n return d;\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,QAAQ,WAA4B;AAClD,QAAM,IAAI,KAAK,SAAS;AAExB,IAAE,SAAS,EAAE;AACb,IAAE,QAAQ,EAAE;AACZ,IAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAE1B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a Date object for the with the input date set to the start of the current year.
|
|
5
|
+
* @param inputDate - A string or Date object
|
|
6
|
+
*/
|
|
7
|
+
declare function yearStart(inputDate: DateInput): Date;
|
|
8
|
+
|
|
9
|
+
export { yearStart };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/yearStart.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function yearStart(inputDate) {
|
|
4
|
+
const d = date(inputDate);
|
|
5
|
+
d.setMonth(0);
|
|
6
|
+
d.setDate(1);
|
|
7
|
+
d.setHours(0, 0, 0);
|
|
8
|
+
return d;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
yearStart
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=yearStart.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/yearStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for the with the input date set to the start of the current year.\n * @param inputDate - A string or Date object\n */\nexport function yearStart(inputDate: DateInput): Date {\n const d = date(inputDate)\n\n d.setMonth(0)\n d.setDate(1)\n d.setHours(0, 0, 0)\n\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAA4B;AACpD,QAAM,IAAI,KAAK,SAAS;AAExB,IAAE,SAAS,CAAC;AACZ,IAAE,QAAQ,CAAC;AACX,IAAE,SAAS,GAAG,GAAG,CAAC;AAElB,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formkit/tempo",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "The easiest way to work with dates in JavaScript and TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
8
|
+
"browser": "dist/bundle.mjs",
|
|
9
|
+
"unpkg": "dist/bundle.mjs",
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
10
12
|
"import": {
|
|
@@ -14,6 +16,10 @@
|
|
|
14
16
|
"require": {
|
|
15
17
|
"types": "./dist/index.d.cts",
|
|
16
18
|
"default": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"browser": {
|
|
21
|
+
"types": "./dist/bundle.d.ts",
|
|
22
|
+
"default": "./dist/bundle.mjs"
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
25
|
},
|
|
@@ -37,6 +43,7 @@
|
|
|
37
43
|
"@types/node": "^20.11.10",
|
|
38
44
|
"bumpp": "^9.3.0",
|
|
39
45
|
"bytes-iec": "^3.1.1",
|
|
46
|
+
"esbuild-plugin-file-path-extensions": "^2.0.0",
|
|
40
47
|
"publint": "^0.2.7",
|
|
41
48
|
"size-limit": "^11.0.2",
|
|
42
49
|
"tsup": "^8.0.1",
|