chrono

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 4 Imported by: 14

Documentation

Index

Constants

View Source
const (
	SQLDateTime = "2006-01-02 15:04:05"
	SQLDate     = "2006-01-02"
	CST         = "2006年01月02日 15:04:05 Z07" // China Standard Time
)

Predefined time formats.

Variables

View Source
var (
	TZShanghai = time.FixedZone("UTC+8", 8*secondsOfHour)
)

Fixed time zones.

Functions

func ParseDateTime

func ParseDateTime(str string, loc *time.Location) (t time.Time, err error)

ParseDateTime parses SQL DATE or DATETIME string in specified location.

Types

type Date

type Date struct {
	time.Time
}

Date is used to save and output YYYY-MM-DD format date string.

func DateFrom

func DateFrom(t time.Time) Date

DateFrom creates a new Time wrapping time.Time.

func DateNow

func DateNow() Date

DateNow creates current time.

func DateUTCFrom added in v0.9.1

func DateUTCFrom(t time.Time) Date

func DateUTCNow added in v0.9.1

func DateUTCNow() Date

func DateZero

func DateZero() Date

DateZero creates the zero value of Time.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON converts a Time struct to ISO8601 string.

func (*Date) Scan

func (d *Date) Scan(value interface{}) (err error)

Scan implements the Scanner interface. SQL NULL will be turned into time zero value.

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON converts ISO8601 data time into a Time struct. Empty string and null will be turned into time.Time zero value.

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value implements the driver Valuer interface. Zero value is turned into SQL NULL.

type Time

type Time struct {
	time.Time
}

Time is used to save and output ISO8601 date time with time zone set to UTC.

func TimeFrom

func TimeFrom(t time.Time) Time

TimeFrom creates a new Time wrapping time.Time.

func TimeNow

func TimeNow() Time

TimeNow creates current time.

func TimeUTCFrom added in v0.9.1

func TimeUTCFrom(t time.Time) Time

func TimeUTCNow added in v0.9.1

func TimeUTCNow() Time

TimeUTCNow creates a Time instance with timezone set to UTC and truncated to second.

func TimeZero

func TimeZero() Time

TimeZero creates the zero value of Time.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON converts a Time struct to ISO8601 string.

func (*Time) Scan

func (t *Time) Scan(value interface{}) (err error)

Scan implements the Scanner interface. SQL NULL will be turned into time zero value.

func (Time) StringCN

func (t Time) StringCN() string

StringCN produces the string representation in Chinese format with locale set to Asia/Shanghai.

func (Time) StringEN

func (t Time) StringEN() string

StringEN produces the string representation in English with locale set to UTC.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format. Empty string and null will be turned into time.Time zero value.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements the driver Valuer interface. Zero value is turned into SQL NULL.

Jump to

Keyboard shortcuts

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