@formkit/tempo 0.1.1 → 1.0.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.
Files changed (147) hide show
  1. package/dist/addDay.d.ts +4 -3
  2. package/dist/addDay.mjs.map +1 -1
  3. package/dist/addHour.d.ts +4 -3
  4. package/dist/addHour.mjs.map +1 -1
  5. package/dist/addMillisecond.d.ts +10 -0
  6. package/dist/addMillisecond.mjs +11 -0
  7. package/dist/addMillisecond.mjs.map +1 -0
  8. package/dist/addMinute.d.ts +5 -4
  9. package/dist/addMinute.mjs.map +1 -1
  10. package/dist/addMonth.d.ts +5 -5
  11. package/dist/addMonth.mjs +1 -2
  12. package/dist/addMonth.mjs.map +1 -1
  13. package/dist/addSecond.d.ts +4 -3
  14. package/dist/addSecond.mjs.map +1 -1
  15. package/dist/addYear.d.ts +5 -5
  16. package/dist/addYear.mjs +1 -2
  17. package/dist/addYear.mjs.map +1 -1
  18. package/dist/ap.mjs +1 -2
  19. package/dist/ap.mjs.map +1 -1
  20. package/dist/applyOffset.d.ts +5 -5
  21. package/dist/applyOffset.mjs +5 -11
  22. package/dist/applyOffset.mjs.map +1 -1
  23. package/dist/bundle.d.ts +256 -115
  24. package/dist/bundle.mjs +158 -140
  25. package/dist/bundle.mjs.map +1 -1
  26. package/dist/common.d.ts +27 -7
  27. package/dist/common.mjs +47 -42
  28. package/dist/common.mjs.map +1 -1
  29. package/dist/date.d.ts +2 -2
  30. package/dist/date.mjs +1 -3
  31. package/dist/date.mjs.map +1 -1
  32. package/dist/dayEnd.d.ts +3 -3
  33. package/dist/dayEnd.mjs.map +1 -1
  34. package/dist/dayOfYear.d.ts +3 -3
  35. package/dist/dayOfYear.mjs.map +1 -1
  36. package/dist/dayStart.d.ts +3 -3
  37. package/dist/dayStart.mjs +1 -1
  38. package/dist/dayStart.mjs.map +1 -1
  39. package/dist/diffDays.d.ts +12 -5
  40. package/dist/diffDays.mjs +1 -0
  41. package/dist/diffDays.mjs.map +1 -1
  42. package/dist/diffHours.d.ts +12 -5
  43. package/dist/diffHours.mjs +1 -0
  44. package/dist/diffHours.mjs.map +1 -1
  45. package/dist/diffMilliseconds.d.ts +10 -4
  46. package/dist/diffMilliseconds.mjs.map +1 -1
  47. package/dist/diffMinutes.d.ts +11 -3
  48. package/dist/diffMinutes.mjs +5 -1
  49. package/dist/diffMinutes.mjs.map +1 -1
  50. package/dist/diffMonths.d.ts +10 -4
  51. package/dist/diffMonths.mjs.map +1 -1
  52. package/dist/diffSeconds.d.ts +12 -5
  53. package/dist/diffSeconds.mjs +5 -1
  54. package/dist/diffSeconds.mjs.map +1 -1
  55. package/dist/diffWeeks.d.ts +10 -3
  56. package/dist/diffWeeks.mjs.map +1 -1
  57. package/dist/diffYears.d.ts +10 -4
  58. package/dist/diffYears.mjs +4 -1
  59. package/dist/diffYears.mjs.map +1 -1
  60. package/dist/format.mjs +2 -3
  61. package/dist/format.mjs.map +1 -1
  62. package/dist/hourEnd.d.ts +3 -3
  63. package/dist/hourEnd.mjs.map +1 -1
  64. package/dist/hourStart.d.ts +3 -3
  65. package/dist/hourStart.mjs +1 -1
  66. package/dist/hourStart.mjs.map +1 -1
  67. package/dist/index.cjs +165 -143
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.cts +256 -115
  70. package/dist/index.d.ts +5 -1
  71. package/dist/index.mjs +8 -0
  72. package/dist/index.mjs.map +1 -1
  73. package/dist/isAfter.d.ts +6 -6
  74. package/dist/isAfter.mjs.map +1 -1
  75. package/dist/isBefore.d.ts +5 -5
  76. package/dist/isBefore.mjs.map +1 -1
  77. package/dist/isEqual.d.ts +13 -4
  78. package/dist/isEqual.mjs.map +1 -1
  79. package/dist/isFuture.d.ts +10 -0
  80. package/dist/isFuture.mjs +9 -0
  81. package/dist/isFuture.mjs.map +1 -0
  82. package/dist/isPast.d.ts +10 -0
  83. package/dist/isPast.mjs +9 -0
  84. package/dist/isPast.mjs.map +1 -0
  85. package/dist/iso8601.d.ts +1 -1
  86. package/dist/iso8601.mjs +4 -7
  87. package/dist/iso8601.mjs.map +1 -1
  88. package/dist/minuteEnd.d.ts +3 -3
  89. package/dist/minuteEnd.mjs.map +1 -1
  90. package/dist/minuteStart.d.ts +3 -3
  91. package/dist/minuteStart.mjs +1 -1
  92. package/dist/minuteStart.mjs.map +1 -1
  93. package/dist/monthDays.d.ts +3 -3
  94. package/dist/monthDays.mjs.map +1 -1
  95. package/dist/monthEnd.d.ts +3 -3
  96. package/dist/monthEnd.mjs.map +1 -1
  97. package/dist/monthStart.d.ts +3 -3
  98. package/dist/monthStart.mjs +1 -1
  99. package/dist/monthStart.mjs.map +1 -1
  100. package/dist/nearestDay.d.ts +3 -3
  101. package/dist/nearestDay.mjs +2 -4
  102. package/dist/nearestDay.mjs.map +1 -1
  103. package/dist/offset.d.ts +5 -5
  104. package/dist/offset.mjs +3 -3
  105. package/dist/offset.mjs.map +1 -1
  106. package/dist/parse.mjs +33 -23
  107. package/dist/parse.mjs.map +1 -1
  108. package/dist/parts.mjs +14 -24
  109. package/dist/parts.mjs.map +1 -1
  110. package/dist/range.mjs +1 -2
  111. package/dist/range.mjs.map +1 -1
  112. package/dist/removeOffset.d.ts +4 -4
  113. package/dist/removeOffset.mjs.map +1 -1
  114. package/dist/sameDay.d.ts +8 -2
  115. package/dist/sameDay.mjs.map +1 -1
  116. package/dist/sameHour.d.ts +8 -2
  117. package/dist/sameHour.mjs.map +1 -1
  118. package/dist/sameMillisecond.d.ts +16 -0
  119. package/dist/sameMillisecond.mjs +11 -0
  120. package/dist/sameMillisecond.mjs.map +1 -0
  121. package/dist/sameMinute.d.ts +8 -2
  122. package/dist/sameMinute.mjs.map +1 -1
  123. package/dist/sameMonth.d.ts +16 -0
  124. package/dist/sameMonth.mjs +11 -0
  125. package/dist/sameMonth.mjs.map +1 -0
  126. package/dist/sameSecond.d.ts +8 -2
  127. package/dist/sameSecond.mjs.map +1 -1
  128. package/dist/sameYear.d.ts +8 -2
  129. package/dist/sameYear.mjs.map +1 -1
  130. package/dist/types.d.ts +15 -7
  131. package/dist/tzDate.d.ts +5 -3
  132. package/dist/tzDate.mjs.map +1 -1
  133. package/dist/weekEnd.d.ts +4 -4
  134. package/dist/weekEnd.mjs +1 -1
  135. package/dist/weekEnd.mjs.map +1 -1
  136. package/dist/weekStart.d.ts +4 -4
  137. package/dist/weekStart.mjs +2 -3
  138. package/dist/weekStart.mjs.map +1 -1
  139. package/dist/yearDays.d.ts +3 -3
  140. package/dist/yearDays.mjs.map +1 -1
  141. package/dist/yearEnd.d.ts +3 -3
  142. package/dist/yearEnd.mjs +1 -2
  143. package/dist/yearEnd.mjs.map +1 -1
  144. package/dist/yearStart.d.ts +3 -3
  145. package/dist/yearStart.mjs +2 -3
  146. package/dist/yearStart.mjs.map +1 -1
  147. package/package.json +32 -23
package/dist/common.mjs CHANGED
@@ -32,6 +32,9 @@ var clock12 = [
32
32
  ["a", { dayPeriod: "narrow" }],
33
33
  ["A", { dayPeriod: "narrow" }]
34
34
  ];
35
+ var fractionalSeconds = [
36
+ ["SSS", { fractionalSecond: "3-digit" }]
37
+ ];
35
38
  var fixedLength = {
36
39
  DD: 2,
37
40
  HH: 2,
@@ -43,6 +46,12 @@ var fixedLength = {
43
46
  ss: 2
44
47
  };
45
48
  function fixedLengthByOffset(offsetString) {
49
+ if (/^[+-]\d{2}:\d{2}:\d{2}/.test(offsetString)) {
50
+ return 9;
51
+ }
52
+ if (/^[+-]\d{6}/.test(offsetString)) {
53
+ return 8;
54
+ }
46
55
  if (/^[+-]\d{2}:\d{2}/.test(offsetString)) {
47
56
  return 6;
48
57
  }
@@ -53,17 +62,12 @@ function fixedLengthByOffset(offsetString) {
53
62
  }
54
63
  var genitiveTokens = ["MMMM", "MMM", "dddd", "ddd"];
55
64
  var tokens = /* @__PURE__ */ new Map(
56
- /* @__PURE__ */ [...clockAgnostic, ...clock24, ...clock12].map((format) => {
65
+ /* @__PURE__ */ [...clockAgnostic, ...clock24, ...clock12, ...fractionalSeconds].map((format) => {
57
66
  return [format[0], format];
58
67
  })
59
68
  );
60
69
  var dayPeriodMap = /* @__PURE__ */ new Map();
61
- var styles = [
62
- "full",
63
- "long",
64
- "medium",
65
- "short"
66
- ];
70
+ var styles = ["full", "long", "medium", "short"];
67
71
  var two = (n) => String(n).padStart(2, "0");
68
72
  var four = (n) => String(n).padStart(2, "0");
69
73
  function normStr(part) {
@@ -76,8 +80,7 @@ function fill(inputDate, parts, locale, genitive = false, offset = null) {
76
80
  const partMap = createPartMap(inputDate, parts, locale, genitive);
77
81
  const d = date(inputDate);
78
82
  function value({ partName, partValue, token }) {
79
- if (partName === "literal")
80
- return partValue;
83
+ if (partName === "literal") return partValue;
81
84
  const value2 = partMap[partName];
82
85
  if (partName === "hour" && token === "H") {
83
86
  return value2.replace(/^0/, "") || "0";
@@ -89,6 +92,9 @@ function fill(inputDate, parts, locale, genitive = false, offset = null) {
89
92
  const p = ap(d.getUTCHours() < 12 ? "am" : "pm", locale);
90
93
  return token === "A" ? p.toUpperCase() : p.toLowerCase();
91
94
  }
95
+ if (partName === "fractionalSecond") {
96
+ return String(d.getUTCMilliseconds()).padStart(3, "0");
97
+ }
92
98
  if (partName === "timeZoneName") {
93
99
  return offset != null ? offset : minsToOffset(-1 * d.getTimezoneOffset(), token);
94
100
  }
@@ -114,8 +120,7 @@ function createPartMap(inputDate, parts, locale, genitive = false) {
114
120
  preciseLocale,
115
121
  requestedParts.reduce(
116
122
  (options, part) => {
117
- if (part.partName === "literal")
118
- return options;
123
+ if (part.partName === "literal") return options;
119
124
  if (genitive && genitiveTokens.includes(part.token)) {
120
125
  genitiveParts.push(part);
121
126
  }
@@ -142,9 +147,7 @@ function createPartMap(inputDate, parts, locale, genitive = false) {
142
147
  }).formatToParts(d).map(normStr);
143
148
  break;
144
149
  }
145
- const genitiveFormattedPart = formattedParts.find(
146
- (p) => p.type === part.partName
147
- );
150
+ const genitiveFormattedPart = formattedParts.find((p) => p.type === part.partName);
148
151
  const index = valueParts.findIndex((p) => p.type === part.partName);
149
152
  if (genitiveFormattedPart && index > -1) {
150
153
  valueParts[index] = genitiveFormattedPart;
@@ -152,50 +155,51 @@ function createPartMap(inputDate, parts, locale, genitive = false) {
152
155
  }
153
156
  }
154
157
  }
155
- if (hour12.length)
156
- addValues(hour12, true);
157
- if (hour24.length)
158
- addValues(hour24);
158
+ if (hour12.length) addValues(hour12, true);
159
+ if (hour24.length) addValues(hour24);
159
160
  return valueParts.reduce((map, part) => {
160
161
  map[part.type] = part.value;
161
162
  return map;
162
163
  }, {});
163
164
  }
164
- function minsToOffset(timeDiffInMins, token = "Z") {
165
- const hours = String(Math.floor(Math.abs(timeDiffInMins / 60))).padStart(
166
- 2,
167
- "0"
168
- );
169
- const mins = String(Math.abs(timeDiffInMins % 60)).padStart(2, "0");
170
- const sign = timeDiffInMins < 0 ? "-" : "+";
165
+ function secsToOffset(totalSecs, token = "Z") {
166
+ const sign = totalSecs < 0 ? "-" : "+";
167
+ const absSecs = Math.abs(totalSecs);
168
+ const hours = String(Math.floor(absSecs / 3600)).padStart(2, "0");
169
+ const mins = String(Math.floor(absSecs % 3600 / 60)).padStart(2, "0");
170
+ const secs = Math.round(absSecs % 60);
171
171
  if (token === "ZZ") {
172
- return `${sign}${hours}${mins}`;
172
+ return secs === 0 ? `${sign}${hours}${mins}` : `${sign}${hours}${mins}${String(secs).padStart(2, "0")}`;
173
173
  }
174
- return `${sign}${hours}:${mins}`;
174
+ return secs === 0 ? `${sign}${hours}:${mins}` : `${sign}${hours}:${mins}:${String(secs).padStart(2, "0")}`;
175
175
  }
176
- function offsetToMins(offset, token) {
176
+ function minsToOffset(timeDiffInMins, token = "Z") {
177
+ return secsToOffset(timeDiffInMins * 60, token);
178
+ }
179
+ function offsetToSecs(offset, token) {
177
180
  validOffset(offset, token);
178
- const [_, sign, hours, mins] = offset.match(
179
- /([+-])([0-3][0-9]):?([0-6][0-9])/
180
- );
181
- const offsetInMins = Number(hours) * 60 + Number(mins);
182
- return sign === "+" ? offsetInMins : -offsetInMins;
181
+ const match = offset.match(/([+-])([0-3][0-9]):?([0-5][0-9])(?::?([0-5][0-9]))?/);
182
+ const [_, sign, hours, mins, secs = "0"] = match;
183
+ const totalSecs = Number(hours) * 3600 + Number(mins) * 60 + Number(secs);
184
+ return sign === "+" ? totalSecs : -totalSecs;
185
+ }
186
+ function offsetToMins(offset, token) {
187
+ return Math.round(offsetToSecs(offset, token) / 60);
183
188
  }
184
189
  function validOffset(offset, token = "Z") {
185
190
  const valid = ((token2) => {
186
191
  switch (token2) {
187
192
  case "Z":
188
- return /^([+-])[0-3][0-9]:[0-6][0-9]$/.test(offset);
193
+ return /^([+-])[0-3][0-9]:[0-5][0-9](?::[0-5][0-9])?$/.test(offset);
189
194
  case "ZZ":
190
- return /^([+-])[0-3][0-9][0-6][0-9]$/.test(offset);
195
+ return /^([+-])[0-3][0-9][0-5][0-9](?:[0-5][0-9])?$/.test(offset);
191
196
  }
192
197
  })(token);
193
- if (!valid)
194
- throw new Error(`Invalid offset: ${offset}`);
198
+ if (!valid) throw new Error(`Invalid offset: ${offset}`);
195
199
  return offset;
196
200
  }
197
201
  function escapeTokens(str) {
198
- return clockAgnostic.concat(clock24).concat(clock12).sort((a, b) => a[0].length > b[0].length ? 1 : -1).reduce((target, part) => {
202
+ return clockAgnostic.concat(clock24).concat(clock12).concat(fractionalSeconds).sort((a, b) => a[0].length > b[0].length ? 1 : -1).reduce((target, part) => {
199
203
  return target.replace(part[0], `\\${part[0]}`);
200
204
  }, str);
201
205
  }
@@ -209,10 +213,8 @@ function validate(parts) {
209
213
  throw new Error(`Numbers in format (${part.partValue}).`);
210
214
  }
211
215
  if (lastPart && lastPart.partName !== "literal" && part.partName !== "literal") {
212
- if (!(lastPart.token in fixedLength) && !(part.token in fixedLength) && !(isNumeric(lastPart) && part.token.toLowerCase() === "a")) {
213
- throw new Error(
214
- `Illegal adjacent tokens (${lastPart.token}, ${part.token})`
215
- );
216
+ if (!(lastPart.token in fixedLength) && !(part.token in fixedLength) && !(isNumeric(lastPart) && part.token.toLowerCase() === "a") && lastPart.token !== "SSS") {
217
+ throw new Error(`Illegal adjacent tokens (${lastPart.token}, ${part.token})`);
216
218
  }
217
219
  }
218
220
  lastPart = part;
@@ -235,6 +237,7 @@ export {
235
237
  fixedLength,
236
238
  fixedLengthByOffset,
237
239
  four,
240
+ fractionalSeconds,
238
241
  genitiveTokens,
239
242
  getOffsetFormat,
240
243
  isNumeric,
@@ -242,6 +245,8 @@ export {
242
245
  minsToOffset,
243
246
  normStr,
244
247
  offsetToMins,
248
+ offsetToSecs,
249
+ secsToOffset,
245
250
  specDate,
246
251
  styles,
247
252
  tokens,
@@ -1 +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,IAAM,WAAW;AAKjB,IAAM,YAAuC,oBAAI,IAAI;AAKrD,IAAM,gBAAiC;AAAA,EAC5C,CAAC,QAAQ,EAAE,MAAM,UAAU,CAAC;AAAA,EAC5B,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAAA,EAC1B,CAAC,QAAQ,EAAE,OAAO,OAAO,CAAC;AAAA,EAC1B,CAAC,OAAO,EAAE,OAAO,QAAQ,CAAC;AAAA,EAC1B,CAAC,MAAM,EAAE,OAAO,UAAU,CAAC;AAAA,EAC3B,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC;AAAA,EAC1B,CAAC,MAAM,EAAE,KAAK,UAAU,CAAC;AAAA,EACzB,CAAC,KAAK,EAAE,KAAK,UAAU,CAAC;AAAA,EACxB,CAAC,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S,MAAM;AAC5D;","names":["value","hour12","token"]}
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 MaybeDateInput,\n ExtendedPartTypes,\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 * Fractional seconds patterns.\n */\nexport const fractionalSeconds: FormatPattern[] = [\n [\"SSS\", { fractionalSecond: \"3-digit\" }],\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 * Determines the length of a timezone offset string.\n * Supports offsets with optional seconds component.\n */\nexport function fixedLengthByOffset(offsetString: string): 9 | 8 | 6 | 5 {\n // starts with [+-]xx:xx:xx (9 chars, Z format with seconds)\n if (/^[+-]\\d{2}:\\d{2}:\\d{2}/.test(offsetString)) {\n return 9\n }\n\n // starts with [+-]xxxxxx (8 chars, ZZ format with seconds)\n if (/^[+-]\\d{6}/.test(offsetString)) {\n return 8\n }\n\n // starts with [+-]xx:xx (6 chars, Z format)\n if (/^[+-]\\d{2}:\\d{2}/.test(offsetString)) {\n return 6\n }\n\n // starts with [+-]xxxx (5 chars, ZZ format)\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, ...fractionalSeconds].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> = [\"full\", \"long\", \"medium\", \"short\"]\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(part: Intl.DateTimeFormatPart): 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: MaybeDateInput,\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 === \"fractionalSecond\") {\n return String(d.getUTCMilliseconds()).padStart(3, \"0\")\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: MaybeDateInput,\n parts: Part[],\n locale: string,\n genitive = false\n): Record<ExtendedPartTypes, 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((p) => p.type === part.partName)\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 as ExtendedPartTypes] = part.value\n return map\n }, {} as Record<ExtendedPartTypes, string>)\n}\n\n/**\n * Converts total seconds to an ISO8601 compatible offset (+04:00 or +0400).\n * Only includes seconds in output if they are non-zero.\n * @param totalSecs - The total offset in seconds (can be negative).\n * @param token - \"Z\" for +HH:mm[:ss] or \"ZZ\" for +HHmm[ss]\n */\nexport function secsToOffset(totalSecs: number, token: string = \"Z\"): string {\n const sign = totalSecs < 0 ? \"-\" : \"+\"\n const absSecs = Math.abs(totalSecs)\n const hours = String(Math.floor(absSecs / 3600)).padStart(2, \"0\")\n const mins = String(Math.floor((absSecs % 3600) / 60)).padStart(2, \"0\")\n const secs = Math.round(absSecs % 60)\n\n if (token === \"ZZ\") {\n return secs === 0\n ? `${sign}${hours}${mins}`\n : `${sign}${hours}${mins}${String(secs).padStart(2, \"0\")}`\n }\n return secs === 0\n ? `${sign}${hours}:${mins}`\n : `${sign}${hours}:${mins}:${String(secs).padStart(2, \"0\")}`\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(timeDiffInMins: number, token: string = \"Z\"): string {\n return secsToOffset(timeDiffInMins * 60, token)\n}\n\n/**\n * Converts an offset (-05:32:11 or -053211) to total seconds.\n * Supports offsets with optional seconds component.\n * @param offset - The offset to convert to seconds.\n * @param token - The timezone token format.\n */\nexport function offsetToSecs(offset: string, token: TimezoneToken): number {\n validOffset(offset, token)\n const match = offset.match(/([+-])([0-3][0-9]):?([0-5][0-9])(?::?([0-5][0-9]))?/)!\n const [_, sign, hours, mins, secs = \"0\"] = match\n const totalSecs = Number(hours) * 3600 + Number(mins) * 60 + Number(secs)\n return sign === \"+\" ? totalSecs : -totalSecs\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 return Math.round(offsetToSecs(offset, token) / 60)\n}\n\n/**\n * Validates that an offset is valid according to the format:\n * [+-]HH:mm or [+-]HH:mm:ss (Z token)\n * [+-]HHmm or [+-]HHmmss (ZZ token)\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-5][0-9](?::[0-5][0-9])?$/.test(offset)\n case \"ZZ\":\n return /^([+-])[0-3][0-9][0-5][0-9](?:[0-5][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 .concat(fractionalSeconds)\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 (lastPart && lastPart.partName !== \"literal\" && part.partName !== \"literal\") {\n if (\n !(lastPart.token in fixedLength) &&\n !(part.token in fixedLength) &&\n !(isNumeric(lastPart) && part.token.toLowerCase() === \"a\") &&\n lastPart.token !== \"SSS\" // SSS can be followed by anything (greedy digit consumer)\n ) {\n throw new Error(`Illegal adjacent tokens (${lastPart.token}, ${part.token})`)\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;AAgBZ,IAAM,WAAW;AAKjB,IAAM,YAAuC,oBAAI,IAAI;AAKrD,IAAM,gBAAiC;AAAA,EAC5C,CAAC,QAAQ,EAAE,MAAM,UAAU,CAAC;AAAA,EAC5B,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAAA,EAC1B,CAAC,QAAQ,EAAE,OAAO,OAAO,CAAC;AAAA,EAC1B,CAAC,OAAO,EAAE,OAAO,QAAQ,CAAC;AAAA,EAC1B,CAAC,MAAM,EAAE,OAAO,UAAU,CAAC;AAAA,EAC3B,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC;AAAA,EAC1B,CAAC,MAAM,EAAE,KAAK,UAAU,CAAC;AAAA,EACzB,CAAC,KAAK,EAAE,KAAK,UAAU,CAAC;AAAA,EACxB,CAAC,QAAQ,EAAE,SAAS,OAAO,CAAC;AAAA,EAC5B,CAAC,OAAO,EAAE,SAAS,QAAQ,CAAC;AAAA,EAC5B,CAAC,KAAK,EAAE,SAAS,SAAS,CAAC;AAAA,EAC3B,CAAC,MAAM,EAAE,QAAQ,UAAU,CAAC;AAAA,EAC5B,CAAC,KAAK,EAAE,QAAQ,UAAU,CAAC;AAAA,EAC3B,CAAC,MAAM,EAAE,QAAQ,UAAU,CAAC;AAAA,EAC5B,CAAC,KAAK,EAAE,QAAQ,UAAU,CAAC;AAAA,EAC3B,CAAC,MAAM,EAAE,cAAc,OAAO,CAAC;AAAA,EAC/B,CAAC,KAAK,EAAE,cAAc,QAAQ,CAAC;AACjC;AAeO,IAAM,UAA2B;AAAA,EACtC,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAAA,EAC1B,CAAC,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B;AACA,cAAM,IAAI,MAAM,4BAA4B,SAAS,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MAC9E;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 CHANGED
@@ -1,9 +1,9 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * A date to parse.
5
5
  * @param date - A Date object or an ISO 8601 date.
6
6
  */
7
- declare function date(date?: DateInput): Date;
7
+ declare function date(date?: MaybeDateInput): Date;
8
8
 
9
9
  export { date };
package/dist/date.mjs CHANGED
@@ -12,9 +12,7 @@ function date(date2) {
12
12
  date2 = /* @__PURE__ */ new Date();
13
13
  }
14
14
  if (date2 instanceof Date) {
15
- const d = new Date(date2);
16
- d.setMilliseconds(0);
17
- return d;
15
+ return new Date(date2);
18
16
  }
19
17
  date2 = date2.trim();
20
18
  if (iso8601(date2)) {
package/dist/date.mjs.map CHANGED
@@ -1 +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"]}
1
+ {"version":3,"sources":["../src/date.ts"],"sourcesContent":["import { iso8601, iso8601Match } from \"./iso8601\"\nimport type { MaybeDateInput } 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?: MaybeDateInput): Date {\n if (!date) {\n date = new Date()\n }\n if (date instanceof Date) {\n return new Date(date)\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,OAA6B;AAChD,MAAI,CAACA,OAAM;AACT,IAAAA,QAAO,oBAAI,KAAK;AAAA,EAClB;AACA,MAAIA,iBAAgB,MAAM;AACxB,WAAO,IAAI,KAAKA,KAAI;AAAA,EACtB;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 CHANGED
@@ -1,9 +1,9 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a Date object for end of the given day.
5
- * @param inputDate - A string or Date object
5
+ * @param [inputDate] - A string, Date object or nothing for the current day
6
6
  */
7
- declare function dayEnd(inputDate: DateInput): Date;
7
+ declare function dayEnd(inputDate?: MaybeDateInput): Date;
8
8
 
9
9
  export { dayEnd };
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../src/dayEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given day.\n * @param [inputDate] - A string, Date object or nothing for the current day\n */\nexport function dayEnd(inputDate?: MaybeDateInput): 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,WAAkC;AACvD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAC1B,SAAO;AACT;","names":[]}
@@ -1,10 +1,10 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Gets the what day of the year a given date is. For example, August 1st is
5
5
  * the 213th day of the year on non- years and 214th on leap years.
6
- * @param inputDate - The input date.
6
+ * @param [inputDate] - The input date or nothing for the current day.
7
7
  */
8
- declare function dayOfYear(inputDate: DateInput): number;
8
+ declare function dayOfYear(inputDate?: MaybeDateInput): number;
9
9
 
10
10
  export { dayOfYear };
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../src/dayOfYear.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } 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 or nothing for the current day.\n */\nexport function dayOfYear(inputDate?: MaybeDateInput): 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,WAAoC;AAC5D,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":[]}
@@ -1,9 +1,9 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a Date object for start of the given day.
5
- * @param inputDate - A string or Date object
5
+ * @param [inputDate] - A string, Date object or nothing for the current day
6
6
  */
7
- declare function dayStart(inputDate: DateInput): Date;
7
+ declare function dayStart(inputDate?: MaybeDateInput): Date;
8
8
 
9
9
  export { dayStart };
package/dist/dayStart.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { date } from "./date.mjs";
3
3
  function dayStart(inputDate) {
4
4
  const d = date(inputDate);
5
- d.setHours(0, 0, 0);
5
+ d.setHours(0, 0, 0, 0);
6
6
  return d;
7
7
  }
8
8
  export {
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../src/dayStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given day.\n * @param [inputDate] - A string, Date object or nothing for the current day\n */\nexport function dayStart(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setHours(0, 0, 0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,SAAS,WAAkC;AACzD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,GAAG,GAAG,GAAG,CAAC;AACrB,SAAO;AACT;","names":[]}
@@ -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: DateInput, roundingMethod?: DiffRoundingMethod): number;
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
@@ -3,6 +3,7 @@ import { diffMilliseconds } from "./diffMilliseconds.mjs";
3
3
  import { diffRound } from "./diffRound.mjs";
4
4
  function diffDays(dateA, dateB, roundingMethod) {
5
5
  return diffRound(
6
+ // @ts-ignore
6
7
  diffMilliseconds(dateA, dateB) / 864e5,
7
8
  // hour * 24
8
9
  roundingMethod
@@ -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;AAQ5C,SAAS,SACd,OACA,OACA,gBACA;AACA,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
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":[]}
@@ -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: DateInput, roundingMethod?: DiffRoundingMethod): number;
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 };
@@ -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
@@ -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;AAS5C,SAAS,UACd,OACA,OACA,gBACA;AACA,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
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: DateInput): number;
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;AAQd,SAAS,iBAAiB,OAAkB,OAAkB;AACnE,QAAM,OAAO,KAAK,KAAK;AACvB,QAAM,QAAQ,KAAK,KAAK;AACxB,SAAO,CAAC,OAAO,CAAC;AAClB;","names":[]}
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":[]}
@@ -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 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 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
 
@@ -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(diffMilliseconds(dateA, dateB) / 6e4, roundingMethod);
5
+ return diffRound(
6
+ //@ts-ignore
7
+ diffMilliseconds(dateA, dateB) / 6e4,
8
+ roundingMethod
9
+ );
6
10
  }
7
11
  export {
8
12
  diffMinutes
@@ -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, 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":[]}
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":[]}
@@ -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: DateInput): number;
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 };
@@ -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 =\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":[]}
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":[]}