time

package
v0.0.0-...-3b2b5cc Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 12 Imported by: 5

Documentation

Overview

Package time GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE

Index

Constants

This section is empty.

Variables

View Source
var (
	UTC               = time.UTC
	TimestampZero     = Timestamp(time.Time{})
	TimestampUnixZero = Timestamp(time.Unix(0, 0))
)
View Source
var CST = time.UTC

CST 表示默认使用的时区位置。

Functions

func AddSupportedLayout

func AddSupportedLayout(layout string, location *time.Location)

AddSupportedLayout 注册一个可解析的时间布局。

func IsDuration

func IsDuration(str string) bool

IsDuration 判断字符串能否被解析为时长。

func ParseDuration

func ParseDuration(cand string) (time.Duration, error)

ParseDuration 解析兼容标准格式与扩展单位写法的时长字符串。

func SetOutputLayout

func SetOutputLayout(layout string, location *time.Location)

SetOutputLayout 设置时间输出布局,并可同步更新默认时区。

func Sub

func Sub(t Timestamp, u Timestamp) time.Duration

Sub 返回两个时间之间的时长差。

Types

type CreationModificationTime

type CreationModificationTime struct {
	CreationTime
	// 更新时间
	UpdatedAt Timestamp `db:"f_updated_at,default='0'" json:"updatedAt"`
}

CreationModificationTime 定义同时包含创建和更新时间的通用结构。

func (*CreationModificationTime) RuntimeDoc

func (v *CreationModificationTime) RuntimeDoc(names ...string) ([]string, bool)

type CreationTime

type CreationTime struct {
	// 创建时间
	CreatedAt Timestamp `db:"f_created_at,default='0'" json:"createdAt"`
}

CreationTime 定义带创建时间字段的通用结构。

func (*CreationTime) MarkCreatedAt

func (times *CreationTime) MarkCreatedAt()

func (*CreationTime) RuntimeDoc

func (v *CreationTime) RuntimeDoc(names ...string) ([]string, bool)

type CreationUpdationDeletionTime

type CreationUpdationDeletionTime struct {
	CreationUpdationTime
	// 删除时间
	DeletedAt Timestamp `db:"f_deleted_at,default='0'" json:"deletedAt"`
}

CreationUpdationDeletionTime 定义带软删除时间的通用结构。

func (*CreationUpdationDeletionTime) MarkDeletedAt

func (times *CreationUpdationDeletionTime) MarkDeletedAt()

func (*CreationUpdationDeletionTime) RuntimeDoc

func (v *CreationUpdationDeletionTime) RuntimeDoc(names ...string) ([]string, bool)

func (CreationUpdationDeletionTime) SoftDeleteFieldAndZeroValue

func (CreationUpdationDeletionTime) SoftDeleteFieldAndZeroValue() (string, driver.Value)

type CreationUpdationTime

type CreationUpdationTime = CreationModificationTime

CreationUpdationTime 是兼容旧命名的更新时间结构别名。

func (*CreationUpdationTime) MarkCreatedAt

func (times *CreationUpdationTime) MarkCreatedAt()

func (*CreationUpdationTime) MarkModifiedAt

func (times *CreationUpdationTime) MarkModifiedAt()

type Duration

type Duration time.Duration

Duration 表示可序列化、可扫描的时长值。

func (Duration) IsZero

func (d Duration) IsZero() bool

IsZero 判断时长是否为零。

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (Duration) OpenAPISchemaFormat

func (Duration) OpenAPISchemaFormat() string

OpenAPISchemaFormat 返回 OpenAPI 使用的格式名。

func (*Duration) Scan

func (d *Duration) Scan(raw any) error

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(data []byte) error

type Timestamp

type Timestamp time.Time

Timestamp 表示以秒级 Unix 时间存储的时间值。

func Add

func Add(t Timestamp, d time.Duration) Timestamp

Add 返回时间加上指定时长后的结果。

func AddDate

func AddDate(t Timestamp, years int, months int, days int) Timestamp

AddDate 返回时间按年月日偏移后的结果。

func Now

func Now() Timestamp

Now 返回当前时间对应的 Timestamp。

func ParseTimestampFromString

func ParseTimestampFromString(s string) (d Timestamp, err error)

ParseTimestampFromString 按已注册布局解析时间字符串。

func ParseTimestampFromStringWithLayout

func ParseTimestampFromStringWithLayout(input, layout string) (Timestamp, error)

ParseTimestampFromStringWithLayout 按指定布局解析时间字符串。

func (Timestamp) DataType

func (Timestamp) DataType(engine string) string

DataType 返回数据库侧的数据类型名。

func (Timestamp) Date

func (dt Timestamp) Date() (int, time.Month, int)

func (Timestamp) Day

func (dt Timestamp) Day() int

func (Timestamp) Format

func (dt Timestamp) Format(layout string) string

func (Timestamp) In

func (dt Timestamp) In(loc *time.Location) Timestamp

func (Timestamp) IsZero

func (dt Timestamp) IsZero() bool

func (Timestamp) MarshalText

func (dt Timestamp) MarshalText() ([]byte, error)

func (Timestamp) Month

func (dt Timestamp) Month() time.Month

func (Timestamp) OpenAPISchemaFormat

func (Timestamp) OpenAPISchemaFormat() string

OpenAPISchemaFormat 返回 OpenAPI 使用的格式名。

func (*Timestamp) Scan

func (dt *Timestamp) Scan(value any) error

func (Timestamp) String

func (dt Timestamp) String() string

func (Timestamp) Unix

func (dt Timestamp) Unix() int64

func (*Timestamp) UnmarshalText

func (dt *Timestamp) UnmarshalText(data []byte) (err error)

func (Timestamp) Value

func (dt Timestamp) Value() (driver.Value, error)

func (Timestamp) Year

func (dt Timestamp) Year() int

Jump to

Keyboard shortcuts

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