-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathHeaderDateTime.vue
More file actions
87 lines (74 loc) · 1.52 KB
/
HeaderDateTime.vue
File metadata and controls
87 lines (74 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<span v-if="enabled" class="header-date-time" :title="localizedDateTime">
{{ localizedDateTime }}
</span>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'HeaderDateTime',
props: {
enabled: {
type: Boolean,
default: false,
},
},
data() {
return {
localizedDateTime: '',
clockInterval: null as number | null,
}
},
watch: {
enabled: {
immediate: true,
handler(enabled: boolean) {
if (!enabled) {
this.stopClock()
return
}
this.updateDateTime()
this.startClock()
},
},
},
beforeDestroy() {
this.stopClock()
},
methods: {
startClock() {
if (this.clockInterval !== null) {
return
}
this.clockInterval = window.setInterval(this.updateDateTime, 30000)
},
stopClock() {
if (this.clockInterval === null) {
return
}
window.clearInterval(this.clockInterval)
this.clockInterval = null
},
updateDateTime() {
this.localizedDateTime = new Intl.DateTimeFormat(undefined, {
dateStyle: 'short',
timeStyle: 'short',
}).format(new Date())
},
},
})
</script>
<style lang="scss" scoped>
.header-date-time {
margin-inline-end: calc(2 * var(--default-grid-baseline));
white-space: nowrap;
font-size: var(--font-size-small);
line-height: var(--header-height);
color: var(--color-background-plain-text);
user-select: none;
}
</style>