@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 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { ap } from \"./ap\"\nimport type {\n DateInput,\n NamedFormats,\n FormatPattern,\n FormatStyle,\n Part,\n FilledPart,\n Format,\n} from \"./types\"\n\n/**\n * A date to use for determining various spec details.\n */\nexport const specDate = \"1999-03-04T02:05:01.000Z\"\n\n/**\n * A cache of Intl tokens and their respective formats.\n */\nexport const memoParts: Map<string, NamedFormats> = new Map()\n\n/**\n * Clock agnostic time format patterns.\n */\nexport const clockAgnostic: FormatPattern[] = [\n [\"YYYY\", { year: \"numeric\" }],\n [\"YY\", { year: \"2-digit\" }],\n [\"MMMM\", { month: \"long\" }],\n [\"MMM\", { month: \"short\" }],\n [\"MM\", { month: \"2-digit\" }],\n [\"M\", { month: \"numeric\" }],\n [\"DD\", { day: \"2-digit\" }],\n [\"D\", { day: \"numeric\" }],\n [\"dddd\", { weekday: \"long\" }],\n [\"ddd\", { weekday: \"short\" }],\n [\"d\", { weekday: \"narrow\" }],\n [\"mm\", { minute: \"2-digit\" }],\n [\"m\", { minute: \"numeric\" }],\n [\"ss\", { second: \"2-digit\" }],\n [\"s\", { second: \"numeric\" }],\n [\"ZZ\", { timeZoneName: \"long\" }],\n [\"Z\", { timeZoneName: \"short\" }],\n]\n\n/**\n * Timezone tokens.\n */\nconst timeZoneTokens = [\"Z\", \"ZZ\"] as const\n\n/**\n * Timezone token type.\n */\nexport type TimezoneToken = (typeof timeZoneTokens)[number]\n\n/**\n * 24 hour click format patterns.\n */\nexport const clock24: FormatPattern[] = [\n [\"HH\", { hour: \"2-digit\" }],\n [\"H\", { hour: \"numeric\" }],\n]\n\n/**\n * 12 hour format patterns.\n */\nexport const clock12: FormatPattern[] = [\n [\"hh\", { hour: \"2-digit\" }],\n [\"h\", { hour: \"numeric\" }],\n [\"a\", { dayPeriod: \"narrow\" }],\n [\"A\", { dayPeriod: \"narrow\" }],\n]\n\n/**\n * Tokens that have a fixed length.\n */\nexport const fixedLength = {\n DD: 2,\n HH: 2,\n MM: 2,\n YY: 2,\n YYYY: 4,\n hh: 2,\n mm: 2,\n ss: 2,\n}\n\n/**\n * token Z can have variable length depending on the actual value, so it's\n */\nexport function fixedLengthByOffset(offsetString: string): 6 | 5 {\n // starts with [+-]xx:xx\n if (/^[+-]\\d{2}:\\d{2}/.test(offsetString)) {\n return 6\n }\n\n // starts with [+-]xxxx\n if (/^[+-]\\d{4}/.test(offsetString)) {\n return 5\n }\n\n throw new Error(\"Invalid offset format\")\n}\n\n/**\n * Tokens that are genitive — in that they can have \"possession\" when used in\n * a date phrase, \"March’s 4th day\" (but not in english).\n *\n * When computing a range for these, the range can be either genitive or not.\n * The same is true for parsing dates containing these tokens.\n */\nexport const genitiveTokens = [\"MMMM\", \"MMM\", \"dddd\", \"ddd\"]\n\n/**\n * A map of FormatPattern tuples to their respective token.\n */\nexport const tokens = /* @__PURE__ */ new Map(\n /* @__PURE__ */ [...clockAgnostic, ...clock24, ...clock12].map((format) => {\n return [format[0], format]\n })\n)\n\n/**\n * A map of locale’s am/pm.\n */\nexport const dayPeriodMap: Map<string, { am?: string; pm?: string }> = new Map()\n\n/**\n * An array of all available date styles.\n */\nexport const styles: ReadonlyArray<FormatStyle> = [\n \"full\",\n \"long\",\n \"medium\",\n \"short\",\n]\n\n/**\n * Creates a leading zero string of 2 digits.\n * @param n - A number.\n */\nexport const two = (n: number) => String(n).padStart(2, \"0\")\n/**\n * Creates a leading zero string of 4 digits.\n * @param n - A number.\n */\nexport const four = (n: number) => String(n).padStart(2, \"0\")\n\n/**\n * Normalizes a given part to NFKC.\n * @param part - The part to normalize.\n */\nexport function normStr(\n part: Intl.DateTimeFormatPart\n): Intl.DateTimeFormatPart {\n if (part.type === \"literal\") {\n part.value = part.value.normalize(\"NFKC\")\n }\n return part\n}\n\n/**\n * Returns the parts filled with pertinent values.\n * @param inputDate - The date to fill parts for\n * @param parts - An array of parts to fill\n * @param locale - The locale to fill with.\n * @param genitive - Whether to use genitive tokens values or not.\n * @param offset - The explicit offset to fill with (ignores the date’s true offset).\n */\nexport function fill(\n inputDate: DateInput,\n parts: Part[],\n locale: string,\n genitive = false,\n offset: string | null = null\n): FilledPart[] {\n const partMap = createPartMap(inputDate, parts, locale, genitive)\n const d = date(inputDate)\n\n /**\n * Not all values get returned \"properly\" as our tokens would suggest. For\n * example, at times Intl returns leading zeros when it shouldn't. This fn\n * is used to clean up those irregular values.\n * @param param - Part\n */\n function value({ partName, partValue, token }: Part) {\n if (partName === \"literal\") return partValue\n const value = partMap[partName]\n if (partName === \"hour\" && token === \"H\") {\n return value.replace(/^0/, \"\") || \"0\"\n }\n if ([\"mm\", \"ss\", \"MM\"].includes(token) && value.length === 1) {\n // Some tokens are supposed to have leading zeros, but Intl doesn't\n // always return them, depending on the locale and the format.\n return `0${value}`\n }\n if (partName === \"dayPeriod\") {\n const p = ap(d.getUTCHours() < 12 ? \"am\" : \"pm\", locale)\n return token === \"A\" ? p.toUpperCase() : p.toLowerCase()\n }\n if (partName === \"timeZoneName\") {\n return offset ?? minsToOffset(-1 * d.getTimezoneOffset(), token)\n }\n return value\n }\n\n return parts.map((part): FilledPart => {\n return {\n ...part,\n value: value(part),\n }\n })\n}\n\n/**\n * Creates a map of part names to their respective values.\n * @param inputDate - The date to format\n * @param parts - The individual parts the need to be formatted.\n * @param locale - The locale to format the parts with.\n * @param genitive - Whether to use genitive tokens values or not.\n */\nfunction createPartMap(\n inputDate: DateInput,\n parts: Part[],\n locale: string,\n genitive = false\n): Record<keyof Intl.DateTimeFormatPartTypesRegistry, string> {\n const d = date(inputDate)\n const hour12 = parts.filter((part) => part.hour12)\n const hour24 = parts.filter((part) => !part.hour12)\n const valueParts: Intl.DateTimeFormatPart[] = []\n const genitiveParts: Part[] = []\n\n function addValues(requestedParts: Part[], hour12 = false) {\n const preciseLocale = `${locale}-u-hc-${hour12 ? \"h12\" : \"h23\"}`\n valueParts.push(\n ...new Intl.DateTimeFormat(\n preciseLocale,\n requestedParts.reduce(\n (options, part) => {\n if (part.partName === \"literal\") return options\n // Side effect! Genitive parts get shoved into a separate array.\n if (genitive && genitiveTokens.includes(part.token)) {\n genitiveParts.push(part)\n }\n return Object.assign(options, part.option)\n },\n { timeZone: \"UTC\" } as Intl.DateTimeFormatOptions\n )\n )\n .formatToParts(d)\n .map(normStr)\n )\n if (genitive && genitiveParts.length) {\n for (const part of genitiveParts) {\n let formattedParts: Intl.DateTimeFormatPart[] = []\n switch (part.token) {\n case \"MMMM\":\n formattedParts = new Intl.DateTimeFormat(preciseLocale, {\n dateStyle: \"long\",\n timeZone: \"UTC\",\n })\n .formatToParts(d)\n .map(normStr)\n break\n case \"MMM\":\n formattedParts = new Intl.DateTimeFormat(preciseLocale, {\n dateStyle: \"medium\",\n timeZone: \"UTC\",\n })\n .formatToParts(d)\n .map(normStr)\n break\n }\n const genitiveFormattedPart = formattedParts.find(\n (p) => p.type === part.partName\n )\n const index = valueParts.findIndex((p) => p.type === part.partName)\n if (genitiveFormattedPart && index > -1) {\n valueParts[index] = genitiveFormattedPart\n }\n }\n }\n }\n\n if (hour12.length) addValues(hour12, true)\n if (hour24.length) addValues(hour24)\n\n return valueParts.reduce((map, part) => {\n map[part.type] = part.value\n return map\n }, {} as Record<keyof Intl.DateTimeFormatPartTypesRegistry, string>)\n}\n\n/**\n * Converts minutes (300) to an ISO8601 compatible offset (+0400 or +04:00).\n * @param timeDiffInMins - The difference in minutes between two timezones.\n * @returns\n */\nexport function minsToOffset(\n timeDiffInMins: number,\n token: string = \"Z\"\n): string {\n const hours = String(Math.floor(Math.abs(timeDiffInMins / 60))).padStart(\n 2,\n \"0\"\n )\n const mins = String(Math.abs(timeDiffInMins % 60)).padStart(2, \"0\")\n const sign = timeDiffInMins < 0 ? \"-\" : \"+\"\n\n if (token === \"ZZ\") {\n return `${sign}${hours}${mins}`\n }\n\n return `${sign}${hours}:${mins}`\n}\n\n/**\n * Converts an offset (-0500) to minutes (-300).\n * @param offset - The offset to convert to minutes.\n * @param token - The timezone token format.\n */\nexport function offsetToMins(offset: string, token: TimezoneToken): number {\n validOffset(offset, token)\n const [_, sign, hours, mins] = offset.match(\n /([+-])([0-3][0-9]):?([0-6][0-9])/\n )!\n const offsetInMins = Number(hours) * 60 + Number(mins)\n return sign === \"+\" ? offsetInMins : -offsetInMins\n}\n\n/**\n * Validates that an offset is valid according to the format:\n * [+-]HHmm or [+-]HH:mm\n * @param offset - The offset to validate.\n * @param token - The timezone token format.\n */\nexport function validOffset(offset: string, token: TimezoneToken = \"Z\") {\n const valid = ((token: TimezoneToken): boolean => {\n switch (token) {\n case \"Z\":\n return /^([+-])[0-3][0-9]:[0-6][0-9]$/.test(offset)\n case \"ZZ\":\n return /^([+-])[0-3][0-9][0-6][0-9]$/.test(offset)\n }\n })(token)\n\n if (!valid) throw new Error(`Invalid offset: ${offset}`)\n return offset\n}\n\n/**\n * Given a string of tokens, escape any characters that are tokens.\n * @param str - The string to escape tokens in.\n * @returns The escaped string.\n */\nexport function escapeTokens(str: string): string {\n return clockAgnostic\n .concat(clock24)\n .concat(clock12)\n .sort((a, b) => (a[0].length > b[0].length ? 1 : -1))\n .reduce((target, part) => {\n return target.replace(part[0], `\\\\${part[0]}`)\n }, str)\n}\n\n/**\n * Checks if a given part should have a numeric value.\n * @param part - A part to check\n */\nexport function isNumeric(part: Part) {\n return [\"numeric\", \"2-digit\"].includes(part.partValue)\n}\n\n/**\n * Validates that an array of Parts can be parsed.\n * @param parts - Parts to validate for parsing ability.\n */\nexport function validate(parts: Part[]): Part[] | never {\n let lastPart: Part | undefined = undefined\n for (const part of parts) {\n if (part.partName === \"literal\" && !isNaN(parseFloat(part.partValue))) {\n throw new Error(`Numbers in format (${part.partValue}).`)\n }\n if (\n lastPart &&\n lastPart.partName !== \"literal\" &&\n part.partName !== \"literal\"\n ) {\n if (\n !(lastPart.token in fixedLength) &&\n !(part.token in fixedLength) &&\n !(isNumeric(lastPart) && part.token.toLowerCase() === \"a\")\n ) {\n throw new Error(\n `Illegal adjacent tokens (${lastPart.token}, ${part.token})`\n )\n }\n }\n lastPart = part\n }\n return parts\n}\n\n/**\n * Returns the timezone token format from a given format.\n * @param format - The format to check.\n * @returns The timezone token format (\"Z\" or \"ZZ\").\n */\nexport function getOffsetFormat(format: Format): TimezoneToken {\n if (typeof format === \"string\") {\n return format.includes(\"ZZ\") ? \"ZZ\" : \"Z\"\n }\n return \"time\" in format && format.time === \"full\" ? \"Z\" : \"ZZ\"\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,UAAU;AAcZ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K,SAAS,IAAI;AAAA,IAC1D;AACA,QACE,YACA,SAAS,aAAa,aACtB,KAAK,aAAa,WAClB;AACA,UACE,EAAE,SAAS,SAAS,gBACpB,EAAE,KAAK,SAAS,gBAChB,EAAE,UAAU,QAAQ,KAAK,KAAK,MAAM,YAAY,MAAM,MACtD;AACA,cAAM,IAAI;AAAA,UACR,4BAA4B,SAAS,KAAK,KAAK,KAAK,KAAK;AAAA,QAC3D;AAAA,MACF;AAAA,IACF;AACA,eAAW;AAAA,EACb;AACA,SAAO;AACT;AAOO,SAAS,gBAAgB,QAA+B;AAC7D,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,OAAO,SAAS,IAAI,IAAI,OAAO;AAAA,EACxC;AACA,SAAO,UAAU,UAAU,OAAO,SAAS,SAAS,MAAM;AAC5D;","names":["value","hour12","token"]}
|
package/dist/date.d.ts
ADDED
package/dist/date.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/date.ts
|
|
2
|
+
import { iso8601, iso8601Match } from "./iso8601.mjs";
|
|
3
|
+
function normalize(date2) {
|
|
4
|
+
const matches = date2.match(iso8601Match);
|
|
5
|
+
if (matches && typeof matches[4] === "undefined") {
|
|
6
|
+
return date2 += "T00:00:00";
|
|
7
|
+
}
|
|
8
|
+
return date2;
|
|
9
|
+
}
|
|
10
|
+
function date(date2) {
|
|
11
|
+
if (!date2) {
|
|
12
|
+
date2 = /* @__PURE__ */ new Date();
|
|
13
|
+
}
|
|
14
|
+
if (date2 instanceof Date) {
|
|
15
|
+
const d = new Date(date2);
|
|
16
|
+
d.setMilliseconds(0);
|
|
17
|
+
return d;
|
|
18
|
+
}
|
|
19
|
+
date2 = date2.trim();
|
|
20
|
+
if (iso8601(date2)) {
|
|
21
|
+
return new Date(normalize(date2));
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`Non ISO 8601 compliant date (${date2}).`);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
date
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=date.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import { iso8601, iso8601Match } from \"./iso8601\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Normalizes a \"short\" date like 2012-01-01 to 2012-01-01T00:00:00 to prevent\n * automatic coercion to UTC.\n * @param date - A string representation of the date.\n */\nfunction normalize(date: string) {\n const matches = date.match(iso8601Match)\n if (matches && typeof matches[4] === \"undefined\") {\n return (date += \"T00:00:00\")\n }\n return date\n}\n\n/**\n * A date to parse.\n * @param date - A Date object or an ISO 8601 date.\n */\nexport function date(date?: DateInput): Date {\n if (!date) {\n date = new Date()\n }\n if (date instanceof Date) {\n const d = new Date(date)\n d.setMilliseconds(0)\n return d\n }\n date = date.trim()\n if (iso8601(date)) {\n return new Date(normalize(date))\n }\n throw new Error(`Non ISO 8601 compliant date (${date}).`)\n}\n"],"mappings":";AAAA,SAAS,SAAS,oBAAoB;AAQtC,SAAS,UAAUA,OAAc;AAC/B,QAAM,UAAUA,MAAK,MAAM,YAAY;AACvC,MAAI,WAAW,OAAO,QAAQ,CAAC,MAAM,aAAa;AAChD,WAAQA,SAAQ;AAAA,EAClB;AACA,SAAOA;AACT;AAMO,SAAS,KAAKA,OAAwB;AAC3C,MAAI,CAACA,OAAM;AACT,IAAAA,QAAO,oBAAI,KAAK;AAAA,EAClB;AACA,MAAIA,iBAAgB,MAAM;AACxB,UAAM,IAAI,IAAI,KAAKA,KAAI;AACvB,MAAE,gBAAgB,CAAC;AACnB,WAAO;AAAA,EACT;AACA,EAAAA,QAAOA,MAAK,KAAK;AACjB,MAAI,QAAQA,KAAI,GAAG;AACjB,WAAO,IAAI,KAAK,UAAUA,KAAI,CAAC;AAAA,EACjC;AACA,QAAM,IAAI,MAAM,gCAAgCA,KAAI,IAAI;AAC1D;","names":["date"]}
|
package/dist/dayEnd.d.ts
ADDED
package/dist/dayEnd.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dayEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given day.\n * @param inputDate - A string or Date object\n */\nexport function dayEnd(inputDate: DateInput): Date {\n const d = date(inputDate)\n d.setHours(23, 59, 59, 999)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,OAAO,WAA4B;AACjD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAC1B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gets the what day of the year a given date is. For example, August 1st is
|
|
5
|
+
* the 213th day of the year on non- years and 214th on leap years.
|
|
6
|
+
* @param inputDate - The input date.
|
|
7
|
+
*/
|
|
8
|
+
declare function dayOfYear(inputDate: DateInput): number;
|
|
9
|
+
|
|
10
|
+
export { dayOfYear };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/dayOfYear.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function dayOfYear(inputDate) {
|
|
4
|
+
const d = date(inputDate);
|
|
5
|
+
return Math.round(
|
|
6
|
+
(new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0).getTime() - new Date(d.getFullYear(), 0, 0).getTime()) / 864e5
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
dayOfYear
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=dayOfYear.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dayOfYear.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Gets the what day of the year a given date is. For example, August 1st is\n * the 213th day of the year on non- years and 214th on leap years.\n * @param inputDate - The input date.\n */\nexport function dayOfYear(inputDate: DateInput): number {\n const d = date(inputDate)\n return Math.round(\n (new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0).getTime() -\n new Date(d.getFullYear(), 0, 0).getTime()) /\n 86400000\n )\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,UAAU,WAA8B;AACtD,QAAM,IAAI,KAAK,SAAS;AACxB,SAAO,KAAK;AAAA,KACT,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,GAAG,GAAG,CAAC,EAAE,QAAQ,IAClE,IAAI,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,EAAE,QAAQ,KACxC;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dayStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given day.\n * @param inputDate - A string or Date object\n */\nexport function dayStart(inputDate: DateInput): Date {\n const d = date(inputDate)\n d.setHours(0, 0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,SAAS,WAA4B;AACnD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,GAAG,GAAG,CAAC;AAClB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deviceLocale.ts"],"sourcesContent":["/**\n * Returns the device's locale. This is a simple proxy of the\n * `Intl.DateTimeFormat().resolvedOptions().locale` call.\n */\nexport function deviceLocale() {\n return Intl.DateTimeFormat().resolvedOptions().locale\n}\n"],"mappings":";AAIO,SAAS,eAAe;AAC7B,SAAO,KAAK,eAAe,EAAE,gBAAgB,EAAE;AACjD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deviceTZ.ts"],"sourcesContent":["/**\n * Get the timezone of the device.\n *\n * * Note: If the environment variable TZ is not set, it will return undefined.\n */\nexport function deviceTZ(): string | undefined {\n return Intl.DateTimeFormat().resolvedOptions().timeZone as string | undefined\n}\n"],"mappings":";AAKO,SAAS,WAA+B;AAC7C,SAAO,KAAK,eAAe,EAAE,gBAAgB,EAAE;AACjD;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
import { DiffRoundingMethod } from './diffRound.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
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
|
|
9
|
+
*/
|
|
10
|
+
declare function diffDays(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
|
|
12
|
+
export { diffDays };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/diffDays.ts
|
|
2
|
+
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
|
+
import { diffRound } from "./diffRound.mjs";
|
|
4
|
+
function diffDays(dateA, dateB, roundingMethod) {
|
|
5
|
+
return diffRound(
|
|
6
|
+
diffMilliseconds(dateA, dateB) / 864e5,
|
|
7
|
+
// hour * 24
|
|
8
|
+
roundingMethod
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
diffDays
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=diffDays.mjs.map
|
|
@@ -0,0 +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;AAQ5C,SAAS,SACd,OACA,OACA,gBACA;AACA,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DiffRoundingMethod } from './diffRound.js';
|
|
2
|
+
import { DateInput } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
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
|
|
9
|
+
*/
|
|
10
|
+
declare function diffHours(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
|
|
12
|
+
export { diffHours };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/diffHours.ts
|
|
2
|
+
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
|
+
import { diffRound } from "./diffRound.mjs";
|
|
4
|
+
function diffHours(dateA, dateB, roundingMethod) {
|
|
5
|
+
return diffRound(
|
|
6
|
+
diffMilliseconds(dateA, dateB) / 36e5,
|
|
7
|
+
// 1000 * 60 * 60
|
|
8
|
+
roundingMethod
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
diffHours
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=diffHours.mjs.map
|
|
@@ -0,0 +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;AAS5C,SAAS,UACd,OACA,OACA,gBACA;AACA,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
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
|
|
7
|
+
*/
|
|
8
|
+
declare function diffMilliseconds(dateA: DateInput, dateB: DateInput): number;
|
|
9
|
+
|
|
10
|
+
export { diffMilliseconds };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/diffMilliseconds.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
function diffMilliseconds(dateA, dateB) {
|
|
4
|
+
const left = date(dateA);
|
|
5
|
+
const right = date(dateB);
|
|
6
|
+
return +left - +right;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
diffMilliseconds
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=diffMilliseconds.mjs.map
|
|
@@ -0,0 +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;AAQd,SAAS,iBAAiB,OAAkB,OAAkB;AACnE,QAAM,OAAO,KAAK,KAAK;AACvB,QAAM,QAAQ,KAAK,KAAK;AACxB,SAAO,CAAC,OAAO,CAAC;AAClB;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
import { DiffRoundingMethod } from './diffRound.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the difference between 2 dates in minutes.
|
|
6
|
+
* @param dateA A date to compare with the right date
|
|
7
|
+
* @param roundingMethod the rounding method to use, default: trunc
|
|
8
|
+
*/
|
|
9
|
+
declare function diffMinutes(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
10
|
+
|
|
11
|
+
export { diffMinutes };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/diffMinutes.ts
|
|
2
|
+
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
|
+
import { diffRound } from "./diffRound.mjs";
|
|
4
|
+
function diffMinutes(dateA, dateB, roundingMethod) {
|
|
5
|
+
return diffRound(diffMilliseconds(dateA, dateB) / 6e4, roundingMethod);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
diffMinutes
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=diffMinutes.mjs.map
|
|
@@ -0,0 +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, roundingMethod)\n}\n"],"mappings":";AACA,SAAS,wBAAwB;AACjC,SAAS,iBAA0C;AAO5C,SAAS,YACd,OACA,OACA,gBACA;AACA,SAAO,UAAU,iBAAiB,OAAO,KAAK,IAAI,KAAQ,cAAc;AAC1E;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
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
|
|
7
|
+
*/
|
|
8
|
+
declare function diffMonths(dateA: DateInput, dateB: DateInput): number;
|
|
9
|
+
|
|
10
|
+
export { diffMonths };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/diffMonths.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
import { monthDays } from "./monthDays.mjs";
|
|
4
|
+
function diffMonths(dateA, dateB) {
|
|
5
|
+
const l = date(dateA);
|
|
6
|
+
const r = date(dateB);
|
|
7
|
+
if (l < r) {
|
|
8
|
+
const rs = diffMonths(r, l);
|
|
9
|
+
return rs == 0 ? 0 : -rs;
|
|
10
|
+
}
|
|
11
|
+
let months = (l.getFullYear() - r.getFullYear()) * 12 + (l.getMonth() - r.getMonth());
|
|
12
|
+
const ld = l.getDate();
|
|
13
|
+
const rd = r.getDate();
|
|
14
|
+
if (ld < rd) {
|
|
15
|
+
const lm = monthDays(l);
|
|
16
|
+
if (!(lm == ld && lm < rd)) {
|
|
17
|
+
months--;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return months == 0 ? 0 : months;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
diffMonths
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=diffMonths.mjs.map
|
|
@@ -0,0 +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 =\n (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;AAOnB,SAAS,WAAW,OAAkB,OAA0B;AACrE,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,UACD,EAAE,YAAY,IAAI,EAAE,YAAY,KAAK,MAAM,EAAE,SAAS,IAAI,EAAE,SAAS;AAExE,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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type DiffRoundingMethod = "trunc" | "round" | "floor" | "ceil";
|
|
2
|
+
/**
|
|
3
|
+
* Return a rounded value with the given rounding method
|
|
4
|
+
* @param value the value to round
|
|
5
|
+
* @param method the rounding method
|
|
6
|
+
*/
|
|
7
|
+
declare function diffRound(value: number, method?: DiffRoundingMethod): number;
|
|
8
|
+
|
|
9
|
+
export { type DiffRoundingMethod, diffRound };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/diffRound.ts"],"sourcesContent":["export type DiffRoundingMethod = \"trunc\" | \"round\" | \"floor\" | \"ceil\"\n\n/**\n * Return a rounded value with the given rounding method\n * @param value the value to round\n * @param method the rounding method\n */\nexport function diffRound(value: number, method: DiffRoundingMethod = \"trunc\") {\n const r = Math[method](value)\n return r == 0 ? 0 : r\n}\n"],"mappings":";AAOO,SAAS,UAAU,OAAe,SAA6B,SAAS;AAC7E,QAAM,IAAI,KAAK,MAAM,EAAE,KAAK;AAC5B,SAAO,KAAK,IAAI,IAAI;AACtB;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DiffRoundingMethod } from './diffRound.js';
|
|
2
|
+
import { DateInput } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
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
|
|
9
|
+
*/
|
|
10
|
+
declare function diffSeconds(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
|
|
12
|
+
export { diffSeconds };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/diffSeconds.ts
|
|
2
|
+
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
|
+
import { diffRound } from "./diffRound.mjs";
|
|
4
|
+
function diffSeconds(dateA, dateB, roundingMethod) {
|
|
5
|
+
return diffRound(diffMilliseconds(dateA, dateB) / 1e3, roundingMethod);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
diffSeconds
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=diffSeconds.mjs.map
|
|
@@ -0,0 +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\n * @param roundingMethod the rounding method to use, default: trunc\n */\nexport function diffSeconds(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n) {\n return diffRound(diffMilliseconds(dateA, dateB) / 1000, roundingMethod)\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAA6B,iBAAiB;AASvC,SAAS,YACd,OACA,OACA,gBACA;AACA,SAAO,UAAU,iBAAiB,OAAO,KAAK,IAAI,KAAM,cAAc;AACxE;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
import { DiffRoundingMethod } from './diffRound.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
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
|
|
9
|
+
*/
|
|
10
|
+
declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
11
|
+
|
|
12
|
+
export { diffWeeks };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/diffWeeks.ts
|
|
2
|
+
import { diffMilliseconds } from "./diffMilliseconds.mjs";
|
|
3
|
+
import { diffRound } from "./diffRound.mjs";
|
|
4
|
+
function diffWeeks(dateA, dateB, roundingMethod) {
|
|
5
|
+
return diffRound(
|
|
6
|
+
diffMilliseconds(dateA, dateB) / 6048e5,
|
|
7
|
+
// day * 7
|
|
8
|
+
roundingMethod
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
diffWeeks
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=diffWeeks.mjs.map
|
|
@@ -0,0 +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;AAQ5C,SAAS,UACd,OACA,OACA,gBACA;AACA,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DateInput } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
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
|
|
7
|
+
*/
|
|
8
|
+
declare function diffYears(dateA: DateInput, dateB: DateInput): number;
|
|
9
|
+
|
|
10
|
+
export { diffYears };
|
|
@@ -0,0 +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;AAQpB,SAAS,UAAU,OAAkB,OAA0B;AACpE,QAAM,IAAI,KAAK,MAAM,WAAW,OAAO,KAAK,IAAI,EAAE;AAElD,SAAO,KAAK,IAAI,IAAI;AACtB;","names":[]}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FormatOptions, DateInput, Format, Part } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Produce a formatted string. Available strings:
|
|
5
|
+
* token | description
|
|
6
|
+
* ------|------------
|
|
7
|
+
* YY | 2 digit year
|
|
8
|
+
* YYYY | 4 digit year
|
|
9
|
+
* M | The month 1-12
|
|
10
|
+
* MM | The month 01-12
|
|
11
|
+
* MMM | Short name Jan-Dec
|
|
12
|
+
* MMMM | Full name January | December
|
|
13
|
+
* D | The day of the month 1-31
|
|
14
|
+
* DD | The day of the month 01-31
|
|
15
|
+
* d | Single digit day "T"
|
|
16
|
+
* ddd | Short day name Thu
|
|
17
|
+
* dddd | Full day name Wednesday
|
|
18
|
+
* H | Minimum hour digits, 24 hour, 0-23
|
|
19
|
+
* HH | 2 hour digits, 24 hour, 00-23
|
|
20
|
+
* h | Minimum hour digits, 12 hour clock, 1-12
|
|
21
|
+
* hh | 2 hour digits, 12 hour clock, 01-12
|
|
22
|
+
* m | The minute 0-59
|
|
23
|
+
* mm | The minute 00-59
|
|
24
|
+
* s | The second 0-59
|
|
25
|
+
* ss | The second 00-59
|
|
26
|
+
* a | am/pm
|
|
27
|
+
* A | AM/PM
|
|
28
|
+
* Z | +0800, +0530, -1345
|
|
29
|
+
*
|
|
30
|
+
* @param inputDate - A date object or ISO 8601 string
|
|
31
|
+
* @param format - A format
|
|
32
|
+
*/
|
|
33
|
+
declare function format(options: FormatOptions): string;
|
|
34
|
+
declare function format(inputDate: DateInput, format?: Format, locale?: string, genitive?: boolean, partFilter?: (part: Part) => boolean): string;
|
|
35
|
+
|
|
36
|
+
export { format };
|
package/dist/format.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/format.ts
|
|
2
|
+
import { date } from "./date.mjs";
|
|
3
|
+
import { parts } from "./parts.mjs";
|
|
4
|
+
import { fill, getOffsetFormat } from "./common.mjs";
|
|
5
|
+
import { offset } from "./offset.mjs";
|
|
6
|
+
import { removeOffset } from "./removeOffset.mjs";
|
|
7
|
+
import { deviceLocale } from "./deviceLocale.mjs";
|
|
8
|
+
import { deviceTZ } from "./deviceTZ.mjs";
|
|
9
|
+
function format(inputDateOrOptions, format2 = "long", locale = "device", genitive = false, partFilter) {
|
|
10
|
+
let tz, forceOffset;
|
|
11
|
+
if (typeof inputDateOrOptions === "object" && !(inputDateOrOptions instanceof Date)) {
|
|
12
|
+
;
|
|
13
|
+
({
|
|
14
|
+
date: inputDateOrOptions,
|
|
15
|
+
format: format2,
|
|
16
|
+
locale,
|
|
17
|
+
genitive,
|
|
18
|
+
partFilter,
|
|
19
|
+
tz
|
|
20
|
+
} = inputDateOrOptions);
|
|
21
|
+
}
|
|
22
|
+
if (format2 === "ISO8601")
|
|
23
|
+
return date(inputDateOrOptions).toISOString();
|
|
24
|
+
if (tz) {
|
|
25
|
+
forceOffset = offset(inputDateOrOptions, "utc", tz, getOffsetFormat(format2));
|
|
26
|
+
}
|
|
27
|
+
tz != null ? tz : tz = deviceTZ();
|
|
28
|
+
if ((tz == null ? void 0 : tz.toLowerCase()) !== "utc") {
|
|
29
|
+
inputDateOrOptions = removeOffset(
|
|
30
|
+
inputDateOrOptions,
|
|
31
|
+
offset(inputDateOrOptions, tz, "utc")
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (!locale || locale === "device") {
|
|
35
|
+
locale = deviceLocale();
|
|
36
|
+
}
|
|
37
|
+
return fill(
|
|
38
|
+
inputDateOrOptions,
|
|
39
|
+
parts(format2, locale).filter(partFilter != null ? partFilter : () => true),
|
|
40
|
+
locale,
|
|
41
|
+
genitive,
|
|
42
|
+
forceOffset
|
|
43
|
+
).map((p) => p.value).join("");
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
format
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=format.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { parts } from \"./parts\"\nimport { fill, getOffsetFormat } from \"./common\"\nimport type { DateInput, Format, FormatOptions, FormatStyle, Part } 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;AAEtC,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;AAAW,WAAO,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,kCAAe,MAAM,IAAK;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,EACF,EACG,IAAI,CAAC,MAAM,EAAE,KAAK,EAClB,KAAK,EAAE;AACZ;","names":["format"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Format, Part } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return the string format for a given format. For example:
|
|
5
|
+
* ```js
|
|
6
|
+
* formatStr({ date: 'long' }, 'en') // dddd, MMMM D, YYYY
|
|
7
|
+
* ```
|
|
8
|
+
* @param format - A format string or object.
|
|
9
|
+
* @param locale - A locale or en by default.
|
|
10
|
+
*/
|
|
11
|
+
declare function formatStr(format: Format, locale?: string, escapeLiterals?: boolean, filterParts?: (part: Part) => boolean): string;
|
|
12
|
+
|
|
13
|
+
export { formatStr };
|