durations

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2022 License: BSD-3-Clause Imports: 5 Imported by: 1

README

GoDoc Go Report Card Build Status tag release

durations

some helpful time/duration funcs

This package is mostly sugar. If you want to do duration math with properly typed ints (think return values from other funcs) you have to cast that int to a time.Duration (int64). This package makes the invocations a bit more fluent and hides the casts from view.

Documentation

Index

Constants

View Source
const FmtYearWeek = "%d%02d"

FmtYearWeek is the format string used by fmt.Println to create a 6 digit string of the yearweek ('YYYYWW'). e.g. `y, w := t.ISOWeek(); fmt.Sprintf(FmtYearWeek, y, w)`

View Source
const (
	MySQLDateTime = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func GetTimeNow added in v0.1.0

func GetTimeNow() time.Time

GetTimeNow fulfills GetTime and is a function that return the current time

func GetTimeNowUTC added in v0.1.0

func GetTimeNowUTC() time.Time

GetTimeNowUTC fulfills GetTime and is a function that return the current UTC time

func Hours

func Hours(n int) time.Duration

Hours returns a duration based on ints. time.Duration is an int64, but there are times when the return value of funcs or other operations aren't int64. This is pure sugar for casting an int to a time.Duration before doing the math.

func Microseconds

func Microseconds(n int) time.Duration

Microseconds returns a duration based on ints. time.Duration is an int64, but there are times when the return value of funcs or other operations aren't int64. This is pure sugar for casting an int to a time.Duration before doing the math.

func Milliseconds

func Milliseconds(n int) time.Duration

Milliseconds returns a duration based on ints. time.Duration is an int64, but there are times when the return value of funcs or other operations aren't int64. This is pure sugar for casting an int to a time.Duration before doing the math.

func Minutes

func Minutes(n int) time.Duration

Minutes returns a duration based on ints. time.Duration is an int64, but there are times when the return value of funcs or other operations aren't int64. This is pure sugar for casting an int to a time.Duration before doing the math.

func Nanoseconds

func Nanoseconds(n int) time.Duration

Nanoseconds returns a duration based on ints. time.Duration is an int64, but there are times when the return value of funcs or other operations aren't int64. This is pure sugar for casting an int to a time.Duration before doing the math.

func Seconds

func Seconds(n int) time.Duration

Seconds returns a duration based on ints. time.Duration is an int64, but there are times when the return value of funcs or other operations aren't int64. This is pure sugar for casting an int to a time.Duration before doing the math.

func Weekof

func Weekof(date time.Time) time.Time

Weekof returns the time.Time anchored to the Monday of the week of the given time.Time. This is useful for communicating ISO 8601 weeks. See https://golang.org/pkg/time/#Time.ISOWeek

func YearWeek added in v0.2.0

func YearWeek(date time.Time) string

YearWeek give you the YearWeek (YYYYWW) of the given date

Types

type FloatTime added in v0.2.0

type FloatTime struct {
	Precision time.Duration
	time.Time
}

FloatTime allows the JSON Un/Marshaling of timestamps sent as floats into time.Time

func NewFloatTime added in v0.2.0

func NewFloatTime() *FloatTime

NewFloatTime allows the JSON Un/Marshaling of timestamps sent as floats into time.Time

func (*FloatTime) MarshalJSON added in v0.2.0

func (f *FloatTime) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the json.Marshaler interface

func (*FloatTime) Unix added in v0.2.0

func (f *FloatTime) Unix() int64

Unix is shorthand for getting the regular unix timestamp from a FloatTime

func (*FloatTime) UnmarshalJSON added in v0.2.0

func (f *FloatTime) UnmarshalJSON(b []byte) error

MarshalJSON satisfies the json.Unmarshaler interface

type GetTime added in v0.1.0

type GetTime func() time.Time

GetTime is a function that returns a time.Time; it is used here exclusively to inject a specific time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL