clock

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Since

func Since(c Clock) time.Duration

Since returns duration from u until now

func Until

func Until(c Clock) time.Duration

Until returns duration from now until c

Types

type Clock

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

Clock represents a time within a day (hour, minute, second)

func MustParse

func MustParse(v string) Clock

MustParse parses a string and panics if parsing fails

func New

func New(hour, min, sec int) Clock

New constructs a Clock from hour, minute, second. Values can exceed normal ranges; they are normalized modulo 24 hours.

func Now

func Now() Clock

Now returns the current local time as a Clock

func Parse

func Parse(v string) (Clock, error)

Parse parses a string into a Clock using supported layouts

func ParseTime

func ParseTime(t time.Time) Clock

ParseTime converts a time.Time into a Clock (hour, minute, second)

func (Clock) Add

func (c Clock) Add(d time.Duration) Clock

Add adds a duration to the Clock and returns a new Clock Duration is truncated to seconds

func (Clock) After

func (c Clock) After(u Clock) bool

After returns true if c is after u

func (Clock) Before

func (c Clock) Before(u Clock) bool

Before returns true if c is before u

func (Clock) Clock

func (c Clock) Clock() (hour, min, sec int)

Clock returns hour, minute, second components of the Clock

func (Clock) Compare

func (c Clock) Compare(u Clock) int

Compare compares c with u and returns -1,0,1

func (Clock) Equal

func (c Clock) Equal(u Clock) bool

Equal returns true if c equals u

func (Clock) Hour

func (c Clock) Hour() int

Hour returns the hour of the Clock

func (Clock) IsValid added in v0.1.75

func (c Clock) IsValid() bool

IsValid returns true if the Clock is not the zero/invalid value

func (Clock) MarshalText

func (c Clock) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Clock) Minute

func (c Clock) Minute() int

Minute returns the minute of the Clock

func (Clock) Second

func (c Clock) Second() int

Second returns the second of the Clock

func (Clock) Seconds

func (c Clock) Seconds() uint64

Seconds returns the number of seconds

func (Clock) Since

func (c Clock) Since(u Clock) time.Duration

Since returns the duration from u until c (c - u, wrapped around 24h)

func (Clock) String

func (c Clock) String() string

String returns the Clock as a string "H:MM:SS", or "invalid" if zero

func (Clock) Sub

func (c Clock) Sub(u Clock) time.Duration

Sub returns the duration between c and u (c - u)

func (Clock) Time

func (c Clock) Time() time.Time

Time converts the Clock into a time.Time on the Unix epoch date

func (*Clock) UnmarshalText

func (c *Clock) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

func (Clock) Until

func (c Clock) Until(u Clock) time.Duration

Until returns the duration from c until u (always non-negative, wraps around 24h)

Jump to

Keyboard shortcuts

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