Documentation ¶
Overview ¶
Package timeutil includes helpers for working with timestamps.
Index ¶
- Constants
- Variables
- func BeginningOfMonth(t time.Time) time.Time
- func DiffHours(t1, t2 time.Time) (hours int)
- func EndOfMonth(t time.Time) time.Time
- func FormatDuration(d time.Duration) string
- func FromMilliseconds(millis float64) time.Duration
- func Max(times ...time.Time) time.Time
- func Milliseconds(d time.Duration) float64
- func Min(times ...time.Time) (min time.Time)
- func MinMax(times ...time.Time) (min time.Time, max time.Time)
- func ParseTime(timeStr string, timeFormats ...string) (output time.Time, err error)
- func ParseTimeDefaults(timeStr string) (time.Time, error)
- func ToFloat64(t time.Time) float64
- func UnixMilliseconds(t time.Time) float64
- type Ascending
- type Descending
Constants ¶
const ( SecondsPerHour = 60 * 60 SecondsPerDay = 60 * 60 * 24 )
SecondsPerXYZ
const ( TimeFormatCompleteDate24TimeUTC = "2006-01-02 15:04Z07:00" TimeFormatCompleteDate24TimeUTCSlash = "2006/01/02 15:04Z07:00" TimeFormatCompleteDate = "2006-01-02" TimeFormatCompleteDateSlash = "2006/01/02" TimeFormatKitchen24 = "15:04" )
Extra time formats
Variables ¶
var ( // DefaultTimeFormats are the default time formats used in parsing. // They are ordered from _most_ specific to least specific. DefaultTimeFormats = []string{ time.RFC3339Nano, time.RFC3339, TimeFormatCompleteDate24TimeUTC, TimeFormatCompleteDate24TimeUTCSlash, TimeFormatCompleteDate, TimeFormatCompleteDateSlash, TimeFormatKitchen24, time.Kitchen, } )
Functions ¶
func BeginningOfMonth ¶
BeginningOfMonth returns the date that represents the last day of the month for a given time.
func EndOfMonth ¶
EndOfMonth returns the date that represents the last day of the month for a given time.
func FormatDuration ¶
FormatDuration formats a duration to it's nearest major increment.
func FromMilliseconds ¶
FromMilliseconds returns a duration from a given float64 millis value.
func Milliseconds ¶
Milliseconds returns a duration as milliseconds.
func ParseTimeDefaults ¶
ParseTimeDefaults parses a time string with the default time formats.
func UnixMilliseconds ¶
UnixMilliseconds returns the time in unix (seconds) format with a floating point remainder for subsecond fraction.
Types ¶
type Descending ¶
Descending sorts a given list of times ascending, or min to max.