timex

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package timex 提供全局统一的时区策略:存储一律 UTC,展示按配置时区或用户时区。 Package timex provides the unified timezone policy: persist in UTC, display in the configured or user timezone.

Index

Constants

View Source
const DefaultDisplayTimezone = "Asia/Shanghai"

DefaultDisplayTimezone 系统默认展示时区。/ System default display timezone.

Variables

This section is empty.

Functions

func Bound

func Bound(t time.Time) time.Time

Bound 将查询区间边界规范化为 UTC,保证与 UTC 存储的列在所有驱动(尤其 SQLite 文本比较)下语义一致。 Bound normalizes a range-query bound to UTC so comparisons against UTC-stored columns are correct on every driver (SQLite compares DATETIME as text).

func BoundAny

func BoundAny(v interface{}) interface{}

BoundAny 对 time.Time / *time.Time 值做 Bound,其他类型原样返回。 BoundAny applies Bound to time.Time or *time.Time values and returns other values unchanged.

func BoundPtr

func BoundPtr(t *time.Time) *time.Time

BoundPtr 是 Bound 的指针版本。/ BoundPtr is the pointer variant of Bound.

func DisplayLocation

func DisplayLocation() *time.Location

DisplayLocation 返回系统默认展示时区。/ DisplayLocation returns the system display location.

func DisplayTimezone

func DisplayTimezone() string

DisplayTimezone 返回系统默认展示时区名称。/ DisplayTimezone returns the system display timezone name.

func EnvDisplayTimezone

func EnvDisplayTimezone() string

EnvDisplayTimezone 读取环境变量中的展示时区(STX_DISPLAY_TIMEZONE,兼容旧的 STX_REPORT_TIMEZONE)。 EnvDisplayTimezone reads the display timezone from env (STX_DISPLAY_TIMEZONE, legacy alias STX_REPORT_TIMEZONE).

func FormatAPI

func FormatAPI(t time.Time) string

FormatAPI 以 RFC3339(UTC,带 Z)序列化时间,零值返回空串。 FormatAPI serializes a time as RFC3339 in UTC (with Z); zero time yields "".

func Now

func Now() time.Time

Now 返回当前 UTC 时间,作为 GORM NowFunc 与所有持久化写入的时间源。 Now returns the current UTC time; used as GORM NowFunc and for all persisted writes.

func ParseAPITime

func ParseAPITime(value, tz string) (time.Time, error)

ParseAPITime 解析 API 时间参数:优先 RFC3339(必须带偏移或 Z); 无偏移的 "2006-01-02 15:04:05"/"2006-01-02T15:04:05"/"2006-01-02" 仅在显式提供 tz 时接受。 ParseAPITime parses API time input: RFC3339 with offset/Z; naive layouts are accepted only with an explicit tz.

func SeatunnelLocation

func SeatunnelLocation() *time.Location

SeatunnelLocation 返回解析 SeaTunnel 引擎/日志中无偏移时间时使用的时区: 环境变量 STX_SEATUNNEL_TIMEZONE,未设置时使用系统展示时区。 SeatunnelLocation returns the zone for naive SeaTunnel engine/log timestamps: STX_SEATUNNEL_TIMEZONE or the display zone.

func SetDisplayTimezone

func SetDisplayTimezone(name string) error

SetDisplayTimezone 设置系统默认展示时区;非法名称返回错误且不修改当前值。 SetDisplayTimezone sets the system display timezone; invalid names return an error and leave the value unchanged.

Types

This section is empty.

Jump to

Keyboard shortcuts

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