Hello team,
i want modify the post data format to YYYY-MM-DD HH:mm
Modifying in frontend javascript doesn’t seem reasonable
1.Can I use a theme to override this time?
2.how can i modify this in the email too(now it only display data)
All the date formats are available to customize along with other text. Check out this guide:
thanks for your reply, David
I saw this custom setting, but it seems that I don’t find it here.
I want to display the time format of all posts as absolute time. For example, the current my topic post ‘3h’ is displayed as ‘12 May 17:33’
do you know what is the best way for me to change all post data to the YYYY-MM-DD HH:mm format, even it post in some minutes
Ah I see!
In that case, you could try changing the “relative date duration” site setting.
relative_date_duration: Number of days after posting where post dates will be shown as relative (7d) instead of absolute (20 Feb).
So I think for your case, you would set it to 0
yes,
I have set it to 0, but it still doesn’t take effect now. Does it take some time or do I need to rake posts:rebake
like we do after change domain?
It should only need a page refresh to take effect. Has it made any difference at all? What do your post dates look like now?
Hmm, it seems like dates which are less than 23.5 hours ago are always shown as relative, regardless of that setting:
So, your change to the setting will have applied to posts more than 1 day old. But it doesn’t look like we currently have a way to change the behaviour of things which are less than a day old.
i see this file
discourse-main/app/assets/javascripts/discourse/app/components/post/meta-data/date.gjs
<template>
<div class="post-info post-date">
<a
class={{concatClass
"post-date"
(if (and @post.wiki @post.last_wiki_edit) "last-wiki-edit")
}}
href={{@post.shareUrl}}
title={{i18n "post.sr_date"}}
{{on "click" this.showShareModal}}
>
<RelativeDate @date={{this.date}} />
</a>
</div>
</template>
is this the correct template, can i change it by a theme component?
No, you cannot override .gjs templates, unfortunately (intended to improve and encourage stability of overrides)
Welcome back. @aksoforever!
How are you getting on with this? Can you tell us some more about your use case?
Why would you want to impose such long, absolute dates on your members? The “time ago” dates are quite friendly on the eye and convey the information you need to know how old a post is. Mousing over it shows you the explicit timestamp.
Thanks for your attention @tobiaseigen
Yes, now the display of Discourse is very modern and friendly, and more suitable for most people
It is only for a small number of people who use it frequently that using absolute time feels faster and more direct.
Regarding the time in the email, it now only shows the month and day.
It is not user-friendly to use email to view information. It does not show the year, especially when reviewing information from many years ago.
I am currently using a downgraded version of Discourse and rewriting the front-end code using components
Email uses below in a plugin, can i modify short_date from a theme componet?
after_initialize do
if SiteSetting.custom_email_date_format_enabled
module ::EmailHelper
def short_date(datetime)
china_time = datetime.in_time_zone("Asia/Shanghai")
china_time.strftime("%Y-%m-%d %H:%M")
end
end
end
end