Documentation
¶
Overview ¶
Package timex 提供全局统一的时区策略:存储一律 UTC,展示按配置时区或用户时区。 Package timex provides the unified timezone policy: persist in UTC, display in the configured or user timezone.
Index ¶
- Constants
- func Bound(t time.Time) time.Time
- func BoundAny(v interface{}) interface{}
- func BoundPtr(t *time.Time) *time.Time
- func DisplayLocation() *time.Location
- func DisplayTimezone() string
- func EnvDisplayTimezone() string
- func FormatAPI(t time.Time) string
- func Now() time.Time
- func ParseAPITime(value, tz string) (time.Time, error)
- func SeatunnelLocation() *time.Location
- func SetDisplayTimezone(name string) error
Constants ¶
const DefaultDisplayTimezone = "Asia/Shanghai"
DefaultDisplayTimezone 系统默认展示时区。/ System default display timezone.
Variables ¶
This section is empty.
Functions ¶
func Bound ¶
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 DisplayLocation ¶
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 ¶
FormatAPI 以 RFC3339(UTC,带 Z)序列化时间,零值返回空串。 FormatAPI serializes a time as RFC3339 in UTC (with Z); zero time yields "".
func Now ¶
Now 返回当前 UTC 时间,作为 GORM NowFunc 与所有持久化写入的时间源。 Now returns the current UTC time; used as GORM NowFunc and for all persisted writes.
func ParseAPITime ¶
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 ¶
SeatunnelLocation 返回解析 SeaTunnel 引擎/日志中无偏移时间时使用的时区: 环境变量 STX_SEATUNNEL_TIMEZONE,未设置时使用系统展示时区。 SeatunnelLocation returns the zone for naive SeaTunnel engine/log timestamps: STX_SEATUNNEL_TIMEZONE or the display zone.
func SetDisplayTimezone ¶
SetDisplayTimezone 设置系统默认展示时区;非法名称返回错误且不修改当前值。 SetDisplayTimezone sets the system display timezone; invalid names return an error and leave the value unchanged.
Types ¶
This section is empty.