@formkit/tempo 1.3.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/bundle.d.ts +4 -4
- package/dist/bundle.mjs +30 -21
- package/dist/bundle.mjs.map +1 -1
- package/dist/dayOfYear.mjs +1 -3
- package/dist/dayOfYear.mjs.map +1 -1
- package/dist/diffDays.mjs +5 -7
- package/dist/diffDays.mjs.map +1 -1
- package/dist/diffMonths.mjs +4 -1
- package/dist/diffMonths.mjs.map +1 -1
- package/dist/diffWeeks.d.ts +5 -5
- package/dist/diffWeeks.mjs +5 -6
- package/dist/diffWeeks.mjs.map +1 -1
- package/dist/hourEnd.mjs +5 -0
- package/dist/hourEnd.mjs.map +1 -1
- package/dist/hourStart.mjs +4 -0
- package/dist/hourStart.mjs.map +1 -1
- package/dist/index.cjs +30 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/minuteEnd.mjs +3 -1
- package/dist/minuteEnd.mjs.map +1 -1
- package/dist/minuteStart.mjs +1 -1
- package/dist/minuteStart.mjs.map +1 -1
- package/dist/nearestDay.mjs +4 -4
- package/dist/nearestDay.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.d.ts
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
|
|
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
|
|
756
|
+
declare function diffWeeks(dateA: DateInput, dateB?: MaybeDateInput, roundingMethod?: DiffRoundingMethod): number;
|
|
757
757
|
/**
|
|
758
|
-
* Returns the difference between 2 dates in
|
|
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:
|
|
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.
|
package/dist/bundle.mjs
CHANGED
|
@@ -482,9 +482,7 @@ function tzDate(inputDate, tz) {
|
|
|
482
482
|
// src/dayOfYear.ts
|
|
483
483
|
function dayOfYear(inputDate) {
|
|
484
484
|
const d = date(inputDate);
|
|
485
|
-
return
|
|
486
|
-
(new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0).getTime() - new Date(d.getFullYear(), 0, 0).getTime()) / 864e5
|
|
487
|
-
);
|
|
485
|
+
return (Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) - Date.UTC(d.getFullYear(), 0, 0)) / 864e5;
|
|
488
486
|
}
|
|
489
487
|
|
|
490
488
|
// src/dayEnd.ts
|
|
@@ -762,6 +760,11 @@ function fourDigitYear(value) {
|
|
|
762
760
|
// src/hourEnd.ts
|
|
763
761
|
function hourEnd(inputDate) {
|
|
764
762
|
const d = date(inputDate);
|
|
763
|
+
const shifted = new Date(
|
|
764
|
+
d.getTime() + ((59 - d.getMinutes()) * 60 + (59 - d.getSeconds())) * 1e3 + (999 - d.getMilliseconds())
|
|
765
|
+
);
|
|
766
|
+
if (shifted.getMinutes() === 59 && shifted.getHours() === d.getHours())
|
|
767
|
+
return shifted;
|
|
765
768
|
d.setMinutes(59, 59, 999);
|
|
766
769
|
return d;
|
|
767
770
|
}
|
|
@@ -769,6 +772,10 @@ function hourEnd(inputDate) {
|
|
|
769
772
|
// src/hourStart.ts
|
|
770
773
|
function hourStart(inputDate) {
|
|
771
774
|
const d = date(inputDate);
|
|
775
|
+
const shifted = new Date(
|
|
776
|
+
d.getTime() - (d.getMinutes() * 60 + d.getSeconds()) * 1e3 - d.getMilliseconds()
|
|
777
|
+
);
|
|
778
|
+
if (shifted.getMinutes() === 0 && shifted.getHours() === d.getHours()) return shifted;
|
|
772
779
|
d.setMinutes(0, 0, 0);
|
|
773
780
|
return d;
|
|
774
781
|
}
|
|
@@ -776,14 +783,16 @@ function hourStart(inputDate) {
|
|
|
776
783
|
// src/minuteEnd.ts
|
|
777
784
|
function minuteEnd(inputDate) {
|
|
778
785
|
const d = date(inputDate);
|
|
779
|
-
d.
|
|
786
|
+
d.setTime(
|
|
787
|
+
d.getTime() + (59 - d.getSeconds()) * 1e3 + (999 - d.getMilliseconds())
|
|
788
|
+
);
|
|
780
789
|
return d;
|
|
781
790
|
}
|
|
782
791
|
|
|
783
792
|
// src/minuteStart.ts
|
|
784
793
|
function minuteStart(inputDate) {
|
|
785
794
|
const d = date(inputDate);
|
|
786
|
-
d.
|
|
795
|
+
d.setTime(d.getTime() - d.getSeconds() * 1e3 - d.getMilliseconds());
|
|
787
796
|
return d;
|
|
788
797
|
}
|
|
789
798
|
|
|
@@ -808,23 +817,23 @@ function nearestDay(inputDate, search, constraint = 7) {
|
|
|
808
817
|
const d = date(inputDate);
|
|
809
818
|
switch (constraint) {
|
|
810
819
|
case "month":
|
|
811
|
-
decrements = d.getDate();
|
|
820
|
+
decrements = d.getDate() - 1;
|
|
812
821
|
increments = monthDays(d) - d.getDate();
|
|
813
822
|
break;
|
|
814
823
|
case "week":
|
|
815
|
-
decrements = d.getDay()
|
|
824
|
+
decrements = d.getDay();
|
|
816
825
|
increments = 6 - d.getDay();
|
|
817
826
|
break;
|
|
818
827
|
case "year":
|
|
819
828
|
const total = yearDays(d);
|
|
820
829
|
const day = dayOfYear(d);
|
|
821
|
-
decrements = day;
|
|
830
|
+
decrements = day - 1;
|
|
822
831
|
increments = total - day;
|
|
823
832
|
break;
|
|
824
833
|
default:
|
|
825
834
|
increments = decrements = constraint;
|
|
826
835
|
}
|
|
827
|
-
for (let i = 0; i <= increments || i
|
|
836
|
+
for (let i = 0; i <= increments || i <= decrements; i++) {
|
|
828
837
|
if (i <= increments) {
|
|
829
838
|
const next = addDay(d, i);
|
|
830
839
|
if (search(next)) return next;
|
|
@@ -1265,24 +1274,24 @@ function diffHours(dateA, dateB, roundingMethod) {
|
|
|
1265
1274
|
|
|
1266
1275
|
// src/diffDays.ts
|
|
1267
1276
|
function diffDays(dateA, dateB, roundingMethod) {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
roundingMethod
|
|
1273
|
-
);
|
|
1277
|
+
const left = date(dateA);
|
|
1278
|
+
const right = date(dateB);
|
|
1279
|
+
const offset2 = (right.getTimezoneOffset() - left.getTimezoneOffset()) * 6e4;
|
|
1280
|
+
return diffRound((+left - +right + offset2) / 864e5, roundingMethod);
|
|
1274
1281
|
}
|
|
1275
1282
|
|
|
1276
1283
|
// src/diffWeeks.ts
|
|
1277
1284
|
function diffWeeks(dateA, dateB, roundingMethod) {
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
);
|
|
1285
|
+
const left = date(dateA);
|
|
1286
|
+
const right = date(dateB);
|
|
1287
|
+
const offset2 = (right.getTimezoneOffset() - left.getTimezoneOffset()) * 6e4;
|
|
1288
|
+
return diffRound((+left - +right + offset2) / 6048e5, roundingMethod);
|
|
1283
1289
|
}
|
|
1284
1290
|
|
|
1285
1291
|
// src/diffMonths.ts
|
|
1292
|
+
function timeOfDay(d) {
|
|
1293
|
+
return ((d.getHours() * 60 + d.getMinutes()) * 60 + d.getSeconds()) * 1e3 + d.getMilliseconds();
|
|
1294
|
+
}
|
|
1286
1295
|
function diffMonths(dateA, dateB) {
|
|
1287
1296
|
const l = date(dateA);
|
|
1288
1297
|
const r = date(dateB);
|
|
@@ -1293,7 +1302,7 @@ function diffMonths(dateA, dateB) {
|
|
|
1293
1302
|
let months = (l.getFullYear() - r.getFullYear()) * 12 + (l.getMonth() - r.getMonth());
|
|
1294
1303
|
const ld = l.getDate();
|
|
1295
1304
|
const rd = r.getDate();
|
|
1296
|
-
if (ld < rd) {
|
|
1305
|
+
if (ld < rd || ld == rd && timeOfDay(l) < timeOfDay(r)) {
|
|
1297
1306
|
const lm = monthDays(l);
|
|
1298
1307
|
if (!(lm == ld && lm < rd)) {
|
|
1299
1308
|
months--;
|