Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fa530fd

Browse files
committedMar 24, 2025·
feat(files_sharing): Show share expiration time in human friendly manner
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 780f3a6 commit fa530fd

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed
 

‎apps/files_sharing/src/components/ShareExpiryTime.vue

+45-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@
2626
import NcButton from '@nextcloud/vue/components/NcButton'
2727
import NcPopover from '@nextcloud/vue/components/NcPopover'
2828
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+
}
2954

3055
export default {
3156
name: 'ShareExpiryTime',
@@ -45,15 +70,28 @@ export default {
4570

4671
computed: {
4772
expiryTime() {
48-
return this.share?.expireDate || null
73+
return this.share?.expireDate ? dayjs(this.share.expireDate) : null
4974
},
5075

5176
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+
})
5589
},
5690
},
91+
92+
created() {
93+
loadLocale(getLocale())
94+
},
5795
}
5896
</script>
5997

@@ -72,7 +110,7 @@ export default {
72110
}
73111

74112
.hint-body {
75-
padding: var(--border-radius-element);
76-
max-width: 300px;
77-
}
113+
padding: var(--border-radius-element);
114+
max-width: 300px;
115+
}
78116
</style>

0 commit comments

Comments
 (0)
Please sign in to comment.