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 (
ErrNilDecoder = errors.New("Nil time decoder")
)
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 = UnixMillisTimeCodec(0)
Functions ¶
func UnixMillis ¶
Types ¶
type LayoutCodec ¶
type LayoutCodec string
const ( ANSIC LayoutCodec = time.ANSIC UnixDate LayoutCodec = time.UnixDate RubyDate LayoutCodec = time.RubyDate RFC822 LayoutCodec = time.RFC822 RFC822Z LayoutCodec = time.RFC822Z RFC850 LayoutCodec = time.RFC850 RFC1123 LayoutCodec = time.RFC1123 RFC1123Z LayoutCodec = time.RFC1123Z RFC3339 LayoutCodec = time.RFC3339 RFC3339Date LayoutCodec = "2006-01-02" RFC3339Millis LayoutCodec = "2006-01-02T15:04:05.999Z07:00" RFC3339Nano LayoutCodec = time.RFC3339Nano )
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 TimeDecoderFunc ¶
func (TimeDecoderFunc) UnmarshalTime ¶
func (dec TimeDecoderFunc) UnmarshalTime(s string) (time.Time, error)
type TimeDecoders ¶
type TimeDecoders []TimeDecoder
func (TimeDecoders) UnmarshalTime ¶
func (tds TimeDecoders) UnmarshalTime(s string) (t time.Time, err error)
type TimeEncoder ¶
type TimeEncoderFunc ¶
func (TimeEncoderFunc) MarshalTime ¶
func (enc TimeEncoderFunc) MarshalTime(t time.Time) string
Click to show internal directories.
Click to hide internal directories.