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" "reflect"
"regexp" "regexp"
"strings" "strings"
"time"
"unsafe" "unsafe"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -128,7 +127,6 @@ var funcMap = template.FuncMap{
"oddOrEven": oddOrEven, "oddOrEven": oddOrEven,
"subtract": subtract, "subtract": subtract,
"timestampPrecise": timestampPrecise, "timestampPrecise": timestampPrecise,
"timestamp": timestamp,
"timestampVague": timestampVague, "timestampVague": timestampVague,
"visibilityIcon": visibilityIcon, "visibilityIcon": visibilityIcon,
} }
@ -174,29 +172,6 @@ const (
badTimestamp = "bad timestamp" 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 { func timestampPrecise(stamp string) string {
t, err := util.ParseISO8601(stamp) t, err := util.ParseISO8601(stamp)
if err != nil { if err != nil {

View file

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

View file

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