daytime

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFormat = errors.New("invalid format")
	ErrInvalidValue  = errors.New("invalid value")
)

Common error messages.

Functions

func Midnight

func Midnight(t time.Time) time.Time

Midnight returns a new time that represents midnight at t.

Types

type DayTime

type DayTime [2]int

DayTime represents a HH:MM time during the day.

func ParseDayTime

func ParseDayTime(str string) (DayTime, error)

ParseDayTime parses a HH:MM time specification.

func (DayTime) AsDuration

func (dt DayTime) AsDuration() time.Duration

AsDuration returns dt as a duration from midnight (00:00).

func (DayTime) AsMinutes

func (dt DayTime) AsMinutes() int

AsMinutes returns dt as a absolute number of minutes starting from midnight (00:00).

func (DayTime) At

func (dt DayTime) At(t time.Time, loc *time.Location) time.Time

At returns a new time.Time that represents dt at t.

func (DayTime) Equals

func (dt DayTime) Equals(other DayTime) bool

func (DayTime) MarshalJSON

func (dr DayTime) MarshalJSON() ([]byte, error)

func (DayTime) String

func (dt DayTime) String() string

func (DayTime) UnmarshalJSON

func (dt DayTime) UnmarshalJSON(blob []byte) error

type Range

type Range struct {
	From DayTime `json:"from"`
	To   DayTime `json:"to"`
}

Range represents a range at any day.

func ParseRange

func ParseRange(str string) (r Range, err error)

ParseRange parses a day time range in the format of "HH:MM - HH:MM" and returns the result.

func (*Range) At

func (dtr *Range) At(d time.Time, loc *time.Location) *TimeRange

At returns a the TimeRange that results when adding dtr to d.

func (*Range) String

func (dtr *Range) String() string

type TimeRange

type TimeRange struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

TimeRange defines a range in time that may start and end at different dates.

func (*TimeRange) Covers

func (tr *TimeRange) Covers(t time.Time) bool

Covers returns true if t is covered by tr.

Jump to

Keyboard shortcuts

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