Package adds some time types for easier work, serialize and deserialize them and some helper functions. Types satisfy the fmt.GoStringer
and fmt.Stringer
interfaces for easier debugging and sql.Scanner
and sql.Valuer
to allow to use this types with the SQL drivers.
The type implements sql.Scanner
and json.Unmarshaler
and tries to read the time value in two formats: ISO8601 for times without date
and ISO8601 with micro precision without date.
// Clock is a wrapper for time.time to allow parsing datetime stamp with time only in
// ISO 8601 format, like "15:04:05"
type Clock time.Time
// NewClock returns the Clock in the given location with given hours, minutes and secs
func NewClock(h, m, s int, loc *time.Location) Clock
// NewUTCClock returns new clock with given hours, minutes and seconds in the UTC location
func NewUTCClock(h, m, s int) Clock
// Duration is a wrapper of time.Duration, that allows to marshal and unmarshal time in RFC3339 format
type Duration time.Duration
// ParseWeekday parses a weekday from a string and, if it's
// can't be parsed, returns
func ParseWeekday(s string) (time.Weekday, error)
// Parsing errors
var (
ErrInvalidClock = errors.New("timetype: invalid clock")
ErrInvalidDuration = errors.New("timetype: invalid duration")
ErrInvalidWeekday = errors.New("timetype: invalid weekday")
ErrUnknownFormat = errors.New("timetype: unknown format")
)
// Templates to parse clocks
const (
ISO8601Clock = "15:04:05"
ISO8601ClockMicro = "15:04:05.000000"
)