clockey 1.2.0 → 1.4.1
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.mts +82 -1
- package/dist/index.d.ts +82 -1
- package/dist/index.js +170 -2
- package/dist/index.mjs +166 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -406,6 +406,87 @@ declare function createTimer(): {
|
|
|
406
406
|
elapsedHrs: number;
|
|
407
407
|
text: string;
|
|
408
408
|
} | null;
|
|
409
|
+
lap: () => {
|
|
410
|
+
durationMs: number;
|
|
411
|
+
durationSec: number;
|
|
412
|
+
durationMin: number;
|
|
413
|
+
durationHrs: number;
|
|
414
|
+
text: string;
|
|
415
|
+
} | null;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
declare function isBefore(timestamp: Date | number | string): {
|
|
419
|
+
error: string;
|
|
420
|
+
isBefore?: undefined;
|
|
421
|
+
durationInMs?: undefined;
|
|
422
|
+
durationInSeconds?: undefined;
|
|
423
|
+
durationInMinutes?: undefined;
|
|
424
|
+
durationInHours?: undefined;
|
|
425
|
+
durationInDays?: undefined;
|
|
426
|
+
} | {
|
|
427
|
+
isBefore: boolean;
|
|
428
|
+
durationInMs: number;
|
|
429
|
+
durationInSeconds: number;
|
|
430
|
+
durationInMinutes: number;
|
|
431
|
+
durationInHours: number;
|
|
432
|
+
durationInDays: number;
|
|
433
|
+
error?: undefined;
|
|
434
|
+
};
|
|
435
|
+
declare function isAfter(timestamp: Date | number | string): {
|
|
436
|
+
error: string;
|
|
437
|
+
isAfter?: undefined;
|
|
438
|
+
durationInMs?: undefined;
|
|
439
|
+
durationInSeconds?: undefined;
|
|
440
|
+
durationInMinutes?: undefined;
|
|
441
|
+
durationInHours?: undefined;
|
|
442
|
+
durationInDays?: undefined;
|
|
443
|
+
} | {
|
|
444
|
+
isAfter: boolean;
|
|
445
|
+
durationInMs: number;
|
|
446
|
+
durationInSeconds: number;
|
|
447
|
+
durationInMinutes: number;
|
|
448
|
+
durationInHours: number;
|
|
449
|
+
durationInDays: number;
|
|
450
|
+
error?: undefined;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
declare function relativeTime(timestamp: Date | number | string): {
|
|
454
|
+
error: string;
|
|
455
|
+
isBefore?: undefined;
|
|
456
|
+
durationInMs?: undefined;
|
|
457
|
+
durationInSeconds?: undefined;
|
|
458
|
+
durationInMinutes?: undefined;
|
|
459
|
+
durationInHours?: undefined;
|
|
460
|
+
durationInDays?: undefined;
|
|
461
|
+
} | {
|
|
462
|
+
isBefore: boolean;
|
|
463
|
+
durationInMs: number;
|
|
464
|
+
durationInSeconds: number;
|
|
465
|
+
durationInMinutes: number;
|
|
466
|
+
durationInHours: number;
|
|
467
|
+
durationInDays: number;
|
|
468
|
+
error?: undefined;
|
|
469
|
+
} | {
|
|
470
|
+
error: string;
|
|
471
|
+
isAfter?: undefined;
|
|
472
|
+
durationInMs?: undefined;
|
|
473
|
+
durationInSeconds?: undefined;
|
|
474
|
+
durationInMinutes?: undefined;
|
|
475
|
+
durationInHours?: undefined;
|
|
476
|
+
durationInDays?: undefined;
|
|
477
|
+
} | {
|
|
478
|
+
isAfter: boolean;
|
|
479
|
+
durationInMs: number;
|
|
480
|
+
durationInSeconds: number;
|
|
481
|
+
durationInMinutes: number;
|
|
482
|
+
durationInHours: number;
|
|
483
|
+
durationInDays: number;
|
|
484
|
+
error?: undefined;
|
|
485
|
+
} | {
|
|
486
|
+
timestamp: number;
|
|
487
|
+
timestampDate: Date;
|
|
488
|
+
humanReadable: string;
|
|
489
|
+
isInFuture: true;
|
|
409
490
|
};
|
|
410
491
|
|
|
411
|
-
export { createTimer, getCurrenHrResponse, getCurrentDate, getCurrentDateNumber, getCurrentDateNumberResponse, getCurrentDateNumberUTC, getCurrentDateNumberUTCResponse, getCurrentDateUTC, getCurrentDateUnixMilliseconds, getCurrentDateUnixMillisecondsResponse, getCurrentDateUnixSeconds, getCurrentDateUnixSecondsResponse, getCurrentDay, getCurrentDayResponse, getCurrentDayUTC, getCurrentDayUTCResponse, getCurrentFullDate, getCurrentFullDateResponse, getCurrentFullDateUTC, getCurrentFullDateUTCResponse, getCurrentHour12Str, getCurrentHour12StrResponse, getCurrentHour12StrUTC, getCurrentHour12StrUTCResponse, getCurrentHour24Str, getCurrentHour24StrResponse, getCurrentHour24StrUTC, getCurrentHour24StrUTCResponse, getCurrentHr, getCurrentHrUTC, getCurrentHrUTCResponse, getCurrentMinute, getCurrentMinuteResponse, getCurrentMinuteStr, getCurrentMinuteStrResponse, getCurrentMinuteStrUTC, getCurrentMinuteStrUTCResponse, getCurrentMinuteUTC, getCurrentMinuteUTCResponse, getCurrentMonth, getCurrentMonthResponse, getCurrentMonthUTC, getCurrentMonthUTCResponse, getCurrentOrdinal, getCurrentOrdinalResponse, getCurrentOrdinalUTC, getCurrentOrdinalUTCResponse, getCurrentPeriod, getCurrentPeriodResponse, getCurrentPeriodUTC, getCurrentPeriodUTCResponse, getCurrentSecond, getCurrentSecondResponse, getCurrentSecondStr, getCurrentSecondStrResponse, getCurrentSecondStrUTC, getCurrentSecondStrUTCResponse, getCurrentSecondUTC, getCurrentSecondUTCResponse, getCurrentTime, getCurrentTimeResponse, getCurrentTimeUTC, getCurrentTimeUTCResponse, getCurrentTimeUnixMilliseconds, getCurrentTimeUnixMillisecondsResponse, getCurrentTimeUnixSeconds, getCurrentTimeUnixSecondsResponse, getCurrentYear, getCurrentYearResponse, getCurrentYearUTC, getCurrentYearUTCResponse, getcurrentDateISO, getcurrentDateISOResponse, getcurrentTimeISO, getcurrentTimeISOResponse };
|
|
492
|
+
export { createTimer, getCurrenHrResponse, getCurrentDate, getCurrentDateNumber, getCurrentDateNumberResponse, getCurrentDateNumberUTC, getCurrentDateNumberUTCResponse, getCurrentDateUTC, getCurrentDateUnixMilliseconds, getCurrentDateUnixMillisecondsResponse, getCurrentDateUnixSeconds, getCurrentDateUnixSecondsResponse, getCurrentDay, getCurrentDayResponse, getCurrentDayUTC, getCurrentDayUTCResponse, getCurrentFullDate, getCurrentFullDateResponse, getCurrentFullDateUTC, getCurrentFullDateUTCResponse, getCurrentHour12Str, getCurrentHour12StrResponse, getCurrentHour12StrUTC, getCurrentHour12StrUTCResponse, getCurrentHour24Str, getCurrentHour24StrResponse, getCurrentHour24StrUTC, getCurrentHour24StrUTCResponse, getCurrentHr, getCurrentHrUTC, getCurrentHrUTCResponse, getCurrentMinute, getCurrentMinuteResponse, getCurrentMinuteStr, getCurrentMinuteStrResponse, getCurrentMinuteStrUTC, getCurrentMinuteStrUTCResponse, getCurrentMinuteUTC, getCurrentMinuteUTCResponse, getCurrentMonth, getCurrentMonthResponse, getCurrentMonthUTC, getCurrentMonthUTCResponse, getCurrentOrdinal, getCurrentOrdinalResponse, getCurrentOrdinalUTC, getCurrentOrdinalUTCResponse, getCurrentPeriod, getCurrentPeriodResponse, getCurrentPeriodUTC, getCurrentPeriodUTCResponse, getCurrentSecond, getCurrentSecondResponse, getCurrentSecondStr, getCurrentSecondStrResponse, getCurrentSecondStrUTC, getCurrentSecondStrUTCResponse, getCurrentSecondUTC, getCurrentSecondUTCResponse, getCurrentTime, getCurrentTimeResponse, getCurrentTimeUTC, getCurrentTimeUTCResponse, getCurrentTimeUnixMilliseconds, getCurrentTimeUnixMillisecondsResponse, getCurrentTimeUnixSeconds, getCurrentTimeUnixSecondsResponse, getCurrentYear, getCurrentYearResponse, getCurrentYearUTC, getCurrentYearUTCResponse, getcurrentDateISO, getcurrentDateISOResponse, getcurrentTimeISO, getcurrentTimeISOResponse, isAfter, isBefore, relativeTime };
|
package/dist/index.d.ts
CHANGED
|
@@ -406,6 +406,87 @@ declare function createTimer(): {
|
|
|
406
406
|
elapsedHrs: number;
|
|
407
407
|
text: string;
|
|
408
408
|
} | null;
|
|
409
|
+
lap: () => {
|
|
410
|
+
durationMs: number;
|
|
411
|
+
durationSec: number;
|
|
412
|
+
durationMin: number;
|
|
413
|
+
durationHrs: number;
|
|
414
|
+
text: string;
|
|
415
|
+
} | null;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
declare function isBefore(timestamp: Date | number | string): {
|
|
419
|
+
error: string;
|
|
420
|
+
isBefore?: undefined;
|
|
421
|
+
durationInMs?: undefined;
|
|
422
|
+
durationInSeconds?: undefined;
|
|
423
|
+
durationInMinutes?: undefined;
|
|
424
|
+
durationInHours?: undefined;
|
|
425
|
+
durationInDays?: undefined;
|
|
426
|
+
} | {
|
|
427
|
+
isBefore: boolean;
|
|
428
|
+
durationInMs: number;
|
|
429
|
+
durationInSeconds: number;
|
|
430
|
+
durationInMinutes: number;
|
|
431
|
+
durationInHours: number;
|
|
432
|
+
durationInDays: number;
|
|
433
|
+
error?: undefined;
|
|
434
|
+
};
|
|
435
|
+
declare function isAfter(timestamp: Date | number | string): {
|
|
436
|
+
error: string;
|
|
437
|
+
isAfter?: undefined;
|
|
438
|
+
durationInMs?: undefined;
|
|
439
|
+
durationInSeconds?: undefined;
|
|
440
|
+
durationInMinutes?: undefined;
|
|
441
|
+
durationInHours?: undefined;
|
|
442
|
+
durationInDays?: undefined;
|
|
443
|
+
} | {
|
|
444
|
+
isAfter: boolean;
|
|
445
|
+
durationInMs: number;
|
|
446
|
+
durationInSeconds: number;
|
|
447
|
+
durationInMinutes: number;
|
|
448
|
+
durationInHours: number;
|
|
449
|
+
durationInDays: number;
|
|
450
|
+
error?: undefined;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
declare function relativeTime(timestamp: Date | number | string): {
|
|
454
|
+
error: string;
|
|
455
|
+
isBefore?: undefined;
|
|
456
|
+
durationInMs?: undefined;
|
|
457
|
+
durationInSeconds?: undefined;
|
|
458
|
+
durationInMinutes?: undefined;
|
|
459
|
+
durationInHours?: undefined;
|
|
460
|
+
durationInDays?: undefined;
|
|
461
|
+
} | {
|
|
462
|
+
isBefore: boolean;
|
|
463
|
+
durationInMs: number;
|
|
464
|
+
durationInSeconds: number;
|
|
465
|
+
durationInMinutes: number;
|
|
466
|
+
durationInHours: number;
|
|
467
|
+
durationInDays: number;
|
|
468
|
+
error?: undefined;
|
|
469
|
+
} | {
|
|
470
|
+
error: string;
|
|
471
|
+
isAfter?: undefined;
|
|
472
|
+
durationInMs?: undefined;
|
|
473
|
+
durationInSeconds?: undefined;
|
|
474
|
+
durationInMinutes?: undefined;
|
|
475
|
+
durationInHours?: undefined;
|
|
476
|
+
durationInDays?: undefined;
|
|
477
|
+
} | {
|
|
478
|
+
isAfter: boolean;
|
|
479
|
+
durationInMs: number;
|
|
480
|
+
durationInSeconds: number;
|
|
481
|
+
durationInMinutes: number;
|
|
482
|
+
durationInHours: number;
|
|
483
|
+
durationInDays: number;
|
|
484
|
+
error?: undefined;
|
|
485
|
+
} | {
|
|
486
|
+
timestamp: number;
|
|
487
|
+
timestampDate: Date;
|
|
488
|
+
humanReadable: string;
|
|
489
|
+
isInFuture: true;
|
|
409
490
|
};
|
|
410
491
|
|
|
411
|
-
export { createTimer, getCurrenHrResponse, getCurrentDate, getCurrentDateNumber, getCurrentDateNumberResponse, getCurrentDateNumberUTC, getCurrentDateNumberUTCResponse, getCurrentDateUTC, getCurrentDateUnixMilliseconds, getCurrentDateUnixMillisecondsResponse, getCurrentDateUnixSeconds, getCurrentDateUnixSecondsResponse, getCurrentDay, getCurrentDayResponse, getCurrentDayUTC, getCurrentDayUTCResponse, getCurrentFullDate, getCurrentFullDateResponse, getCurrentFullDateUTC, getCurrentFullDateUTCResponse, getCurrentHour12Str, getCurrentHour12StrResponse, getCurrentHour12StrUTC, getCurrentHour12StrUTCResponse, getCurrentHour24Str, getCurrentHour24StrResponse, getCurrentHour24StrUTC, getCurrentHour24StrUTCResponse, getCurrentHr, getCurrentHrUTC, getCurrentHrUTCResponse, getCurrentMinute, getCurrentMinuteResponse, getCurrentMinuteStr, getCurrentMinuteStrResponse, getCurrentMinuteStrUTC, getCurrentMinuteStrUTCResponse, getCurrentMinuteUTC, getCurrentMinuteUTCResponse, getCurrentMonth, getCurrentMonthResponse, getCurrentMonthUTC, getCurrentMonthUTCResponse, getCurrentOrdinal, getCurrentOrdinalResponse, getCurrentOrdinalUTC, getCurrentOrdinalUTCResponse, getCurrentPeriod, getCurrentPeriodResponse, getCurrentPeriodUTC, getCurrentPeriodUTCResponse, getCurrentSecond, getCurrentSecondResponse, getCurrentSecondStr, getCurrentSecondStrResponse, getCurrentSecondStrUTC, getCurrentSecondStrUTCResponse, getCurrentSecondUTC, getCurrentSecondUTCResponse, getCurrentTime, getCurrentTimeResponse, getCurrentTimeUTC, getCurrentTimeUTCResponse, getCurrentTimeUnixMilliseconds, getCurrentTimeUnixMillisecondsResponse, getCurrentTimeUnixSeconds, getCurrentTimeUnixSecondsResponse, getCurrentYear, getCurrentYearResponse, getCurrentYearUTC, getCurrentYearUTCResponse, getcurrentDateISO, getcurrentDateISOResponse, getcurrentTimeISO, getcurrentTimeISOResponse };
|
|
492
|
+
export { createTimer, getCurrenHrResponse, getCurrentDate, getCurrentDateNumber, getCurrentDateNumberResponse, getCurrentDateNumberUTC, getCurrentDateNumberUTCResponse, getCurrentDateUTC, getCurrentDateUnixMilliseconds, getCurrentDateUnixMillisecondsResponse, getCurrentDateUnixSeconds, getCurrentDateUnixSecondsResponse, getCurrentDay, getCurrentDayResponse, getCurrentDayUTC, getCurrentDayUTCResponse, getCurrentFullDate, getCurrentFullDateResponse, getCurrentFullDateUTC, getCurrentFullDateUTCResponse, getCurrentHour12Str, getCurrentHour12StrResponse, getCurrentHour12StrUTC, getCurrentHour12StrUTCResponse, getCurrentHour24Str, getCurrentHour24StrResponse, getCurrentHour24StrUTC, getCurrentHour24StrUTCResponse, getCurrentHr, getCurrentHrUTC, getCurrentHrUTCResponse, getCurrentMinute, getCurrentMinuteResponse, getCurrentMinuteStr, getCurrentMinuteStrResponse, getCurrentMinuteStrUTC, getCurrentMinuteStrUTCResponse, getCurrentMinuteUTC, getCurrentMinuteUTCResponse, getCurrentMonth, getCurrentMonthResponse, getCurrentMonthUTC, getCurrentMonthUTCResponse, getCurrentOrdinal, getCurrentOrdinalResponse, getCurrentOrdinalUTC, getCurrentOrdinalUTCResponse, getCurrentPeriod, getCurrentPeriodResponse, getCurrentPeriodUTC, getCurrentPeriodUTCResponse, getCurrentSecond, getCurrentSecondResponse, getCurrentSecondStr, getCurrentSecondStrResponse, getCurrentSecondStrUTC, getCurrentSecondStrUTCResponse, getCurrentSecondUTC, getCurrentSecondUTCResponse, getCurrentTime, getCurrentTimeResponse, getCurrentTimeUTC, getCurrentTimeUTCResponse, getCurrentTimeUnixMilliseconds, getCurrentTimeUnixMillisecondsResponse, getCurrentTimeUnixSeconds, getCurrentTimeUnixSecondsResponse, getCurrentYear, getCurrentYearResponse, getCurrentYearUTC, getCurrentYearUTCResponse, getcurrentDateISO, getcurrentDateISOResponse, getcurrentTimeISO, getcurrentTimeISOResponse, isAfter, isBefore, relativeTime };
|
package/dist/index.js
CHANGED
|
@@ -94,7 +94,10 @@ __export(index_exports, {
|
|
|
94
94
|
getcurrentDateISO: () => getcurrentDateISO,
|
|
95
95
|
getcurrentDateISOResponse: () => getcurrentDateISOResponse,
|
|
96
96
|
getcurrentTimeISO: () => getcurrentTimeISO,
|
|
97
|
-
getcurrentTimeISOResponse: () => getcurrentTimeISOResponse
|
|
97
|
+
getcurrentTimeISOResponse: () => getcurrentTimeISOResponse,
|
|
98
|
+
isAfter: () => isAfter,
|
|
99
|
+
isBefore: () => isBefore,
|
|
100
|
+
relativeTime: () => relativeTime
|
|
98
101
|
});
|
|
99
102
|
module.exports = __toCommonJS(index_exports);
|
|
100
103
|
|
|
@@ -890,7 +893,169 @@ function createTimer() {
|
|
|
890
893
|
elapsedHrs: elapsed / 36e5,
|
|
891
894
|
text: `${elapsed.toFixed(2)} ms`
|
|
892
895
|
};
|
|
896
|
+
},
|
|
897
|
+
lap: () => {
|
|
898
|
+
if (startTime === null) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
const duration = performance.now() - startTime;
|
|
902
|
+
return {
|
|
903
|
+
durationMs: duration,
|
|
904
|
+
durationSec: duration / 1e3,
|
|
905
|
+
durationMin: duration / 6e4,
|
|
906
|
+
durationHrs: duration / 36e5,
|
|
907
|
+
text: `${duration.toFixed(2)} ms`
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// src/utilities/diffChecker.ts
|
|
914
|
+
function isBefore(timestamp) {
|
|
915
|
+
if (timestamp instanceof Date) {
|
|
916
|
+
if (isNaN(timestamp.getTime())) {
|
|
917
|
+
return {
|
|
918
|
+
error: "invalid timestamp (date), please read documentation for more info"
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
} else if (typeof timestamp === "string") {
|
|
922
|
+
const tsDate = new Date(timestamp);
|
|
923
|
+
if (isNaN(tsDate.getTime())) {
|
|
924
|
+
return {
|
|
925
|
+
error: "invalid timestamp (string), please read documentation for more info"
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
} else if (typeof timestamp === "number") {
|
|
929
|
+
if (isNaN(timestamp)) {
|
|
930
|
+
return {
|
|
931
|
+
error: "invalid timestamp (number), please read documentation for more info"
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
return {
|
|
936
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
const date = /* @__PURE__ */ new Date();
|
|
940
|
+
let isBefore2;
|
|
941
|
+
let duration;
|
|
942
|
+
if (timestamp instanceof Date) {
|
|
943
|
+
isBefore2 = date.getTime() > timestamp.getTime();
|
|
944
|
+
duration = date.getTime() - timestamp.getTime();
|
|
945
|
+
} else if (typeof timestamp === "string") {
|
|
946
|
+
const tsDate = new Date(timestamp);
|
|
947
|
+
isBefore2 = date.getTime() > tsDate.getTime();
|
|
948
|
+
duration = date.getTime() - tsDate.getTime();
|
|
949
|
+
} else {
|
|
950
|
+
isBefore2 = Date.now() > timestamp;
|
|
951
|
+
duration = Date.now() - timestamp;
|
|
952
|
+
}
|
|
953
|
+
return {
|
|
954
|
+
isBefore: isBefore2,
|
|
955
|
+
durationInMs: Math.abs(duration),
|
|
956
|
+
durationInSeconds: Math.abs(duration) / 1e3,
|
|
957
|
+
durationInMinutes: Math.abs(duration) / (1e3 * 60),
|
|
958
|
+
durationInHours: Math.abs(duration) / (1e3 * 60 * 60),
|
|
959
|
+
durationInDays: Math.abs(duration) / (1e3 * 60 * 60 * 24)
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
function isAfter(timestamp) {
|
|
963
|
+
if (timestamp instanceof Date) {
|
|
964
|
+
if (isNaN(timestamp.getTime())) {
|
|
965
|
+
return {
|
|
966
|
+
error: "invalid timestamp (date), please read documentation for more info"
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
} else if (typeof timestamp === "string") {
|
|
970
|
+
const tsDate = new Date(timestamp);
|
|
971
|
+
if (isNaN(tsDate.getTime())) {
|
|
972
|
+
return {
|
|
973
|
+
error: "invalid timestamp (string), please read documentation for more info"
|
|
974
|
+
};
|
|
893
975
|
}
|
|
976
|
+
} else if (typeof timestamp === "number") {
|
|
977
|
+
if (isNaN(timestamp)) {
|
|
978
|
+
return {
|
|
979
|
+
error: "invalid timestamp (number), please read documentation for more info"
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
} else {
|
|
983
|
+
return {
|
|
984
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
const date = /* @__PURE__ */ new Date();
|
|
988
|
+
let isAfter2;
|
|
989
|
+
let duration;
|
|
990
|
+
if (timestamp instanceof Date) {
|
|
991
|
+
isAfter2 = date.getTime() < timestamp.getTime();
|
|
992
|
+
duration = timestamp.getTime() - date.getTime();
|
|
993
|
+
} else if (typeof timestamp === "string") {
|
|
994
|
+
const tsDate = new Date(timestamp);
|
|
995
|
+
isAfter2 = date.getTime() < tsDate.getTime();
|
|
996
|
+
duration = tsDate.getTime() - date.getTime();
|
|
997
|
+
} else {
|
|
998
|
+
isAfter2 = Date.now() < timestamp;
|
|
999
|
+
duration = timestamp - Date.now();
|
|
1000
|
+
}
|
|
1001
|
+
return {
|
|
1002
|
+
isAfter: isAfter2,
|
|
1003
|
+
durationInMs: Math.abs(duration),
|
|
1004
|
+
durationInSeconds: Math.abs(duration) / 1e3,
|
|
1005
|
+
durationInMinutes: Math.abs(duration) / (1e3 * 60),
|
|
1006
|
+
durationInHours: Math.abs(duration) / (1e3 * 60 * 60),
|
|
1007
|
+
durationInDays: Math.abs(duration) / (1e3 * 60 * 60 * 24)
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/utilities/relativeTime.ts
|
|
1012
|
+
function relativeTime(timestamp) {
|
|
1013
|
+
if (timestamp === null || timestamp === void 0) {
|
|
1014
|
+
return {
|
|
1015
|
+
error: "timestamp is either null or undefined, please read documentation for more info"
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
const timestampDate = timestamp instanceof Date ? timestamp : new Date(timestamp);
|
|
1019
|
+
if (timestampDate.toString() === "Invalid Date") {
|
|
1020
|
+
return {
|
|
1021
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
let humanTxt;
|
|
1025
|
+
const afterResult = isAfter(timestamp);
|
|
1026
|
+
if ("error" in afterResult) {
|
|
1027
|
+
return afterResult;
|
|
1028
|
+
}
|
|
1029
|
+
const durationType = afterResult.isAfter ? afterResult : isBefore(timestamp);
|
|
1030
|
+
if ("error" in durationType) {
|
|
1031
|
+
return durationType;
|
|
1032
|
+
}
|
|
1033
|
+
if (afterResult.isAfter) {
|
|
1034
|
+
if (durationType.durationInSeconds < 60) {
|
|
1035
|
+
humanTxt = `${Math.round(durationType.durationInSeconds)} second(s) ago`;
|
|
1036
|
+
} else if (durationType.durationInMinutes < 60) {
|
|
1037
|
+
humanTxt = `${Math.round(durationType.durationInMinutes)} minute(s) ago`;
|
|
1038
|
+
} else if (durationType.durationInHours < 24) {
|
|
1039
|
+
humanTxt = `${Math.round(durationType.durationInHours)} hour(s) ago`;
|
|
1040
|
+
} else {
|
|
1041
|
+
const months = Math.round(durationType.durationInDays / 30);
|
|
1042
|
+
if (months < 12) {
|
|
1043
|
+
humanTxt = `${months} month(s) ago`;
|
|
1044
|
+
} else {
|
|
1045
|
+
const years = Math.round(months / 12);
|
|
1046
|
+
humanTxt = `${years} year(s) ago`;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
} else {
|
|
1050
|
+
return {
|
|
1051
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
return {
|
|
1055
|
+
timestamp: Date.parse(timestampDate.toString()),
|
|
1056
|
+
timestampDate,
|
|
1057
|
+
humanReadable: humanTxt,
|
|
1058
|
+
isInFuture: afterResult.isAfter
|
|
894
1059
|
};
|
|
895
1060
|
}
|
|
896
1061
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -969,5 +1134,8 @@ function createTimer() {
|
|
|
969
1134
|
getcurrentDateISO,
|
|
970
1135
|
getcurrentDateISOResponse,
|
|
971
1136
|
getcurrentTimeISO,
|
|
972
|
-
getcurrentTimeISOResponse
|
|
1137
|
+
getcurrentTimeISOResponse,
|
|
1138
|
+
isAfter,
|
|
1139
|
+
isBefore,
|
|
1140
|
+
relativeTime
|
|
973
1141
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -790,9 +790,171 @@ function createTimer() {
|
|
|
790
790
|
elapsedHrs: elapsed / 36e5,
|
|
791
791
|
text: `${elapsed.toFixed(2)} ms`
|
|
792
792
|
};
|
|
793
|
+
},
|
|
794
|
+
lap: () => {
|
|
795
|
+
if (startTime === null) {
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
const duration = performance.now() - startTime;
|
|
799
|
+
return {
|
|
800
|
+
durationMs: duration,
|
|
801
|
+
durationSec: duration / 1e3,
|
|
802
|
+
durationMin: duration / 6e4,
|
|
803
|
+
durationHrs: duration / 36e5,
|
|
804
|
+
text: `${duration.toFixed(2)} ms`
|
|
805
|
+
};
|
|
793
806
|
}
|
|
794
807
|
};
|
|
795
808
|
}
|
|
809
|
+
|
|
810
|
+
// src/utilities/diffChecker.ts
|
|
811
|
+
function isBefore(timestamp) {
|
|
812
|
+
if (timestamp instanceof Date) {
|
|
813
|
+
if (isNaN(timestamp.getTime())) {
|
|
814
|
+
return {
|
|
815
|
+
error: "invalid timestamp (date), please read documentation for more info"
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
} else if (typeof timestamp === "string") {
|
|
819
|
+
const tsDate = new Date(timestamp);
|
|
820
|
+
if (isNaN(tsDate.getTime())) {
|
|
821
|
+
return {
|
|
822
|
+
error: "invalid timestamp (string), please read documentation for more info"
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
} else if (typeof timestamp === "number") {
|
|
826
|
+
if (isNaN(timestamp)) {
|
|
827
|
+
return {
|
|
828
|
+
error: "invalid timestamp (number), please read documentation for more info"
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
} else {
|
|
832
|
+
return {
|
|
833
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
const date = /* @__PURE__ */ new Date();
|
|
837
|
+
let isBefore2;
|
|
838
|
+
let duration;
|
|
839
|
+
if (timestamp instanceof Date) {
|
|
840
|
+
isBefore2 = date.getTime() > timestamp.getTime();
|
|
841
|
+
duration = date.getTime() - timestamp.getTime();
|
|
842
|
+
} else if (typeof timestamp === "string") {
|
|
843
|
+
const tsDate = new Date(timestamp);
|
|
844
|
+
isBefore2 = date.getTime() > tsDate.getTime();
|
|
845
|
+
duration = date.getTime() - tsDate.getTime();
|
|
846
|
+
} else {
|
|
847
|
+
isBefore2 = Date.now() > timestamp;
|
|
848
|
+
duration = Date.now() - timestamp;
|
|
849
|
+
}
|
|
850
|
+
return {
|
|
851
|
+
isBefore: isBefore2,
|
|
852
|
+
durationInMs: Math.abs(duration),
|
|
853
|
+
durationInSeconds: Math.abs(duration) / 1e3,
|
|
854
|
+
durationInMinutes: Math.abs(duration) / (1e3 * 60),
|
|
855
|
+
durationInHours: Math.abs(duration) / (1e3 * 60 * 60),
|
|
856
|
+
durationInDays: Math.abs(duration) / (1e3 * 60 * 60 * 24)
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function isAfter(timestamp) {
|
|
860
|
+
if (timestamp instanceof Date) {
|
|
861
|
+
if (isNaN(timestamp.getTime())) {
|
|
862
|
+
return {
|
|
863
|
+
error: "invalid timestamp (date), please read documentation for more info"
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
} else if (typeof timestamp === "string") {
|
|
867
|
+
const tsDate = new Date(timestamp);
|
|
868
|
+
if (isNaN(tsDate.getTime())) {
|
|
869
|
+
return {
|
|
870
|
+
error: "invalid timestamp (string), please read documentation for more info"
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
} else if (typeof timestamp === "number") {
|
|
874
|
+
if (isNaN(timestamp)) {
|
|
875
|
+
return {
|
|
876
|
+
error: "invalid timestamp (number), please read documentation for more info"
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
} else {
|
|
880
|
+
return {
|
|
881
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
const date = /* @__PURE__ */ new Date();
|
|
885
|
+
let isAfter2;
|
|
886
|
+
let duration;
|
|
887
|
+
if (timestamp instanceof Date) {
|
|
888
|
+
isAfter2 = date.getTime() < timestamp.getTime();
|
|
889
|
+
duration = timestamp.getTime() - date.getTime();
|
|
890
|
+
} else if (typeof timestamp === "string") {
|
|
891
|
+
const tsDate = new Date(timestamp);
|
|
892
|
+
isAfter2 = date.getTime() < tsDate.getTime();
|
|
893
|
+
duration = tsDate.getTime() - date.getTime();
|
|
894
|
+
} else {
|
|
895
|
+
isAfter2 = Date.now() < timestamp;
|
|
896
|
+
duration = timestamp - Date.now();
|
|
897
|
+
}
|
|
898
|
+
return {
|
|
899
|
+
isAfter: isAfter2,
|
|
900
|
+
durationInMs: Math.abs(duration),
|
|
901
|
+
durationInSeconds: Math.abs(duration) / 1e3,
|
|
902
|
+
durationInMinutes: Math.abs(duration) / (1e3 * 60),
|
|
903
|
+
durationInHours: Math.abs(duration) / (1e3 * 60 * 60),
|
|
904
|
+
durationInDays: Math.abs(duration) / (1e3 * 60 * 60 * 24)
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/utilities/relativeTime.ts
|
|
909
|
+
function relativeTime(timestamp) {
|
|
910
|
+
if (timestamp === null || timestamp === void 0) {
|
|
911
|
+
return {
|
|
912
|
+
error: "timestamp is either null or undefined, please read documentation for more info"
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
const timestampDate = timestamp instanceof Date ? timestamp : new Date(timestamp);
|
|
916
|
+
if (timestampDate.toString() === "Invalid Date") {
|
|
917
|
+
return {
|
|
918
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
let humanTxt;
|
|
922
|
+
const afterResult = isAfter(timestamp);
|
|
923
|
+
if ("error" in afterResult) {
|
|
924
|
+
return afterResult;
|
|
925
|
+
}
|
|
926
|
+
const durationType = afterResult.isAfter ? afterResult : isBefore(timestamp);
|
|
927
|
+
if ("error" in durationType) {
|
|
928
|
+
return durationType;
|
|
929
|
+
}
|
|
930
|
+
if (afterResult.isAfter) {
|
|
931
|
+
if (durationType.durationInSeconds < 60) {
|
|
932
|
+
humanTxt = `${Math.round(durationType.durationInSeconds)} second(s) ago`;
|
|
933
|
+
} else if (durationType.durationInMinutes < 60) {
|
|
934
|
+
humanTxt = `${Math.round(durationType.durationInMinutes)} minute(s) ago`;
|
|
935
|
+
} else if (durationType.durationInHours < 24) {
|
|
936
|
+
humanTxt = `${Math.round(durationType.durationInHours)} hour(s) ago`;
|
|
937
|
+
} else {
|
|
938
|
+
const months = Math.round(durationType.durationInDays / 30);
|
|
939
|
+
if (months < 12) {
|
|
940
|
+
humanTxt = `${months} month(s) ago`;
|
|
941
|
+
} else {
|
|
942
|
+
const years = Math.round(months / 12);
|
|
943
|
+
humanTxt = `${years} year(s) ago`;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
} else {
|
|
947
|
+
return {
|
|
948
|
+
error: "invalid timestamp, please read documentation for more info"
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
return {
|
|
952
|
+
timestamp: Date.parse(timestampDate.toString()),
|
|
953
|
+
timestampDate,
|
|
954
|
+
humanReadable: humanTxt,
|
|
955
|
+
isInFuture: afterResult.isAfter
|
|
956
|
+
};
|
|
957
|
+
}
|
|
796
958
|
export {
|
|
797
959
|
createTimer,
|
|
798
960
|
getCurrenHrResponse,
|
|
@@ -868,5 +1030,8 @@ export {
|
|
|
868
1030
|
getcurrentDateISO,
|
|
869
1031
|
getcurrentDateISOResponse,
|
|
870
1032
|
getcurrentTimeISO,
|
|
871
|
-
getcurrentTimeISOResponse
|
|
1033
|
+
getcurrentTimeISOResponse,
|
|
1034
|
+
isAfter,
|
|
1035
|
+
isBefore,
|
|
1036
|
+
relativeTime
|
|
872
1037
|
};
|