@formkit/tempo 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -748,19 +748,19 @@ declare function diffDays(dateA: DateInput, dateB?: MaybeDateInput, roundingMeth
748
748
  declare function diffDays(dateA: MaybeDateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
749
749
 
750
750
  /**
751
- * Returns the difference between 2 dates in days.
751
+ * Returns the difference between 2 dates in weeks.
752
752
  * @param dateA - A date to compare with the right date
753
753
  * @param [dateB] - A date to compare with the left date or nothing to compare with the current time
754
754
  * @param [roundingMethod] - the rounding method to use, default: trunc
755
755
  */
756
- declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
756
+ declare function diffWeeks(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
757
757
  /**
758
- * Returns the difference between 2 dates in days.
758
+ * Returns the difference between 2 dates in weeks.
759
759
  * @param [dateA] - A date to compare with the right date or null to compare with the current time
760
760
  * @param dateB - A date to compare with the left date
761
761
  * @param [roundingMethod] - the rounding method to use, default: trunc
762
762
  */
763
- declare function diffWeeks(dateA: DateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
763
+ declare function diffWeeks(dateA: MaybeDateInput, dateB: DateInput, roundingMethod?: DiffRoundingMethod): number;
764
764
 
765
765
  /**
766
766
  * Returns the difference between 2 dates in months.
@@ -2,7 +2,9 @@
2
2
  import { date } from "./date.mjs";
3
3
  function minuteEnd(inputDate) {
4
4
  const d = date(inputDate);
5
- d.setSeconds(59, 999);
5
+ d.setTime(
6
+ d.getTime() + (59 - d.getSeconds()) * 1e3 + (999 - d.getMilliseconds())
7
+ );
6
8
  return d;
7
9
  }
8
10
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/minuteEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given minute.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function minuteEnd(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setSeconds(59, 999)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAkC;AAC1D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,IAAI,GAAG;AACpB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/minuteEnd.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for end of the given minute.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function minuteEnd(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n // Shift the timestamp instead of using local setters, which pick the first\n // occurrence of a repeated hour (DST fall-back).\n d.setTime(\n d.getTime() + (59 - d.getSeconds()) * 1000 + (999 - d.getMilliseconds())\n )\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAkC;AAC1D,QAAM,IAAI,KAAK,SAAS;AAGxB,IAAE;AAAA,IACA,EAAE,QAAQ,KAAK,KAAK,EAAE,WAAW,KAAK,OAAQ,MAAM,EAAE,gBAAgB;AAAA,EACxE;AACA,SAAO;AACT;","names":[]}
@@ -2,7 +2,7 @@
2
2
  import { date } from "./date.mjs";
3
3
  function minuteStart(inputDate) {
4
4
  const d = date(inputDate);
5
- d.setSeconds(0, 0);
5
+ d.setTime(d.getTime() - d.getSeconds() * 1e3 - d.getMilliseconds());
6
6
  return d;
7
7
  }
8
8
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/minuteStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given minute.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function minuteStart(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n d.setSeconds(0, 0)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,YAAY,WAAkC;AAC5D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,GAAG,CAAC;AACjB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/minuteStart.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a Date object for start of the given minute.\n * @param [inputDate] - A string, Date object or nothing for the current time\n */\nexport function minuteStart(inputDate?: MaybeDateInput): Date {\n const d = date(inputDate)\n // Shift the timestamp instead of using local setters, which pick the first\n // occurrence of a repeated hour (DST fall-back).\n d.setTime(d.getTime() - d.getSeconds() * 1000 - d.getMilliseconds())\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,YAAY,WAAkC;AAC5D,QAAM,IAAI,KAAK,SAAS;AAGxB,IAAE,QAAQ,EAAE,QAAQ,IAAI,EAAE,WAAW,IAAI,MAAO,EAAE,gBAAgB,CAAC;AACnE,SAAO;AACT;","names":[]}
@@ -10,23 +10,23 @@ function nearestDay(inputDate, search, constraint = 7) {
10
10
  const d = date(inputDate);
11
11
  switch (constraint) {
12
12
  case "month":
13
- decrements = d.getDate();
13
+ decrements = d.getDate() - 1;
14
14
  increments = monthDays(d) - d.getDate();
15
15
  break;
16
16
  case "week":
17
- decrements = d.getDay() + 1;
17
+ decrements = d.getDay();
18
18
  increments = 6 - d.getDay();
19
19
  break;
20
20
  case "year":
21
21
  const total = yearDays(d);
22
22
  const day = dayOfYear(d);
23
- decrements = day;
23
+ decrements = day - 1;
24
24
  increments = total - day;
25
25
  break;
26
26
  default:
27
27
  increments = decrements = constraint;
28
28
  }
29
- for (let i = 0; i <= increments || i < decrements; i++) {
29
+ for (let i = 0; i <= increments || i <= decrements; i++) {
30
30
  if (i <= increments) {
31
31
  const next = addDay(d, i);
32
32
  if (search(next)) return next;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/nearestDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport { yearDays } from \"./yearDays\"\nimport { dayOfYear } from \"./dayOfYear\"\nimport { addDay } from \"./addDay\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Performs a bidirectional search for the nearest date that passes a function.\n * @param [inputDate] - Performs a search for the nearest passing date.\n * @param search - The search function to use, given a date returns a boolean.\n * @param constraint - The number of iterations to perform before giving up, or logical constraint like \"month\", or \"week\".\n *\n */\nexport function nearestDay(\n inputDate: MaybeDateInput,\n search: (date: Date) => boolean,\n constraint: number | \"month\" | \"week\" | \"year\" = 7\n): Date | null {\n let increments: number\n let decrements: number\n const d = date(inputDate)\n switch (constraint) {\n case \"month\":\n decrements = d.getDate()\n increments = monthDays(d) - d.getDate()\n break\n case \"week\":\n decrements = d.getDay() + 1\n increments = 6 - d.getDay()\n break\n case \"year\":\n const total = yearDays(d)\n const day = dayOfYear(d)\n decrements = day\n increments = total - day\n break\n default:\n increments = decrements = constraint\n }\n\n for (let i = 0; i <= increments || i < decrements; i++) {\n if (i <= increments) {\n const next = addDay(d, i)\n if (search(next)) return next\n }\n if (i && i <= decrements) {\n const prev = addDay(d, -i)\n if (search(prev)) return prev\n }\n }\n return null\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AAUhB,SAAS,WACd,WACA,QACA,aAAiD,GACpC;AACb,MAAI;AACJ,MAAI;AACJ,QAAM,IAAI,KAAK,SAAS;AACxB,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,mBAAa,EAAE,QAAQ;AACvB,mBAAa,UAAU,CAAC,IAAI,EAAE,QAAQ;AACtC;AAAA,IACF,KAAK;AACH,mBAAa,EAAE,OAAO,IAAI;AAC1B,mBAAa,IAAI,EAAE,OAAO;AAC1B;AAAA,IACF,KAAK;AACH,YAAM,QAAQ,SAAS,CAAC;AACxB,YAAM,MAAM,UAAU,CAAC;AACvB,mBAAa;AACb,mBAAa,QAAQ;AACrB;AAAA,IACF;AACE,mBAAa,aAAa;AAAA,EAC9B;AAEA,WAAS,IAAI,GAAG,KAAK,cAAc,IAAI,YAAY,KAAK;AACtD,QAAI,KAAK,YAAY;AACnB,YAAM,OAAO,OAAO,GAAG,CAAC;AACxB,UAAI,OAAO,IAAI,EAAG,QAAO;AAAA,IAC3B;AACA,QAAI,KAAK,KAAK,YAAY;AACxB,YAAM,OAAO,OAAO,GAAG,CAAC,CAAC;AACzB,UAAI,OAAO,IAAI,EAAG,QAAO;AAAA,IAC3B;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/nearestDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport { yearDays } from \"./yearDays\"\nimport { dayOfYear } from \"./dayOfYear\"\nimport { addDay } from \"./addDay\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Performs a bidirectional search for the nearest date that passes a function.\n * @param [inputDate] - Performs a search for the nearest passing date.\n * @param search - The search function to use, given a date returns a boolean.\n * @param constraint - The number of iterations to perform before giving up, or logical constraint like \"month\", or \"week\".\n *\n */\nexport function nearestDay(\n inputDate: MaybeDateInput,\n search: (date: Date) => boolean,\n constraint: number | \"month\" | \"week\" | \"year\" = 7\n): Date | null {\n let increments: number\n let decrements: number\n const d = date(inputDate)\n switch (constraint) {\n case \"month\":\n decrements = d.getDate() - 1\n increments = monthDays(d) - d.getDate()\n break\n case \"week\":\n decrements = d.getDay()\n increments = 6 - d.getDay()\n break\n case \"year\":\n const total = yearDays(d)\n const day = dayOfYear(d)\n decrements = day - 1\n increments = total - day\n break\n default:\n increments = decrements = constraint\n }\n\n for (let i = 0; i <= increments || i <= decrements; i++) {\n if (i <= increments) {\n const next = addDay(d, i)\n if (search(next)) return next\n }\n if (i && i <= decrements) {\n const prev = addDay(d, -i)\n if (search(prev)) return prev\n }\n }\n return null\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AAUhB,SAAS,WACd,WACA,QACA,aAAiD,GACpC;AACb,MAAI;AACJ,MAAI;AACJ,QAAM,IAAI,KAAK,SAAS;AACxB,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,mBAAa,EAAE,QAAQ,IAAI;AAC3B,mBAAa,UAAU,CAAC,IAAI,EAAE,QAAQ;AACtC;AAAA,IACF,KAAK;AACH,mBAAa,EAAE,OAAO;AACtB,mBAAa,IAAI,EAAE,OAAO;AAC1B;AAAA,IACF,KAAK;AACH,YAAM,QAAQ,SAAS,CAAC;AACxB,YAAM,MAAM,UAAU,CAAC;AACvB,mBAAa,MAAM;AACnB,mBAAa,QAAQ;AACrB;AAAA,IACF;AACE,mBAAa,aAAa;AAAA,EAC9B;AAEA,WAAS,IAAI,GAAG,KAAK,cAAc,KAAK,YAAY,KAAK;AACvD,QAAI,KAAK,YAAY;AACnB,YAAM,OAAO,OAAO,GAAG,CAAC;AACxB,UAAI,OAAO,IAAI,EAAG,QAAO;AAAA,IAC3B;AACA,QAAI,KAAK,KAAK,YAAY;AACxB,YAAM,OAAO,OAAO,GAAG,CAAC,CAAC;AACzB,UAAI,OAAO,IAAI,EAAG,QAAO;AAAA,IAC3B;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formkit/tempo",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "packageManager": "pnpm@10.11.0",
5
5
  "description": "The easiest way to work with dates in JavaScript and TypeScript.",
6
6
  "type": "module",