Web interface: dates and times in the user's Nextcloud locale
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
// SPDX-FileCopyrightText: 2026 Dillard Blom
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
import { getCanonicalLocale } from '@nextcloud/l10n'
|
||||
|
||||
// The locale of the user's Nextcloud settings (Personal info > Locale), not the browser's:
|
||||
// a browser set to English would otherwise show 4:00 PM to someone with a 24-hour locale.
|
||||
const locale = getCanonicalLocale()
|
||||
|
||||
// A number is a unix timestamp in seconds, a string an ISO 8601 date (snapshot times).
|
||||
const toDate = (value) => typeof value === 'number' ? new Date(value * 1000) : new Date(value)
|
||||
|
||||
export const formatDateTime = (value) => toDate(value).toLocaleString(locale)
|
||||
|
||||
export const formatDate = (value) => toDate(value).toLocaleDateString(locale)
|
||||
|
||||
export function formatSize(bytes) {
|
||||
if (bytes === null || bytes === undefined) {
|
||||
return ''
|
||||
|
||||
Reference in New Issue
Block a user