@1001-digital/layers.base 0.0.3 → 0.0.5
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/.claude/settings.local.json +9 -0
- package/app/composables/time.ts +63 -0
- package/app/utils/time.ts +20 -0
- package/package.json +3 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DateTime } from 'luxon'
|
|
2
|
+
import type { Ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
let nowInterval: NodeJS.Timeout | undefined
|
|
5
|
+
|
|
6
|
+
export const useSeconds = () => {
|
|
7
|
+
const now = useState<number>('now', () => nowInSeconds())
|
|
8
|
+
|
|
9
|
+
if (import.meta.client && !nowInterval) {
|
|
10
|
+
nowInterval = setInterval(() => {
|
|
11
|
+
now.value = nowInSeconds()
|
|
12
|
+
}, 1000)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return now
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useCountDown = (s: Ref<number | bigint>, showSecondsWithin: number = 60) => {
|
|
19
|
+
const duration = computed(() => Math.abs(Number(s.value)))
|
|
20
|
+
|
|
21
|
+
const seconds = computed(() => duration.value % 60)
|
|
22
|
+
const minutes = computed(() => Math.floor(duration.value / 60) % 60)
|
|
23
|
+
const hours = computed(() => Math.floor(duration.value / 60 / 60) % 24)
|
|
24
|
+
const days = computed(() => Math.floor(duration.value / 60 / 60 / 24))
|
|
25
|
+
|
|
26
|
+
const str = computed(() =>
|
|
27
|
+
[
|
|
28
|
+
days.value ? `${days.value}d` : null,
|
|
29
|
+
hours.value ? `${hours.value}h` : null,
|
|
30
|
+
minutes.value ? `${minutes.value}m` : null,
|
|
31
|
+
duration.value < showSecondsWithin && seconds.value ? `${seconds.value}s` : null,
|
|
32
|
+
]
|
|
33
|
+
.filter((s) => !!s)
|
|
34
|
+
.join(' '),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
seconds,
|
|
39
|
+
minutes,
|
|
40
|
+
hours,
|
|
41
|
+
days,
|
|
42
|
+
str,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const useSecondsAgo = (time: Ref<string | undefined>) => {
|
|
47
|
+
const ago = ref<string>()
|
|
48
|
+
const now = useSeconds()
|
|
49
|
+
|
|
50
|
+
watch(
|
|
51
|
+
now,
|
|
52
|
+
() => {
|
|
53
|
+
if (time.value) {
|
|
54
|
+
ago.value = DateTime.fromISO(time.value).toRelative({ style: 'short', locale: 'en' }) ?? undefined
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
immediate: true,
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return ago
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DateTime } from 'luxon'
|
|
2
|
+
|
|
3
|
+
export const delay = (ms: number): Promise<void> =>
|
|
4
|
+
new Promise((resolve) => setTimeout(resolve, ms))
|
|
5
|
+
|
|
6
|
+
export const daysInSeconds = (days: number): number => days * 60 * 60 * 24
|
|
7
|
+
|
|
8
|
+
export const nowInSeconds = (): number => Math.floor(Date.now() / 1000)
|
|
9
|
+
|
|
10
|
+
export const asUTCDate = (date: Date | null) =>
|
|
11
|
+
date
|
|
12
|
+
? DateTime.utc(
|
|
13
|
+
date.getFullYear(),
|
|
14
|
+
date.getMonth() + 1,
|
|
15
|
+
date.getDate(),
|
|
16
|
+
date.getHours(),
|
|
17
|
+
date.getMinutes(),
|
|
18
|
+
date.getSeconds(),
|
|
19
|
+
)
|
|
20
|
+
: null
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1001-digital/layers.base",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@iconify-json/lucide": "^1.2.81",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@nuxt/icon": "^1.10.3",
|
|
18
|
+
"@types/luxon": "^3.6.2",
|
|
19
|
+
"luxon": "^3.6.1",
|
|
18
20
|
"modern-normalize": "^3.0.1",
|
|
19
21
|
"reka-ui": "^2.6.1"
|
|
20
22
|
},
|