This commit is contained in:
tobi 2025-03-02 11:01:33 +01:00
commit f94347864e
3 changed files with 13 additions and 35 deletions

View file

@ -26,7 +26,6 @@ import (
"reflect"
"regexp"
"strings"
"time"
"unsafe"
"github.com/gin-gonic/gin"
@ -128,7 +127,6 @@ var funcMap = template.FuncMap{
"oddOrEven": oddOrEven,
"subtract": subtract,
"timestampPrecise": timestampPrecise,
"timestamp": timestamp,
"timestampVague": timestampVague,
"visibilityIcon": visibilityIcon,
}
@ -174,29 +172,6 @@ const (
badTimestamp = "bad timestamp"
)
func timestamp(stamp string) string {
t, err := util.ParseISO8601(stamp)
if err != nil {
log.Errorf(nil, "error parsing timestamp %s: %s", stamp, err)
return badTimestamp
}
t = t.Local()
tYear, tMonth, tDay := t.Date()
now := time.Now()
currentYear, currentMonth, currentDay := now.Date()
switch {
case tYear == currentYear && tMonth == currentMonth && tDay == currentDay:
return "Today, " + t.Format(justTime)
case tYear == currentYear:
return t.Format(dateTime)
default:
return t.Format(dateYear)
}
}
func timestampPrecise(stamp string) string {
t, err := util.ParseISO8601(stamp)
if err != nil {

View file

@ -185,16 +185,19 @@ Array.from(document.getElementsByClassName("plyr-video")).forEach((video) => {
Array.from(document.getElementsByTagName('time')).forEach(timeTag => {
const datetime = timeTag.getAttribute('datetime');
const currentText = timeTag.textContent.trim();
// Only format if current text contains precise time
// Only format if current text contains precise time.
if (currentText.match(/\d{2}:\d{2}/)) {
const date = new Date(datetime);
timeTag.textContent = date.toLocaleString(undefined, {
timeTag.textContent = date.toLocaleString(
undefined,
{
year: 'numeric',
month: 'short',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false
});
},
);
}
});

View file

@ -18,7 +18,7 @@
*/ -}}
{{- define "ariaLabel" -}}
@{{ .Account.Acct -}}, {{ timestamp .CreatedAt -}}
@{{ .Account.Acct -}}, {{ .CreatedAt | timestampPrecise -}}
{{- if .LanguageTag -}}
, language {{ .LanguageTag.DisplayStr -}}
{{- end -}}