Documentation ¶
Overview ¶
Package timex extends the standard package time.
Index ¶
- Constants
- Variables
- func DStr(d time.Duration) string
- func DT(t time.Time) string
- func ISO(t time.Time) string
- func ISODefault(t time.Time, defaultVal string) string
- func InfTime() time.Time
- func NsStr(nanoseconds int64) string
- func ParseDuration(str string) (time.Duration, error)
- func ParseTime(str string) (_ time.Time, ok bool)
- func Relative(t time.Time, days int) time.Time
- func SameDate(t1, t2 time.Time) bool
- func SameHour(t1, t2 time.Time) bool
- func SameMinuteSecond(t1, t2 time.Time) bool
- func SecStr(seconds int32) string
- func YMD(t time.Time) string
Constants ¶
const ( MinuteSec = 60 // MinuteSec = number of seconds in one minute. HourSec = 3600 // HourSec = number of seconds in one hour. DaySec = 24 * HourSec // DaySec = number of seconds in one day. WeekSec = 7 * DaySec // WeekSec = number of seconds in one week. MonthSec = YearSec / 12 // MonthSec = number of seconds in one month. YearSec = 31556952 // SecondsInOneYear is the average of the the number of seconds in one year. MicrosecondNs = 1000 // Number of nanoseconds in 1 microsecond MillisecondNs = 1000 * MicrosecondNs // Number of nanoseconds in 1 millisecond SecondNs = 1000 * MillisecondNs // Number of nanoseconds in 1 second MinuteNs = SecondNs * MinuteSec // Number of nanoseconds in 1 minute HourNs = SecondNs * HourSec // Number of nanoseconds in 1 hour DayNs = SecondNs * DaySec // Number of nanoseconds in 1 day WeekNs = SecondNs * WeekSec // Number of nanoseconds in 1 week MonthNs = SecondNs * MonthSec // Number of nanoseconds in 1 month YearNs = SecondNs * YearSec // Number of nanoseconds in 1 year Nanosecond = time.Nanosecond // Nanosecond = one billionth of a second Microsecond = time.Microsecond // Microsecond = 1000 nanoseconds Millisecond = time.Millisecond // Millisecond = 1000 microseconds Second = time.Second // Second = 1000 milliseconds Minute = time.Minute // Minute = 60 seconds (no leap seconds) Hour = time.Hour // Hour = 60 minutes Day = Second * DaySec // Day = 24 hours (ignoring daylight savings effects) Week = Second * WeekSec // Week = 7 days Month = Second * MonthSec // Month = one twelfth of a year (2629746 seconds, about 30.4 days) Year = Second * YearSec // Year = 31556952 seconds (average considering leap years, about 365.24 days) )
Durations in nanoseconds from 1 nanosecond to 1 year.
const ( DateOnly = "2006-01-02" TimeOnly = "15:04:05" )
const Inf = "inf"
const Infinite = math.MaxInt32 - 1
Variables ¶
var ( // ErrMissingTimeAndUnit indicates time parser was expecting at least a time value followed by a time unit. ErrMissingTimeAndUnit = errors.New("time: expecting a value followed by a unit") // ErrExpectingInt indicates time parser was expecting one or more successive numbers. ErrExpectingInt = errors.New("time: expecting [0-9]*") // ErrNoDigits indicates time parser was expecting at least one number, but none. ErrNoDigits = errors.New("time: no digits (e.g. '.s' or '-.s')") // ErrNoUnit indicates time parser was expecting a time unit, but none. ErrNoUnit = errors.New("time: missing unit (ns, us, ms, s, m, h, d, w, mo, y)") // ErrUnknownUnit indicates time parser did not recognized the time unit. ErrUnknownUnit = errors.New("time: unknown unit (valid: ns, us, ms, s, m, h, d, w, mo, y)") // ErrOverflowTime indicates time parser is computing a time value larger that 63 bits. ErrOverflowTime = errors.New("time: time value overflow 63 bits") )
Functions ¶
func DStr ¶
DStr stringifies the duration in number of days, seconds, microseconds and nanoseconds. DStr truncates the string depending on the precision.
func DT ¶
DT stringifies a time using the layout "2006-01-02.15:04:05". DT is used in debug logs when retrieving data from InfluxDB.
func ISO ¶
ISO stringifies a time using the layout RFC3339Nano (ISO 8601). Used in JSON response for /{topic} endpoints.
func ISODefault ¶
ISODefault uses the ISO-8601 (RFC-3339) format with the nanosecond precision, but defaults to defaultVal when t.IsZero().
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d", "w", "mo" (month) and "y".
func SameMinuteSecond ¶
SameMinuteSecond returns true if t1 and t2 have same minute and second.
Types ¶
This section is empty.