Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( InvalidISOWeekString = errors.New("Invalid ISOWeek string") InvalidWeekNumberError = errors.New("Invalid week number") )
View Source
var ISOWeekCodec = NewTimeCodec(func(t time.Time) string { y, d := t.ISOWeek() return fmt.Sprintf("%d-%02d", y, d) }, func(value string) (time.Time, error) { match := isoweekRx.FindStringSubmatch(value) if match == nil { return time.Time{}, InvalidISOWeekString } year, _ := strconv.Atoi(string(match[1])) week, _ := strconv.Atoi(string(match[2])) if !(0 < week && week <= 53) { return time.Time{}, InvalidWeekNumberError } t := time.Date(year, 1, 0, 0, 0, 0, 0, time.UTC) for t.Weekday() > time.Sunday { t = t.Add(-24 * time.Hour) } t = t.Add(time.Duration(week+1) * 7 * 24 * time.Hour) return t, nil })
View Source
var MillisTimeCodec = NewTimeCodec(func(t time.Time) string { return strconv.FormatInt(UnixMillis(t), 10) }, func(value string) (time.Time, error) { ms, err := strconv.ParseInt(value, 10, 64) if err != nil { return time.Time{}, err } t := time.Unix(0, int64(time.Duration(ms)*time.Millisecond)) return t, err })
Functions ¶
func UnixMillis ¶
Types ¶
type LayoutCodec ¶
type LayoutCodec string
func (LayoutCodec) MarshalTime ¶
func (layout LayoutCodec) MarshalTime(t time.Time) string
func (LayoutCodec) UnmarshalTime ¶
func (layout LayoutCodec) UnmarshalTime(value string) (time.Time, error)
type TimeCodec ¶
type TimeCodec interface { TimeEncoder TimeDecoder }
func NewTimeCodec ¶
func NewTimeCodec(enc TimeEncoderFunc, dec TimeDecoderFunc) TimeCodec
func UnixMillisTimeCodec ¶
func UnixTimeCodec ¶
type TimeEncoder ¶
type TimeEncoderFunc ¶
Click to show internal directories.
Click to hide internal directories.