@clyrex-digital/clyrex-controls-dev 0.8.1-dev.20260807130918 → 0.8.1-dev.20260808073515

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.
@@ -0,0 +1,76 @@
1
+ "use client";
2
+
3
+ // src/components/controls/view/TimeUntilStartsClient.tsx
4
+ import { useState, useEffect } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ var TimeUntilStartsClient = (props) => {
7
+ const calculateTimeDifference = (startDate) => {
8
+ const now = /* @__PURE__ */ new Date();
9
+ const nowUtc = new Date(now.getTime() + now.getTimezoneOffset() * 6e4);
10
+ const startDateUtc = new Date(startDate);
11
+ const diffMs = startDateUtc.getTime() - nowUtc.getTime();
12
+ const isPast = diffMs < 0;
13
+ const absoluteDiffMs = Math.abs(diffMs);
14
+ const diffDays = Math.floor(absoluteDiffMs / (1e3 * 60 * 60 * 24));
15
+ const diffHours = Math.floor(
16
+ absoluteDiffMs % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)
17
+ );
18
+ const diffMinutes = Math.floor(
19
+ absoluteDiffMs % (1e3 * 60 * 60) / (1e3 * 60)
20
+ );
21
+ if (absoluteDiffMs < 6e4) {
22
+ return "Just now";
23
+ }
24
+ let timeParts = [
25
+ { value: diffDays, unit: "days" },
26
+ { value: diffHours, unit: "hours" },
27
+ { value: diffMinutes, unit: "minutes" }
28
+ ];
29
+ timeParts = timeParts.filter((part) => part.value > 0);
30
+ if (isPast) {
31
+ if (diffDays > 0) {
32
+ return `${diffDays} day(s) ago`;
33
+ } else if (diffHours > 0) {
34
+ return `${diffHours} hour(s) ago`;
35
+ } else if (diffMinutes > 0) {
36
+ return `${diffMinutes} minute(s) ago`;
37
+ } else {
38
+ return "Just now";
39
+ }
40
+ } else {
41
+ if (timeParts.length > 2) {
42
+ timeParts = timeParts.slice(0, 2);
43
+ }
44
+ const displayString = timeParts.map((part) => `${part.value} ${part.unit}`).join(" ");
45
+ return displayString ? `Starting in ${displayString}` : "Started";
46
+ }
47
+ };
48
+ const isValidDate = (date) => {
49
+ return !isNaN(Date.parse(date));
50
+ };
51
+ const [timeUntilStart, setTimeUntilStart] = useState(() => {
52
+ if (props.value && isValidDate(props.value)) {
53
+ return calculateTimeDifference(props.value);
54
+ }
55
+ return "";
56
+ });
57
+ useEffect(() => {
58
+ if (props.value && isValidDate(props.value)) {
59
+ setTimeUntilStart(calculateTimeDifference(props.value));
60
+ const initialTimeout = setTimeout(() => {
61
+ const interval = setInterval(() => {
62
+ setTimeUntilStart(calculateTimeDifference(props.value));
63
+ }, 6e4);
64
+ return () => clearInterval(interval);
65
+ }, 5e3);
66
+ return () => clearTimeout(initialTimeout);
67
+ } else {
68
+ setTimeUntilStart("");
69
+ }
70
+ }, [props.value]);
71
+ return /* @__PURE__ */ jsx("div", { children: timeUntilStart });
72
+ };
73
+ var TimeUntilStartsClient_default = TimeUntilStartsClient;
74
+ export {
75
+ TimeUntilStartsClient_default as default
76
+ };
@@ -0,0 +1,78 @@
1
+ "use client";
2
+
3
+ "use client";
4
+
5
+ // src/components/controls/view/TimeUntilStartsClient.tsx
6
+ import { useState, useEffect } from "react";
7
+ import { jsx } from "react/jsx-runtime";
8
+ var TimeUntilStartsClient = (props) => {
9
+ const calculateTimeDifference = (startDate) => {
10
+ const now = /* @__PURE__ */ new Date();
11
+ const nowUtc = new Date(now.getTime() + now.getTimezoneOffset() * 6e4);
12
+ const startDateUtc = new Date(startDate);
13
+ const diffMs = startDateUtc.getTime() - nowUtc.getTime();
14
+ const isPast = diffMs < 0;
15
+ const absoluteDiffMs = Math.abs(diffMs);
16
+ const diffDays = Math.floor(absoluteDiffMs / (1e3 * 60 * 60 * 24));
17
+ const diffHours = Math.floor(
18
+ absoluteDiffMs % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)
19
+ );
20
+ const diffMinutes = Math.floor(
21
+ absoluteDiffMs % (1e3 * 60 * 60) / (1e3 * 60)
22
+ );
23
+ if (absoluteDiffMs < 6e4) {
24
+ return "Just now";
25
+ }
26
+ let timeParts = [
27
+ { value: diffDays, unit: "days" },
28
+ { value: diffHours, unit: "hours" },
29
+ { value: diffMinutes, unit: "minutes" }
30
+ ];
31
+ timeParts = timeParts.filter((part) => part.value > 0);
32
+ if (isPast) {
33
+ if (diffDays > 0) {
34
+ return `${diffDays} day(s) ago`;
35
+ } else if (diffHours > 0) {
36
+ return `${diffHours} hour(s) ago`;
37
+ } else if (diffMinutes > 0) {
38
+ return `${diffMinutes} minute(s) ago`;
39
+ } else {
40
+ return "Just now";
41
+ }
42
+ } else {
43
+ if (timeParts.length > 2) {
44
+ timeParts = timeParts.slice(0, 2);
45
+ }
46
+ const displayString = timeParts.map((part) => `${part.value} ${part.unit}`).join(" ");
47
+ return displayString ? `Starting in ${displayString}` : "Started";
48
+ }
49
+ };
50
+ const isValidDate = (date) => {
51
+ return !isNaN(Date.parse(date));
52
+ };
53
+ const [timeUntilStart, setTimeUntilStart] = useState(() => {
54
+ if (props.value && isValidDate(props.value)) {
55
+ return calculateTimeDifference(props.value);
56
+ }
57
+ return "";
58
+ });
59
+ useEffect(() => {
60
+ if (props.value && isValidDate(props.value)) {
61
+ setTimeUntilStart(calculateTimeDifference(props.value));
62
+ const initialTimeout = setTimeout(() => {
63
+ const interval = setInterval(() => {
64
+ setTimeUntilStart(calculateTimeDifference(props.value));
65
+ }, 6e4);
66
+ return () => clearInterval(interval);
67
+ }, 5e3);
68
+ return () => clearTimeout(initialTimeout);
69
+ } else {
70
+ setTimeUntilStart("");
71
+ }
72
+ }, [props.value]);
73
+ return /* @__PURE__ */ jsx("div", { children: timeUntilStart });
74
+ };
75
+ var TimeUntilStartsClient_default = TimeUntilStartsClient;
76
+ export {
77
+ TimeUntilStartsClient_default as default
78
+ };