Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ReplyBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import moment from '@nextcloud/moment'
import negate from 'lodash/fp/negate.js'
import { formatDateTimeFromUnix } from './util/formatDateTime.js'
import { html } from './util/text.js'

/**
Expand All @@ -24,7 +24,7 @@ export function buildReplyBody(original, from, date, replyOnTop = true) {
switch (original.format) {
case 'plain':
if (from) {
const dateString = moment.unix(date).format('LLL')
const dateString = formatDateTimeFromUnix(date)
return replyOnTop
? html(`${startEnd}${quoteStart}"${from.label}" ${from.email} – ${dateString}` + plainBody + quoteEnd)
: html(`${quoteStart}"${from.label}" ${from.email} – ${dateString}` + plainBody + quoteEnd + startEnd)
Expand All @@ -35,7 +35,7 @@ export function buildReplyBody(original, from, date, replyOnTop = true) {
}
case 'html':
if (from) {
const dateString = moment.unix(date).format('LLL')
const dateString = formatDateTimeFromUnix(date)
return replyOnTop
? html(`${startEnd}${quoteStart}"${from.label}" ${from.email} – ${dateString}<br>${htmlBody}${quoteEnd}`)
: html(`${quoteStart}"${from.label}" ${from.email} – ${dateString}<br>${htmlBody}${quoteEnd}${startEnd}`)
Expand Down
5 changes: 3 additions & 2 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ import { findRecipient } from '../service/AutocompleteService.js'
import { savePreference } from '../service/PreferenceService.js'
import { EDITOR_MODE_HTML, EDITOR_MODE_TEXT } from '../store/constants.js'
import useMainStore from '../store/mainStore.js'
import { formatDateTime } from '../util/formatDateTime.js'
import { detect, html, toHtml, toPlain } from '../util/text.js'
import textBlockSvg from './../../img/text_snippet.svg'

Expand Down Expand Up @@ -760,11 +761,11 @@ export default {
firstDayDatetimePicker: getFirstDay() === 0 ? 7 : getFirstDay(),
formatter: {
stringify: (date) => {
return date ? moment(date).format('LLL') : ''
return date ? formatDateTime(date) : ''
},

parse: (value) => {
return value ? moment(value, 'LLL').toDate() : null
return value ? new Date(value) : null
},
},

Expand Down
4 changes: 2 additions & 2 deletions src/components/Thread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
<script>
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import moment from '@nextcloud/moment'
import { NcAppContentDetails as AppContentDetails, NcPopover } from '@nextcloud/vue'
import debounce from 'lodash/fp/debounce.js'
import { mapStores } from 'pinia'
Expand All @@ -87,6 +86,7 @@ import logger from '../logger.js'
import { summarizeThread } from '../service/AiIntergrationsService.js'
import useMainStore from '../store/mainStore.js'
import { getRandomMessageErrorMessage } from '../util/ErrorMessageFactory.js'
import { formatDateTimeFromUnix } from '../util/formatDateTime.js'

export default {
name: 'Thread',
Expand Down Expand Up @@ -466,7 +466,7 @@ export default {

const dateSpan = virtualIframeDocument.createElement('p')
dateSpan.style.fontWeight = 'bold'
dateSpan.textContent = t('mail', 'Date') + ': ' + moment.unix(this.thread[index].dateInt).format('LLL')
dateSpan.textContent = t('mail', 'Date') + ': ' + formatDateTimeFromUnix(this.thread[index].dateInt)

const recipientSpan = virtualIframeDocument.createElement('p')
recipientSpan.style.fontWeight = 'bold'
Expand Down
32 changes: 32 additions & 0 deletions src/util/formatDateTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { getCanonicalLocale } from '@nextcloud/l10n'

/**
* Format a date as a localized long date with time (equivalent to moment's LLL format).
*
* @param {Date} date The date to format
* @return {string} Formatted date string (e.g. "September 4, 1986, 8:30 PM")
*/
export function formatDateTime(date) {
return new Intl.DateTimeFormat(getCanonicalLocale(), {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
}).format(date)
}

/**
* Format a Unix timestamp as a localized long date with time.
*
* @param {number} timestamp Unix timestamp in seconds
* @return {string} Formatted date string
*/
export function formatDateTimeFromUnix(timestamp) {
return formatDateTime(new Date(timestamp * 1000))
}
Loading