@unitedstatespowersquadrons/components 1.3.4-4 → 1.3.4-6
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/Badges/LiveDate.tsx +24 -3
- package/package.json +1 -1
package/Badges/LiveDate.tsx
CHANGED
|
@@ -4,18 +4,39 @@ import "javascript-time-ago/locale/en";
|
|
|
4
4
|
import Badge from "./Badge";
|
|
5
5
|
import { dateBadgeColor } from "./Date";
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface HasDate {
|
|
8
|
+
date: Date;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface HasTimestamp {
|
|
8
12
|
timestamp: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface BaseProps {
|
|
9
16
|
label?: string;
|
|
10
17
|
logo?: string;
|
|
11
18
|
}
|
|
12
19
|
|
|
20
|
+
type Props =
|
|
21
|
+
| BaseProps & HasDate
|
|
22
|
+
| BaseProps & HasTimestamp;
|
|
23
|
+
|
|
13
24
|
const LiveDateBadge = (props: Props) => {
|
|
14
|
-
const {
|
|
25
|
+
const { label = "date", logo } = props;
|
|
26
|
+
|
|
27
|
+
let timestamp: number;
|
|
28
|
+
|
|
29
|
+
if ("date" in props) {
|
|
30
|
+
timestamp = props.date.getTime();
|
|
31
|
+
} else if ("timestamp" in props) {
|
|
32
|
+
timestamp = props.timestamp;
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error("Must provide date or timestamp");
|
|
35
|
+
}
|
|
15
36
|
|
|
16
37
|
const now = Math.floor(Date.now() / 1000);
|
|
17
38
|
|
|
18
|
-
const badgeTimestamp = Math.floor(
|
|
39
|
+
const badgeTimestamp = Math.floor(timestamp / 1000);
|
|
19
40
|
const badgeDate = new Date(badgeTimestamp * 1000);
|
|
20
41
|
const badgeDateDiff = badgeTimestamp - now;
|
|
21
42
|
const color = dateBadgeColor(badgeDateDiff);
|