timeutil

package
v1.20.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: GPL-3.0 Imports: 3 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 AddTime added in v1.20.2

func AddTime(unit string, quantity int64, baseTime ...time.Time) time.Time

func DayDiff added in v1.20.2

func DayDiff(startTime, endTime time.Time) int64

func DaysToMonthDay added in v1.20.2

func DaysToMonthDay(t time.Time, targetDay int) int64

func DaysToNextMonth added in v1.20.2

func DaysToNextMonth(t time.Time) int64

func DaysToYearDay added in v1.20.2

func DaysToYearDay(t time.Time, month int, day int) int64

func FormatDate

func FormatDate(t time.Time) string

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

func GetLastDayOfMonth added in v1.20.2

func GetLastDayOfMonth(t time.Time) int64

GetLastDayOfMonth 获取指定时间所在月份的最后一天

func GetYearDays added in v1.20.2

func GetYearDays(t time.Time, month int, day int) int64

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 MonthDiff added in v1.20.2

func MonthDiff(startTime, endTime time.Time) int

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).

func YearDiff added in v1.20.2

func YearDiff(startTime, endTime time.Time) int

Types

This section is empty.

Jump to

Keyboard shortcuts

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