26
26
import NcButton from '@nextcloud/vue/components/NcButton'
27
27
import NcPopover from '@nextcloud/vue/components/NcPopover'
28
28
import ClockIcon from 'vue-material-design-icons/Clock.vue'
29
+ import { getLocale } from '@nextcloud/l10n'
30
+ import dayjs from 'dayjs'
31
+ import relativeTime from 'dayjs/plugin/relativeTime'
32
+ import utc from 'dayjs/plugin/utc'
33
+ import timezone from 'dayjs/plugin/timezone'
34
+ import localizedFormat from 'dayjs/plugin/localizedFormat'
35
+
36
+ dayjs.extend(relativeTime)
37
+ dayjs.extend(utc)
38
+ dayjs.extend(timezone)
39
+ dayjs.extend(localizedFormat)
40
+
41
+ /**
42
+ *
43
+ * @param locale
44
+ */
45
+ async function loadLocale(locale) {
46
+ try {
47
+ await import(`dayjs/locale/${locale}.js`)
48
+ dayjs.locale(locale)
49
+ } catch (error) {
50
+ console.warn(`Locale ${locale} not found, falling back to English`)
51
+ dayjs.locale('en')
52
+ }
53
+ }
29
54
30
55
export default {
31
56
name: 'ShareExpiryTime',
@@ -45,15 +70,28 @@ export default {
45
70
46
71
computed: {
47
72
expiryTime() {
48
- return this.share?.expireDate || null
73
+ return this.share?.expireDate ? dayjs(this.share.expireDate) : null
49
74
},
50
75
51
76
formattedExpiry() {
52
- return this.expiryTime
53
- ? this.t('files_sharing', 'Share expires on {datetime}', { datetime: this.expiryTime })
54
- : ''
77
+ if (!this.expiryTime) {
78
+ return ''
79
+ }
80
+
81
+ const userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone
82
+ const formattedDate = this.expiryTime.tz(userTimezone).locale(getLocale()).format('LLLL')
83
+ const relativeTime = this.expiryTime.tz(userTimezone).fromNow()
84
+
85
+ return this.t('files_sharing', 'Share expires on {datetime} ({relative})', {
86
+ datetime: formattedDate,
87
+ relative: relativeTime,
88
+ })
55
89
},
56
90
},
91
+
92
+ created() {
93
+ loadLocale(getLocale())
94
+ },
57
95
}
58
96
</script>
59
97
@@ -72,7 +110,7 @@ export default {
72
110
}
73
111
74
112
.hint-body {
75
- padding: var(--border-radius-element);
76
- max-width: 300px;
77
- }
113
+ padding: var(--border-radius-element);
114
+ max-width: 300px;
115
+ }
78
116
</style>
0 commit comments