@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/addDay.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a new date object 1/n days after the original one.
5
- * @param inputDate - A date to increment by 1 day.
5
+ * @param [inputDate] - A date to increment or null to increment from the current time.
6
+ * @param [count] - The quantity to add.
6
7
  */
7
- declare function addDay(inputDate: DateInput, count?: number): Date;
8
+ declare function addDay(inputDate?: MaybeDateInput, count?: number): Date;
8
9
 
9
10
  export { addDay };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/addDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n days after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addDay(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setDate(d.getDate() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,OAAO,WAAsB,QAAQ,GAAG;AACtD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,QAAQ,EAAE,QAAQ,IAAI,KAAK;AAC7B,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/addDay.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n days after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addDay(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setDate(d.getDate() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,OAAO,WAA4B,QAAQ,GAAG;AAC5D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,QAAQ,EAAE,QAAQ,IAAI,KAAK;AAC7B,SAAO;AACT;","names":[]}
package/dist/addHour.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a new date object 1/n hours after the original one.
5
- * @param inputDate - A date to increment by 1 day.
5
+ * @param [inputDate] - A date to increment or null to increment from the current time.
6
+ * @param [count] - The quantity to add.
6
7
  */
7
- declare function addHour(inputDate: DateInput, count?: number): Date;
8
+ declare function addHour(inputDate?: MaybeDateInput, count?: number): Date;
8
9
 
9
10
  export { addHour };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/addHour.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n hours after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addHour(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setHours(d.getHours() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,QAAQ,WAAsB,QAAQ,GAAG;AACvD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAC/B,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/addHour.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n hours after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addHour(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setHours(d.getHours() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,QAAQ,WAA4B,QAAQ,GAAG;AAC7D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAC/B,SAAO;AACT;","names":[]}
@@ -0,0 +1,10 @@
1
+ import { MaybeDateInput } from './types.js';
2
+
3
+ /**
4
+ * Returns a new date object 1/n milliseconds after the original one.
5
+ * @param [inputDate] - A date to increment or null to increment from the current time.
6
+ * @param [count] - The quantity to add.
7
+ */
8
+ declare function addMillisecond(inputDate?: MaybeDateInput, count?: number): Date;
9
+
10
+ export { addMillisecond };
@@ -0,0 +1,11 @@
1
+ // src/addMillisecond.ts
2
+ import { date } from "./date.mjs";
3
+ function addMillisecond(inputDate, count = 1) {
4
+ const d = date(inputDate);
5
+ d.setMilliseconds(d.getMilliseconds() + count);
6
+ return d;
7
+ }
8
+ export {
9
+ addMillisecond
10
+ };
11
+ //# sourceMappingURL=addMillisecond.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/addMillisecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n milliseconds after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addMillisecond(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setMilliseconds(d.getMilliseconds() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,eAAe,WAA4B,QAAQ,GAAG;AACpE,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,gBAAgB,EAAE,gBAAgB,IAAI,KAAK;AAC7C,SAAO;AACT;","names":[]}
@@ -1,9 +1,10 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
- * Returns a new date object 1/n seconds after the original one.
5
- * @param inputDate - A date to increment by 1 day.
4
+ * Returns a new date object 1/n minutes after the original one.
5
+ * @param [inputDate] - A date to increment or null to increment from the current time.
6
+ * @param [count] - The quantity to add.
6
7
  */
7
- declare function addMinute(inputDate: DateInput, count?: number): Date;
8
+ declare function addMinute(inputDate?: MaybeDateInput, count?: number): Date;
8
9
 
9
10
  export { addMinute };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/addMinute.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n seconds after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addMinute(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setMinutes(d.getMinutes() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAsB,QAAQ,GAAG;AACzD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/addMinute.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n minutes after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addMinute(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setMinutes(d.getMinutes() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,UAAU,WAA4B,QAAQ,GAAG;AAC/D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
@@ -1,13 +1,13 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a new date object 1/n months after the original one. Keep in mind if you
5
5
  * start with a date late in a given month you could get a date after the next
6
6
  * month.
7
- * @param inputDate - A date to increment by 1 or more months.
8
- * @param count - The quantity to add.
9
- * @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
7
+ * @param [inputDate] - A date to increment or null to increment from the current time
8
+ * @param [count] - The quantity to add.
9
+ * @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
10
10
  */
11
- declare function addMonth(inputDate: DateInput, count?: number, dateOverflow?: boolean): Date;
11
+ declare function addMonth(inputDate?: MaybeDateInput, count?: number, dateOverflow?: boolean): Date;
12
12
 
13
13
  export { addMonth };
package/dist/addMonth.mjs CHANGED
@@ -4,8 +4,7 @@ import { monthDays } from "./monthDays.mjs";
4
4
  function addMonth(inputDate, count = 1, dateOverflow = false) {
5
5
  const d = date(inputDate);
6
6
  const dayOfMonth = d.getDate();
7
- if (!dateOverflow)
8
- d.setDate(1);
7
+ if (!dateOverflow) d.setDate(1);
9
8
  d.setMonth(d.getMonth() + count);
10
9
  if (!dateOverflow) {
11
10
  const daysInMonth = monthDays(d);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/addMonth.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n months after the original one. Keep in mind if you\n * start with a date late in a given month you could get a date after the next\n * month.\n * @param inputDate - A date to increment by 1 or more months.\n * @param count - The quantity to add.\n * @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addMonth(\n inputDate: DateInput,\n count = 1,\n dateOverflow = false\n) {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n d.setMonth(d.getMonth() + count)\n\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAWnB,SAAS,SACd,WACA,QAAQ,GACR,eAAe,OACf;AACA,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC;AAAc,MAAE,QAAQ,CAAC;AAC9B,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAI/B,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/addMonth.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { DateInput, MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n months after the original one. Keep in mind if you\n * start with a date late in a given month you could get a date after the next\n * month.\n * @param [inputDate] - A date to increment or null to increment from the current time\n * @param [count] - The quantity to add.\n * @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addMonth(inputDate?: MaybeDateInput, count = 1, dateOverflow = false) {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n d.setMonth(d.getMonth() + count)\n\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAWnB,SAAS,SAAS,WAA4B,QAAQ,GAAG,eAAe,OAAO;AACpF,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC,aAAc,GAAE,QAAQ,CAAC;AAC9B,IAAE,SAAS,EAAE,SAAS,IAAI,KAAK;AAI/B,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
@@ -1,9 +1,10 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a new date object 1/n seconds after the original one.
5
- * @param inputDate - A date to increment by 1 day.
5
+ * @param [inputDate] - A date to increment or null to increment from the current time.
6
+ * @param [count] - The quantity to add.
6
7
  */
7
- declare function addSecond(inputDate: DateInput, count?: number): Date;
8
+ declare function addSecond(inputDate?: MaybeDateInput, count?: number): Date;
8
9
 
9
10
  export { addSecond };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/addSecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n seconds after the original one.\n * @param inputDate - A date to increment by 1 day.\n */\nexport function addSecond(inputDate: DateInput, count = 1) {\n const d = date(inputDate)\n d.setSeconds(d.getSeconds() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAOd,SAAS,UAAU,WAAsB,QAAQ,GAAG;AACzD,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/addSecond.ts"],"sourcesContent":["import { date } from \"./date\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n seconds after the original one.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity to add.\n */\nexport function addSecond(inputDate?: MaybeDateInput, count = 1) {\n const d = date(inputDate)\n d.setSeconds(d.getSeconds() + count)\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAQd,SAAS,UAAU,WAA4B,QAAQ,GAAG;AAC/D,QAAM,IAAI,KAAK,SAAS;AACxB,IAAE,WAAW,EAAE,WAAW,IAAI,KAAK;AACnC,SAAO;AACT;","names":[]}
package/dist/addYear.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Returns a new date object 1/n years after the original one. Keep in mind if
5
5
  * you start with a date late in a given month you could get a date after the
6
6
  * next month.
7
- * @param inputDate - A date to increment by 1 day.
8
- * @param count - The quantity of years add.
9
- * @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
7
+ * @param [inputDate] - A date to increment or null to increment from the current time.
8
+ * @param [count] - The quantity of years add.
9
+ * @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.
10
10
  */
11
- declare function addYear(inputDate: DateInput, count?: number, dateOverflow?: boolean): Date;
11
+ declare function addYear(inputDate?: MaybeDateInput, count?: number, dateOverflow?: boolean): Date;
12
12
 
13
13
  export { addYear };
package/dist/addYear.mjs CHANGED
@@ -4,8 +4,7 @@ import { monthDays } from "./monthDays.mjs";
4
4
  function addYear(inputDate, count = 1, dateOverflow = false) {
5
5
  const d = date(inputDate);
6
6
  const dayOfMonth = d.getDate();
7
- if (!dateOverflow)
8
- d.setDate(1);
7
+ if (!dateOverflow) d.setDate(1);
9
8
  d.setFullYear(d.getFullYear() + count);
10
9
  if (!dateOverflow) {
11
10
  const daysInMonth = monthDays(d);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/addYear.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n years after the original one. Keep in mind if\n * you start with a date late in a given month you could get a date after the\n * next month.\n * @param inputDate - A date to increment by 1 day.\n * @param count - The quantity of years add.\n * @param dateOverflow - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addYear(inputDate: DateInput, count = 1, dateOverflow = false) {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n\n d.setFullYear(d.getFullYear() + count)\n\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAWnB,SAAS,QAAQ,WAAsB,QAAQ,GAAG,eAAe,OAAO;AAC7E,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC;AAAc,MAAE,QAAQ,CAAC;AAE9B,IAAE,YAAY,EAAE,YAAY,IAAI,KAAK;AAIrC,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/addYear.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { monthDays } from \"./monthDays\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Returns a new date object 1/n years after the original one. Keep in mind if\n * you start with a date late in a given month you could get a date after the\n * next month.\n * @param [inputDate] - A date to increment or null to increment from the current time.\n * @param [count] - The quantity of years add.\n * @param [dateOverflow] - Whether or not to allow the date to overflow to another month if the inputDate’s month is out of range of the new month.\n */\nexport function addYear(inputDate?: MaybeDateInput, count = 1, dateOverflow = false) {\n const d = date(inputDate)\n const dayOfMonth = d.getDate()\n // If overflowing is disallowed, set the date back to the first of the month\n if (!dateOverflow) d.setDate(1)\n\n d.setFullYear(d.getFullYear() + count)\n\n // If overflowing is disallowed, we need to set the date back to the proper\n // day or the last day of the month.\n if (!dateOverflow) {\n const daysInMonth = monthDays(d)\n d.setDate(daysInMonth < dayOfMonth ? daysInMonth : dayOfMonth)\n }\n return d\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAWnB,SAAS,QAAQ,WAA4B,QAAQ,GAAG,eAAe,OAAO;AACnF,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,aAAa,EAAE,QAAQ;AAE7B,MAAI,CAAC,aAAc,GAAE,QAAQ,CAAC;AAE9B,IAAE,YAAY,EAAE,YAAY,IAAI,KAAK;AAIrC,MAAI,CAAC,cAAc;AACjB,UAAM,cAAc,UAAU,CAAC;AAC/B,MAAE,QAAQ,cAAc,aAAa,cAAc,UAAU;AAAA,EAC/D;AACA,SAAO;AACT;","names":[]}
package/dist/ap.mjs CHANGED
@@ -2,8 +2,7 @@
2
2
  import { dayPeriodMap, specDate, normStr } from "./common.mjs";
3
3
  function ap(ampm, locale) {
4
4
  const l = dayPeriodMap.get(locale);
5
- if (l && l[ampm])
6
- return l[ampm];
5
+ if (l && l[ampm]) return l[ampm];
7
6
  const specimen = new Date(specDate);
8
7
  specimen.setUTCHours(ampm === "am" ? 5 : 20);
9
8
  const subparts = new Intl.DateTimeFormat(locale, {
package/dist/ap.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ap.ts"],"sourcesContent":["import { dayPeriodMap, specDate, normStr } from \"./common\"\n\n/**\n * Determines the correct value for am/pm by locale and memoizes it.\n * @param ampm - am or pm\n * @param locale - The locale to fetch.\n */\nexport function ap(ampm: \"am\" | \"pm\", locale: string): string {\n const l = dayPeriodMap.get(locale)\n if (l && l[ampm]) return l[ampm] as string\n const specimen = new Date(specDate)\n specimen.setUTCHours(ampm === \"am\" ? 5 : 20)\n const subparts = new Intl.DateTimeFormat(locale, {\n timeStyle: \"full\",\n timeZone: \"UTC\",\n hour12: true,\n })\n .formatToParts(specimen)\n .map(normStr)\n const period = subparts.find((part) => part.type === \"dayPeriod\")\n if (period) {\n const localePeriods: { am?: string; pm?: string } = l || {}\n dayPeriodMap.set(\n locale,\n Object.assign(localePeriods, { [ampm]: period.value })\n )\n return period.value\n }\n return ampm\n}\n"],"mappings":";AAAA,SAAS,cAAc,UAAU,eAAe;AAOzC,SAAS,GAAG,MAAmB,QAAwB;AAC5D,QAAM,IAAI,aAAa,IAAI,MAAM;AACjC,MAAI,KAAK,EAAE,IAAI;AAAG,WAAO,EAAE,IAAI;AAC/B,QAAM,WAAW,IAAI,KAAK,QAAQ;AAClC,WAAS,YAAY,SAAS,OAAO,IAAI,EAAE;AAC3C,QAAM,WAAW,IAAI,KAAK,eAAe,QAAQ;AAAA,IAC/C,WAAW;AAAA,IACX,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC,EACE,cAAc,QAAQ,EACtB,IAAI,OAAO;AACd,QAAM,SAAS,SAAS,KAAK,CAAC,SAAS,KAAK,SAAS,WAAW;AAChE,MAAI,QAAQ;AACV,UAAM,gBAA8C,KAAK,CAAC;AAC1D,iBAAa;AAAA,MACX;AAAA,MACA,OAAO,OAAO,eAAe,EAAE,CAAC,IAAI,GAAG,OAAO,MAAM,CAAC;AAAA,IACvD;AACA,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/ap.ts"],"sourcesContent":["import { dayPeriodMap, specDate, normStr } from \"./common\"\n\n/**\n * Determines the correct value for am/pm by locale and memoizes it.\n * @param ampm - am or pm\n * @param locale - The locale to fetch.\n */\nexport function ap(ampm: \"am\" | \"pm\", locale: string): string {\n const l = dayPeriodMap.get(locale)\n if (l && l[ampm]) return l[ampm] as string\n const specimen = new Date(specDate)\n specimen.setUTCHours(ampm === \"am\" ? 5 : 20)\n const subparts = new Intl.DateTimeFormat(locale, {\n timeStyle: \"full\",\n timeZone: \"UTC\",\n hour12: true,\n })\n .formatToParts(specimen)\n .map(normStr)\n const period = subparts.find((part) => part.type === \"dayPeriod\")\n if (period) {\n const localePeriods: { am?: string; pm?: string } = l || {}\n dayPeriodMap.set(\n locale,\n Object.assign(localePeriods, { [ampm]: period.value })\n )\n return period.value\n }\n return ampm\n}\n"],"mappings":";AAAA,SAAS,cAAc,UAAU,eAAe;AAOzC,SAAS,GAAG,MAAmB,QAAwB;AAC5D,QAAM,IAAI,aAAa,IAAI,MAAM;AACjC,MAAI,KAAK,EAAE,IAAI,EAAG,QAAO,EAAE,IAAI;AAC/B,QAAM,WAAW,IAAI,KAAK,QAAQ;AAClC,WAAS,YAAY,SAAS,OAAO,IAAI,EAAE;AAC3C,QAAM,WAAW,IAAI,KAAK,eAAe,QAAQ;AAAA,IAC/C,WAAW;AAAA,IACX,UAAU;AAAA,IACV,QAAQ;AAAA,EACV,CAAC,EACE,cAAc,QAAQ,EACtB,IAAI,OAAO;AACd,QAAM,SAAS,SAAS,KAAK,CAAC,SAAS,KAAK,SAAS,WAAW;AAChE,MAAI,QAAQ;AACV,UAAM,gBAA8C,KAAK,CAAC;AAC1D,iBAAa;AAAA,MACX;AAAA,MACA,OAAO,OAAO,eAAe,EAAE,CAAC,IAAI,GAAG,OAAO,MAAM,CAAC;AAAA,IACvD;AACA,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;","names":[]}
@@ -1,11 +1,11 @@
1
- import { DateInput } from './types.js';
1
+ import { MaybeDateInput } from './types.js';
2
2
 
3
3
  /**
4
4
  * Apply a given offset to a date, returning a new date with the offset
5
- * applied by adding or subtracting the given number of minutes.
6
- * @param dateInput - The date to apply the offset to.
7
- * @param offset - The offset to apply in the +-HHmm or +-HH:mm format.
5
+ * applied by adding or subtracting the given number of seconds.
6
+ * @param [dateInput] - The date to apply the offset to. (default: current time)
7
+ * @param [offset] - The offset to apply in the +-HHmm, +-HH:mm, +-HHmmss, or +-HH:mm:ss format.
8
8
  */
9
- declare function applyOffset(dateInput: DateInput, offset?: string): Date;
9
+ declare function applyOffset(dateInput?: MaybeDateInput, offset?: string): Date;
10
10
 
11
11
  export { applyOffset };
@@ -1,18 +1,12 @@
1
1
  // src/applyOffset.ts
2
2
  import { date } from "./date.mjs";
3
- import { fixedLengthByOffset, offsetToMins } from "./common.mjs";
3
+ import { fixedLengthByOffset, offsetToSecs } from "./common.mjs";
4
4
  function applyOffset(dateInput, offset = "+00:00") {
5
5
  const d = date(dateInput);
6
- const token = (() => {
7
- switch (fixedLengthByOffset(offset)) {
8
- case 5:
9
- return "ZZ";
10
- case 6:
11
- return "Z";
12
- }
13
- })();
14
- const timeDiffInMins = offsetToMins(offset, token);
15
- return new Date(d.getTime() + timeDiffInMins * 1e3 * 60);
6
+ const len = fixedLengthByOffset(offset);
7
+ const token = len === 5 || len === 8 ? "ZZ" : "Z";
8
+ const timeDiffInSecs = offsetToSecs(offset, token);
9
+ return new Date(d.getTime() + timeDiffInSecs * 1e3);
16
10
  }
17
11
  export {
18
12
  applyOffset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/applyOffset.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { TimezoneToken, fixedLengthByOffset, offsetToMins } from \"./common\"\nimport type { DateInput } from \"./types\"\n\n/**\n * Apply a given offset to a date, returning a new date with the offset\n * applied by adding or subtracting the given number of minutes.\n * @param dateInput - The date to apply the offset to.\n * @param offset - The offset to apply in the +-HHmm or +-HH:mm format.\n */\nexport function applyOffset(dateInput: DateInput, offset = \"+00:00\"): Date {\n const d = date(dateInput)\n const token = ((): TimezoneToken => {\n switch (fixedLengthByOffset(offset)) {\n case 5:\n return \"ZZ\"\n case 6:\n return \"Z\"\n }\n })()\n const timeDiffInMins = offsetToMins(offset, token)\n return new Date(d.getTime() + timeDiffInMins * 1000 * 60)\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAwB,qBAAqB,oBAAoB;AAS1D,SAAS,YAAY,WAAsB,SAAS,UAAgB;AACzE,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,SAAS,MAAqB;AAClC,YAAQ,oBAAoB,MAAM,GAAG;AAAA,MACnC,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,IACX;AAAA,EACF,GAAG;AACH,QAAM,iBAAiB,aAAa,QAAQ,KAAK;AACjD,SAAO,IAAI,KAAK,EAAE,QAAQ,IAAI,iBAAiB,MAAO,EAAE;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../src/applyOffset.ts"],"sourcesContent":["import { date } from \"./date\"\nimport { TimezoneToken, fixedLengthByOffset, offsetToSecs } from \"./common\"\nimport type { MaybeDateInput } from \"./types\"\n\n/**\n * Apply a given offset to a date, returning a new date with the offset\n * applied by adding or subtracting the given number of seconds.\n * @param [dateInput] - The date to apply the offset to. (default: current time)\n * @param [offset] - The offset to apply in the +-HHmm, +-HH:mm, +-HHmmss, or +-HH:mm:ss format.\n */\nexport function applyOffset(dateInput?: MaybeDateInput, offset = \"+00:00\"): Date {\n const d = date(dateInput)\n const len = fixedLengthByOffset(offset)\n // 5 or 8 chars = no colons (ZZ format), 6 or 9 chars = with colons (Z format)\n const token: TimezoneToken = len === 5 || len === 8 ? \"ZZ\" : \"Z\"\n const timeDiffInSecs = offsetToSecs(offset, token)\n return new Date(d.getTime() + timeDiffInSecs * 1000)\n}\n"],"mappings":";AAAA,SAAS,YAAY;AACrB,SAAwB,qBAAqB,oBAAoB;AAS1D,SAAS,YAAY,WAA4B,SAAS,UAAgB;AAC/E,QAAM,IAAI,KAAK,SAAS;AACxB,QAAM,MAAM,oBAAoB,MAAM;AAEtC,QAAM,QAAuB,QAAQ,KAAK,QAAQ,IAAI,OAAO;AAC7D,QAAM,iBAAiB,aAAa,QAAQ,KAAK;AACjD,SAAO,IAAI,KAAK,EAAE,QAAQ,IAAI,iBAAiB,GAAI;AACrD;","names":[]}