@h3ravel/support 1.29.0-alpha.16 → 2.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.
package/dist/traits.cjs DELETED
@@ -1,55 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_Time = require("./Time-CjHXeIZv.cjs");
3
- let _h3ravel_shared = require("@h3ravel/shared");
4
- let dayjs_plugin_duration_js = require("dayjs/plugin/duration.js");
5
- dayjs_plugin_duration_js = require_Time.__toESM(dayjs_plugin_duration_js, 1);
6
- //#region src/Traits/InteractsWithTime.ts
7
- const InteractsWithTime = (0, _h3ravel_shared.trait)((Base) => class InteractsWithTime extends Base {
8
- /**
9
- * Get the number of seconds until the given DateTime.
10
- *
11
- * @param delay
12
- */
13
- secondsUntil(delay) {
14
- delay = this.parseDateInterval(delay);
15
- return delay instanceof require_Time.DateTime ? Math.max(0, delay.getTimestamp() - this.currentTime()) : Number(delay);
16
- }
17
- /**
18
- * Get the "available at" UNIX timestamp.
19
- *
20
- * @param delay
21
- */
22
- availableAt(delay = 0) {
23
- delay = this.parseDateInterval(delay);
24
- return delay instanceof require_Time.DateTime ? delay.getTimestamp() : require_Time.DateTime.now().add(delay, "seconds").getTimestamp();
25
- }
26
- /**
27
- * If the given value is an interval, convert it to a DateTime instance.
28
- *
29
- * @param delay
30
- */
31
- parseDateInterval(delay) {
32
- if (typeof delay === "number") delay = require_Time.DateTime.now().add(delay);
33
- return delay;
34
- }
35
- /**
36
- * Get the current system time as a UNIX timestamp.
37
- */
38
- currentTime() {
39
- return require_Time.DateTime.now().getTimestamp();
40
- }
41
- /**
42
- * Given a start time, format the total run time for human readability.
43
- *
44
- * @param startTime
45
- * @param endTime
46
- */
47
- runTimeForHumans(startTime, endTime) {
48
- endTime ??= Date.now();
49
- const runTime = endTime - startTime;
50
- if (runTime < 1e3) return `${runTime.toFixed(2)}ms`;
51
- return require_Time.DateTime.plugin(dayjs_plugin_duration_js.default).duration(runTime).humanize();
52
- }
53
- });
54
- //#endregion
55
- exports.InteractsWithTime = InteractsWithTime;