timeutil

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package timeutil provides centralized timezone handling for the application. Call LoadLocation once during initialization to set the canonical timezone, then use Now() and Location() throughout business logic instead of time.Now() and time.Local.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats a time as "2006-01-02" in the application timezone.

func InLoc

func InLoc(t time.Time) time.Time

InLoc converts a time to the application timezone.

func LoadLocation

func LoadLocation(tzName string) error

LoadLocation loads the timezone by name (e.g., "Asia/Shanghai", "UTC"). Must be called once at startup before any other function in this package.

func Location

func Location() *time.Location

Location returns the canonical application timezone. Falls back to time.Local if LoadLocation was never called.

func LocationName

func LocationName() string

LocationName returns the configured timezone name.

func Now

func Now() time.Time

Now returns the current time in the application timezone. Falls back to time.Now() if LoadLocation was never called.

func ParseDate

func ParseDate(s string) (time.Time, error)

ParseDate parses a "2006-01-02" string in the application timezone.

func TodayEnd

func TodayEnd() time.Time

TodayEnd returns the end of today (24:00:00) in the application timezone.

func TodayStart

func TodayStart() time.Time

TodayStart returns the start of today (00:00:00) in the application timezone.

func UnixMilli

func UnixMilli(t time.Time) int64

UnixMilli returns the UnixMilli of the given time (for timestamp fields).

Types

This section is empty.

Jump to

Keyboard shortcuts

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