Files
oslstats/internal/view/seasonsview/localtime.templ

44 lines
1.2 KiB
Plaintext

package seasonsview
import "time"
// formatISO returns an ISO 8601 UTC string for use in <time datetime="...">.
func formatISO(t *time.Time) string {
if t == nil {
return ""
}
return t.UTC().Format(time.RFC3339)
}
// formatISOUnix returns an ISO 8601 UTC string from a Unix timestamp.
func formatISOUnix(unix int64) string {
return time.Unix(unix, 0).UTC().Format(time.RFC3339)
}
// localtime renders a <time> element that will be formatted client-side
// in the user's local timezone. The format parameter maps to data-localtime:
// "date" → "Mon 2 Jan 2026"
// "time" → "3:04 PM"
// "datetime" → "Mon 2 Jan 2026 at 3:04 PM"
// "short" → "Mon 2 Jan 3:04 PM"
// "histdate" → "2 Jan 2006 15:04"
templ localtime(t *time.Time, format string) {
if t != nil {
<time datetime={ formatISO(t) } data-localtime={ format }>
{ t.UTC().Format("2 Jan 2006 15:04 UTC") }
</time>
} else {
No time set
}
}
// localtimeUnix renders a <time> element from a Unix timestamp.
templ localtimeUnix(unix int64, format string) {
{{
t := time.Unix(unix, 0)
}}
<time datetime={ formatISOUnix(unix) } data-localtime={ format }>
{ t.UTC().Format("2 Jan 2006 15:04 UTC") }
</time>
}