Documentation ¶
Overview ¶
Package dur is a package to convert string duration and time specifications to numbers of seconds and to unix timestamps. It aims to support the full specification as outlined in http://graphite.readthedocs.io/en/latest/render_api.html#from-until which incorporates the formats defined by `at`.
this package works with the following shorthands: Duration : unsigned (positive) number of seconds NDuration: like Duration, but non-zero.
Index ¶
- func FormatDuration(seconds uint32) string
- func IsTime(s string) bool
- func MustParseDateTime(s string, loc *time.Location, now time.Time, def uint32) uint32
- func MustParseDuration(desc, s string) uint32
- func MustParseNDuration(desc, s string) uint32
- func ParseDateTime(s string, loc *time.Location, now time.Time, def uint32) (uint32, error)
- func ParseDuration(s string) (uint32, error)
- func ParseNDuration(s string) (uint32, error)
- func ParseTime(s string) (hour, minute int, err error)
- func RewindToWeekday(t time.Time, day time.Weekday) time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration takes a number of seconds and returns a minimal string represention that can be parsed by ParseDuration(). Due to its ambiguity and length, we don't use "month" units in the returned value.
func MustParseDateTime ¶
MustParseDateTime parses a format string to a unix timestamp, or panics otherwise
func MustParseDuration ¶
MustParseDuration parses a format string to a number of seconds, or panics otherwise unit defaults to s if not specified
func MustParseNDuration ¶
MustParseNDuration parses a format string to a non-zero number of seconds, or panics otherwise unit defaults to s if not specified
func ParseDateTime ¶
ParseDateTime parses a format string to a unix timestamp, or error otherwise. 'loc' is the timezone to use for interpretation (when applicable) 'now' is a reference, in case a relative specification is given. 'def' is a default in case an empty specification is given.
func ParseDuration ¶
ParseDuration parses a format string to a number of seconds, or error otherwise valid units are s/sec/secs/second/seconds, m/min/mins/minute/minutes, h/hour/hours, d/day/days, w/week/weeks, mon/month/months, y/year/years unit defaults to s if not specified
func ParseNDuration ¶
ParseNDuration parses a format string to a non-zero number of seconds, or error otherwise unit defaults to s if not specified
Types ¶
This section is empty.