sitetime

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sitetime holds the site's time zone (entity.SiteInformation.Timezone): dates are stored in UTC and shown in this zone. Set at startup and whenever the setting is saved; UTC until then.

Index

Constants

This section is empty.

Variables

View Source
var Zones = append([]string{"UTC"}, zones...)

Zones - the time zones offered in the site and user settings: UTC, then every canonical IANA zone of the world's regions (zones_gen.go). A stored zone outside the list is offered too (ZoneOptions).

Functions

func ForUser

func ForUser(name string) *time.Location

ForUser - the time zone to show a user's pages in: their own (name) when user time zones are on and name is a valid zone, else the site's.

func Format

func Format(t time.Time, layout string) string

Format - t in the site's time zone in layout; "-" for no time (zero or before 1970).

func FromContext

func FromContext(ctx context.Context) *time.Location

FromContext - the request's time zone (WithLocation), else the site's.

func In

func In(t time.Time) time.Time

In - t in the site's time zone.

func IsSite

func IsSite(loc *time.Location) bool

IsSite - loc is the site's time zone (the shared, pre-rendered output applies as is).

func Load

func Load(name string) (*time.Location, error)

Load - the zone named name; an empty name is invalid (unlike time.LoadLocation, which reads it as UTC).

func Location

func Location() *time.Location

Location - the site's time zone.

func Now

func Now() time.Time

Now - the current time in the site's time zone.

func Set

func Set(name string) error

Set makes name (an IANA zone like "Europe/Moscow") the site's time zone; an empty or unknown name is an error and changes nothing.

func SetUserZones

func SetUserZones(on bool)

SetUserZones turns per-user time zones on or off.

func UserZonesEnabled

func UserZonesEnabled() bool

UserZonesEnabled - whether users may set their own time zone.

func WithLocation

func WithLocation(ctx context.Context, loc *time.Location) context.Context

WithLocation - ctx carrying loc as the request's time zone.

Types

type ZoneOption

type ZoneOption struct {
	Name  string
	Label string
	Group string
}

ZoneOption - a zone for a select: Group - its region ("Europe", "America"…; "" for UTC), for an <optgroup>; Label - the rest of its name, readable, with its current UTC offset ("Buenos Aires, Argentina (UTC-3)" in "America"; "UTC").

func ZoneOptions

func ZoneOptions(current string) []ZoneOption

ZoneOptions - Zones (plus current when it is outside them), grouped by region, labelled by place and current offset.

Directories

Path Synopsis
internal
zonesgen command
Command zonesgen writes pkg/sitetime/zones_gen.go - the canonical IANA time zones (the tz database's Zone entries, not its Link aliases) of the world's regions, from a tzdata.zi file (default /usr/share/zoneinfo/tzdata.zi).
Command zonesgen writes pkg/sitetime/zones_gen.go - the canonical IANA time zones (the tz database's Zone entries, not its Link aliases) of the world's regions, from a tzdata.zi file (default /usr/share/zoneinfo/tzdata.zi).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL