times

package
v0.0.0-...-889a765 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClockTimezone

func GetClockTimezone(c Clock) *time.Location

GetClockTimezone returns timezone of given clock. It is useful for wire dependency injection.

func LoadLocation

func LoadLocation(name string) (*time.Location, error)

LoadLocation loads the timezone with the given name.

func Local

func Local() (*time.Location, error)

Local returns the local timezone with full name. In comparison to time.Local, this function returns the full name of the timezone. Example:

time.Local.String() -> "Local"
Local().String() -> "Europe/Berlin" (or whatever your local timezone is)

This is useful in cases where a session is timezone oriented.

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time

	// Unix returns the current time in unix format.
	Unix() int64

	// UnixNano returns the current time in unix format.
	UnixNano() int64

	// Location returns the current location.
	Location() *time.Location

	// Since returns the time elapsed since t.
	Since(t time.Time) time.Duration

	// Until returns the time until t.
	Until(t time.Time) time.Duration
}

Clock is an interface that gives access to the current time.

type ZonedClock

type ZonedClock struct {
	// contains filtered or unexported fields
}

ZonedClock is the default implementation of the Clock interface.

func NewLocalClock

func NewLocalClock() (*ZonedClock, error)

NewLocalClock creates a new ZonedClock.

func NewZonedClock

func NewZonedClock(loc *time.Location) *ZonedClock

NewZonedClock creates a new ZonedClock.

func (*ZonedClock) Location

func (c *ZonedClock) Location() *time.Location

Location returns the current location.

func (*ZonedClock) Now

func (c *ZonedClock) Now() time.Time

Now returns the current time.

func (*ZonedClock) Since

func (c *ZonedClock) Since(t time.Time) time.Duration

Since returns the time elapsed since t.

func (*ZonedClock) Unix

func (c *ZonedClock) Unix() int64

Unix returns the current time in unix format.

func (*ZonedClock) UnixNano

func (c *ZonedClock) UnixNano() int64

UnixNano returns the current time in unix format.

func (*ZonedClock) Until

func (c *ZonedClock) Until(t time.Time) time.Duration

Until returns the time until t.

Directories

Path Synopsis
internal
tzlocal
Code generated by tzlocal/update_tzmapping.go DO NOT EDIT.
Code generated by tzlocal/update_tzmapping.go DO NOT EDIT.

Jump to

Keyboard shortcuts

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