@formkit/tempo 0.1.2 → 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 -142
  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 -145
  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 -5
  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
@@ -1,12 +1,19 @@
1
1
  import { DiffRoundingMethod } from './diffRound.js';
2
- import { DateInput } from './types.js';
2
+ import { DateInput, MaybeDateInput } from './types.js';
3
3
 
4
4
  /**
5
5
  * Returns the difference between 2 dates in seconds.
6
- * @param dateA A date to compare with the right date
7
- * @param dateB A date to compare with the left date
8
- * @param roundingMethod the rounding method to use, default: trunc
6
+ * @param dateA - A date to compare with the right date
7
+ * @param [dateB] - A date to compare with the left date or nothing to compare with the current time.
8
+ * @param [roundingMethod] - the rounding method to use, default: trunc
9
9
  */
10
- declare function diffSeconds(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
10
+ declare function diffSeconds(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
11
+ /**
12
+ * Returns the difference between 2 dates in seconds.
13
+ * @param [dateA] - A date to compare with the right date or null to compare with the current time
14
+ * @param dateB - A date to compare with the left date
15
+ * @param [roundingMethod] - the rounding method to use, default: trunc
16
+ */
17
+ declare function diffSeconds(dateA: MaybeDateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
11
18
 
12
19
  export { diffSeconds };
@@ -2,7 +2,11 @@
2
2
  import { diffMilliseconds } from "./diffMilliseconds.mjs";
3
3
  import { diffRound } from "./diffRound.mjs";
4
4
  function diffSeconds(dateA, dateB, roundingMethod) {
5
- return diffRound(diffMilliseconds(dateA, dateB) / 1e3, roundingMethod);
5
+ return diffRound(
6
+ // @ts-ignore
7
+ diffMilliseconds(dateA, dateB) / 1e3,
8
+ roundingMethod
9
+ );
6
10
  }
7
11
  export {
8
12
  diffSeconds
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/diffSeconds.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DiffRoundingMethod, diffRound } from \"./diffRound\"\nimport { DateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in seconds.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date\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":[]}
1
+ {"version":3,"sources":["../src/diffSeconds.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DiffRoundingMethod, diffRound } from \"./diffRound\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in seconds.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time.\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffSeconds(\n dateA: DateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\n/**\n * Returns the difference between 2 dates in seconds.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffSeconds(\n dateA: MaybeDateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffSeconds(\n dateA: MaybeDateInput,\n dateB?: MaybeDateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n // @ts-ignore\n diffMilliseconds(dateA, dateB) / 1000,\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAA6B,iBAAiB;AA2BvC,SAAS,YACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA;AAAA,IAEL,iBAAiB,OAAO,KAAK,IAAI;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
@@ -3,9 +3,16 @@ import { DiffRoundingMethod } from './diffRound.js';
3
3
 
4
4
  /**
5
5
  * Returns the difference between 2 dates in days.
6
- * @param dateA A date to compare with the right date
7
- * @param dateB A date to compare with the left date
8
- * @param roundingMethod the rounding method to use, default: trunc
6
+ * @param dateA - A date to compare with the right date
7
+ * @param [dateB] - A date to compare with the left date or nothing to compare with the current time
8
+ * @param [roundingMethod] - the rounding method to use, default: trunc
9
+ */
10
+ declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
11
+ /**
12
+ * Returns the difference between 2 dates in days.
13
+ * @param [dateA] - A date to compare with the right date or null to compare with the current time
14
+ * @param dateB - A date to compare with the left date
15
+ * @param [roundingMethod] - the rounding method to use, default: trunc
9
16
  */
10
17
  declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
11
18
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/diffWeeks.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DateInput } from \"./types\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in days.\n * @param dateA A date to compare with the right date\n * @param dateB A date to compare with the left date\n * @param roundingMethod the rounding method to use, default: trunc\n */\nexport function diffWeeks(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n) {\n return diffRound(\n diffMilliseconds(dateA, dateB) / 604800000, // day * 7\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,iBAA0C;AAQ5C,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/diffWeeks.ts"],"sourcesContent":["import { diffMilliseconds } from \"./diffMilliseconds\"\nimport { DateInput, MaybeDateInput } from \"./types\"\nimport { diffRound, type DiffRoundingMethod } from \"./diffRound\"\n\n/**\n * Returns the difference between 2 dates in days.\n * @param dateA - A date to compare with the right date\n * @param [dateB] - A date to compare with the left date or nothing to compare with the current time\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffWeeks(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\n/**\n * Returns the difference between 2 dates in days.\n * @param [dateA] - A date to compare with the right date or null to compare with the current time\n * @param dateB - A date to compare with the left date\n * @param [roundingMethod] - the rounding method to use, default: trunc\n */\nexport function diffWeeks(\n dateA: DateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number\n\nexport function diffWeeks(\n dateA: MaybeDateInput,\n dateB: DateInput,\n roundingMethod?: DiffRoundingMethod\n): number {\n return diffRound(\n diffMilliseconds(dateA, dateB) / 604800000, // day * 7\n roundingMethod\n )\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,iBAA0C;AA0B5C,SAAS,UACd,OACA,OACA,gBACQ;AACR,SAAO;AAAA,IACL,iBAAiB,OAAO,KAAK,IAAI;AAAA;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
@@ -1,10 +1,16 @@
1
- import { DateInput } from './types.js';
1
+ import { DateInput, MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns the difference between 2 dates in years.
5
- * @param dateA A date to compare with the dateB date
6
- * @param dateB A date to compare with the dateA date
5
+ * @param dateA - A date to compare with the dateB date
6
+ * @param [dateB] - A date to compare with the dateA date or nothing to compare with the current time
7
7
  */
8
- declare function diffYears(dateA: DateInput, dateB: DateInput): number;
8
+ declare function diffYears(dateA: DateInput, dateB?: MaybeDateInput): number;
9
+ /**
10
+ * Returns the difference between 2 dates in years.
11
+ * @param [dateA] - A date to compare with the dateB date or null to compare with the current time
12
+ * @param dateB - A date to compare with the dateA date
13
+ */
14
+ declare function diffYears(dateA: MaybeDateInput, dateB: DateInput): number;
9
15
 
10
16
  export { diffYears };
@@ -1,7 +1,10 @@
1
1
  // src/diffYears.ts
2
2
  import { diffMonths } from "./diffMonths.mjs";
3
3
  function diffYears(dateA, dateB) {
4
- const r = Math.trunc(diffMonths(dateA, dateB) / 12);
4
+ const r = Math.trunc(
5
+ //@ts-ignore
6
+ diffMonths(dateA, dateB) / 12
7
+ );
5
8
  return r == 0 ? 0 : r;
6
9
  }
7
10
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/diffYears.ts"],"sourcesContent":["import { diffMonths } from \"./diffMonths\"\nimport { DateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in years.\n * @param dateA A date to compare with the dateB date\n * @param dateB A date to compare with the dateA date\n */\nexport function diffYears(dateA: DateInput, dateB: DateInput): number {\n const r = Math.trunc(diffMonths(dateA, dateB) / 12)\n //ensures we don't give back -0\n return r == 0 ? 0 : r\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAQpB,SAAS,UAAU,OAAkB,OAA0B;AACpE,QAAM,IAAI,KAAK,MAAM,WAAW,OAAO,KAAK,IAAI,EAAE;AAElD,SAAO,KAAK,IAAI,IAAI;AACtB;","names":[]}
1
+ {"version":3,"sources":["../src/diffYears.ts"],"sourcesContent":["import { diffMonths } from \"./diffMonths\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns the difference between 2 dates in years.\n * @param dateA - A date to compare with the dateB date\n * @param [dateB] - A date to compare with the dateA date or nothing to compare with the current time\n */\nexport function diffYears(dateA: DateInput, dateB?: MaybeDateInput): number\n\n/**\n * Returns the difference between 2 dates in years.\n * @param [dateA] - A date to compare with the dateB date or null to compare with the current time\n * @param dateB - A date to compare with the dateA date\n */\nexport function diffYears(dateA: MaybeDateInput, dateB: DateInput): number\nexport function diffYears(dateA: MaybeDateInput, dateB?: MaybeDateInput): number {\n const r = Math.trunc(\n //@ts-ignore\n diffMonths(dateA, dateB) / 12\n )\n //ensures we don't give back -0\n return r == 0 ? 0 : r\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAgBpB,SAAS,UAAU,OAAuB,OAAgC;AAC/E,QAAM,IAAI,KAAK;AAAA;AAAA,IAEb,WAAW,OAAO,KAAK,IAAI;AAAA,EAC7B;AAEA,SAAO,KAAK,IAAI,IAAI;AACtB;","names":[]}
package/dist/format.mjs CHANGED
@@ -19,8 +19,7 @@ function format(inputDateOrOptions, format2 = "long", locale = "device", genitiv
19
19
  tz
20
20
  } = inputDateOrOptions);
21
21
  }
22
- if (format2 === "ISO8601")
23
- return date(inputDateOrOptions).toISOString();
22
+ if (format2 === "ISO8601") return date(inputDateOrOptions).toISOString();
24
23
  if (tz) {
25
24
  forceOffset = offset(inputDateOrOptions, "utc", tz, getOffsetFormat(format2));
26
25
  }
@@ -36,7 +35,7 @@ function format(inputDateOrOptions, format2 = "long", locale = "device", genitiv
36
35
  }
37
36
  return fill(
38
37
  inputDateOrOptions,
39
- parts(format2, locale).filter(partFilter != null ? partFilter : () => true),
38
+ parts(format2, locale).filter(partFilter != null ? partFilter : (() => true)),
40
39
  locale,
41
40
  genitive,
42
41
  forceOffset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/format.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { parts } from \"./parts\"\nimport { fill, getOffsetFormat } from \"./common\"\nimport type {\n DateInput,\n Format,\n FormatOptions,\n FormatStyle,\n Part,\n} from \"./types\"\nimport { offset } from \"./offset\"\nimport { removeOffset } from \"./removeOffset\"\nimport { deviceLocale } from \"./deviceLocale\"\nimport { deviceTZ } from \"./deviceTZ\"\n\n/**\n * Produce a formatted string. Available strings:\n * token | description\n * ------|------------\n * YY | 2 digit year\n * YYYY | 4 digit year\n * M | The month 1-12\n * MM | The month 01-12\n * MMM | Short name Jan-Dec\n * MMMM | Full name January | December\n * D | The day of the month 1-31\n * DD | The day of the month 01-31\n * d | Single digit day \"T\"\n * ddd | Short day name Thu\n * dddd | Full day name Wednesday\n * H | Minimum hour digits, 24 hour, 0-23\n * HH | 2 hour digits, 24 hour, 00-23\n * h | Minimum hour digits, 12 hour clock, 1-12\n * hh | 2 hour digits, 12 hour clock, 01-12\n * m | The minute 0-59\n * mm | The minute 00-59\n * s | The second 0-59\n * ss | The second 00-59\n * a | am/pm\n * A | AM/PM\n * Z | +0800, +0530, -1345\n *\n * @param inputDate - A date object or ISO 8601 string\n * @param format - A format\n */\nexport function format(options: FormatOptions): string\nexport function format(\n inputDate: DateInput,\n format?: Format,\n locale?: string,\n genitive?: boolean,\n partFilter?: (part: Part) => boolean\n): string\nexport function format(\n inputDateOrOptions: DateInput | FormatOptions,\n format: Format = \"long\",\n locale: string | undefined = \"device\",\n genitive: boolean | undefined = false,\n partFilter?: (part: Part) => boolean\n): string {\n let tz: string | undefined, forceOffset: string | undefined\n\n if (\n typeof inputDateOrOptions === \"object\" &&\n !(inputDateOrOptions instanceof Date)\n ) {\n // Extract options from the object.\n ;({\n date: inputDateOrOptions,\n format,\n locale,\n genitive,\n partFilter,\n tz,\n } = inputDateOrOptions)\n }\n // ISO 8601 is a special case because it doesn't require a format.\n if (format === \"ISO8601\") return date(inputDateOrOptions).toISOString()\n\n if (tz) {\n forceOffset = offset(inputDateOrOptions, \"utc\", tz, getOffsetFormat(format))\n }\n\n // We need to apply an offset to the date so that it can be formatted as UTC.\n tz ??= deviceTZ()\n if (tz?.toLowerCase() !== \"utc\") {\n inputDateOrOptions = removeOffset(\n inputDateOrOptions,\n offset(inputDateOrOptions, tz, \"utc\")\n )\n }\n\n if (!locale || locale === \"device\") {\n locale = deviceLocale()\n }\n\n return fill(\n inputDateOrOptions,\n parts(format, locale).filter(partFilter ?? (() => true)),\n locale,\n genitive,\n forceOffset\n )\n .map((p) => p.value)\n .join(\"\")\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,MAAM,uBAAuB;AAQtC,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AAwClB,SAAS,OACd,oBACAA,UAAiB,QACjB,SAA6B,UAC7B,WAAgC,OAChC,YACQ;AACR,MAAI,IAAwB;AAE5B,MACE,OAAO,uBAAuB,YAC9B,EAAE,8BAA8B,OAChC;AAEA;AAAC,KAAC;AAAA,MACA,MAAM;AAAA,MACN,QAAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAAA,EACN;AAEA,MAAIA,YAAW;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"]}
1
+ {"version":3,"sources":["../src/format.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { parts } from \"./parts\"\nimport { fill, getOffsetFormat } from \"./common\"\nimport type {\n DateInput,\n Format,\n FormatOptions,\n FormatStyle,\n Part,\n} from \"./types\"\nimport { offset } from \"./offset\"\nimport { removeOffset } from \"./removeOffset\"\nimport { deviceLocale } from \"./deviceLocale\"\nimport { deviceTZ } from \"./deviceTZ\"\n\n/**\n * Produce a formatted string. Available strings:\n * token | description\n * ------|------------\n * YY | 2 digit year\n * YYYY | 4 digit year\n * M | The month 1-12\n * MM | The month 01-12\n * MMM | Short name Jan-Dec\n * MMMM | Full name January | December\n * D | The day of the month 1-31\n * DD | The day of the month 01-31\n * d | Single digit day \"T\"\n * ddd | Short day name Thu\n * dddd | Full day name Wednesday\n * H | Minimum hour digits, 24 hour, 0-23\n * HH | 2 hour digits, 24 hour, 00-23\n * h | Minimum hour digits, 12 hour clock, 1-12\n * hh | 2 hour digits, 12 hour clock, 01-12\n * m | The minute 0-59\n * mm | The minute 00-59\n * s | The second 0-59\n * ss | The second 00-59\n * a | am/pm\n * A | AM/PM\n * Z | +0800, +0530, -1345\n *\n * @param inputDate - A date object or ISO 8601 string\n * @param format - A format\n */\nexport function format(options: FormatOptions): string\nexport function format(\n inputDate: DateInput,\n format?: Format,\n locale?: string,\n genitive?: boolean,\n partFilter?: (part: Part) => boolean\n): string\nexport function format(\n inputDateOrOptions: DateInput | FormatOptions,\n format: Format = \"long\",\n locale: string | undefined = \"device\",\n genitive: boolean | undefined = false,\n partFilter?: (part: Part) => boolean\n): string {\n let tz: string | undefined, forceOffset: string | undefined\n\n if (\n typeof inputDateOrOptions === \"object\" &&\n !(inputDateOrOptions instanceof Date)\n ) {\n // Extract options from the object.\n ;({\n date: inputDateOrOptions,\n format,\n locale,\n genitive,\n partFilter,\n tz,\n } = inputDateOrOptions)\n }\n // ISO 8601 is a special case because it doesn't require a format.\n if (format === \"ISO8601\") return date(inputDateOrOptions).toISOString()\n\n if (tz) {\n forceOffset = offset(inputDateOrOptions, \"utc\", tz, getOffsetFormat(format))\n }\n\n // We need to apply an offset to the date so that it can be formatted as UTC.\n tz ??= deviceTZ()\n if (tz?.toLowerCase() !== \"utc\") {\n inputDateOrOptions = removeOffset(\n inputDateOrOptions,\n offset(inputDateOrOptions, tz, \"utc\")\n )\n }\n\n if (!locale || locale === \"device\") {\n locale = deviceLocale()\n }\n\n return fill(\n inputDateOrOptions,\n parts(format, locale).filter(partFilter ?? (() => true)),\n locale,\n genitive,\n forceOffset\n )\n .map((p) => p.value)\n .join(\"\")\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,MAAM,uBAAuB;AAQtC,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AAwClB,SAAS,OACd,oBACAA,UAAiB,QACjB,SAA6B,UAC7B,WAAgC,OAChC,YACQ;AACR,MAAI,IAAwB;AAE5B,MACE,OAAO,uBAAuB,YAC9B,EAAE,8BAA8B,OAChC;AAEA;AAAC,KAAC;AAAA,MACA,MAAM;AAAA,MACN,QAAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAAA,EACN;AAEA,MAAIA,YAAW,UAAW,QAAO,KAAK,kBAAkB,EAAE,YAAY;AAEtE,MAAI,IAAI;AACN,kBAAc,OAAO,oBAAoB,OAAO,IAAI,gBAAgBA,OAAM,CAAC;AAAA,EAC7E;AAGA,yBAAO,SAAS;AAChB,OAAI,yBAAI,mBAAkB,OAAO;AAC/B,yBAAqB;AAAA,MACnB;AAAA,MACA,OAAO,oBAAoB,IAAI,KAAK;AAAA,IACtC;AAAA,EACF;AAEA,MAAI,CAAC,UAAU,WAAW,UAAU;AAClC,aAAS,aAAa;AAAA,EACxB;AAEA,SAAO;AAAA,IACL;AAAA,IACA,MAAMA,SAAQ,MAAM,EAAE,OAAO,mCAAe,MAAM,KAAK;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,EACF,EACG,IAAI,CAAC,MAAM,EAAE,KAAK,EAClB,KAAK,EAAE;AACZ;","names":["format"]}
package/dist/hourEnd.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 hour.
5
- * @param inputDate - A string or Date object
5
+ * @param [inputDate] - A string, Date object or nothing for the current time
6
6
  */
7
- declare function hourEnd(inputDate: DateInput): Date;
7
+ declare function hourEnd(inputDate?: MaybeDateInput): Date;
8
8
 
9
9
  export { hourEnd };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hourEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given hour.\n * @param inputDate - A string or Date object\n */\nexport function hourEnd(inputDate: DateInput): Date {\n const d = date(inputDate)\n d.setMinutes(59, 59, 999)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,QAAQ,WAA4B;AAClD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,IAAI,IAAI,GAAG;AACxB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/hourEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given hour.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function hourEnd(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setMinutes(59, 59, 999)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,QAAQ,WAAkC;AACxD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,IAAI,IAAI,GAAG;AACxB,SAAO;AACT;","names":[]}
@@ -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 hour.
5
- * @param inputDate - A string or Date object
5
+ * @param [inputDate] - A string, Date object or nothing for the current time
6
6
  */
7
- declare function hourStart(inputDate: DateInput): Date;
7
+ declare function hourStart(inputDate?: MaybeDateInput): Date;
8
8
 
9
9
  export { hourStart };
@@ -2,7 +2,7 @@
2
2
  import { date } from "./date.mjs";
3
3
  function hourStart(inputDate) {
4
4
  const d = date(inputDate);
5
- d.setMinutes(0, 0);
5
+ d.setMinutes(0, 0, 0);
6
6
  return d;
7
7
  }
8
8
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hourStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given hour.\n * @param inputDate - A string or Date object\n */\nexport function hourStart(inputDate: DateInput): Date {\n const d = date(inputDate)\n d.setMinutes(0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAA4B;AACpD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,GAAG,CAAC;AACjB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/hourStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given hour.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function hourStart(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setMinutes(0, 0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAkC;AAC1D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,GAAG,GAAG,CAAC;AACpB,SAAO;AACT;","names":[]}