utime

package
v2.29.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MarshalFormat to use for (un-)marshaling time.Time values.
	MarshalFormat = time.RFC3339

	// SQLFormat to use for (un-)marshaling time.Time values with sql drivers.
	SQLFormat = time.RFC3339Nano

	// StartOfWeek is the beginning of the week.
	// This overrides the default time.Sunday and changes behavior of weekday-related functions in this package.
	StartOfWeek = time.Monday
)

Functions

func EndOfWeek

func EndOfWeek(startOfWeek time.Weekday) time.Weekday

EndOfWeek returns the circular-shifted time.Weekday according to the defined StartOfWeek global variable.

func LocalWeekday

func LocalWeekday(startOfWeek, day time.Weekday) int

LocalWeekday returns the circular-shifted weekday number [0; 6] according to the given `startOfWeek`.

Types

type ExclusiveInterval added in v2.27.0

type ExclusiveInterval Interval

ExclusiveInterval is the right-open Interval [StartTime, EndTime). Mimics the interval.Interval proto representation.

func IntervalFromPB added in v2.26.0

func IntervalFromPB(pb *interval.Interval) ExclusiveInterval

IntervalFromPB creates an ExclusiveInterval from the given proto representation.

func (ExclusiveInterval) Contains added in v2.27.0

func (i ExclusiveInterval) Contains(t Time) bool

Contains returns `true` if the given Time t is contained in the ExclusiveInterval.

func (ExclusiveInterval) Inclusive added in v2.27.0

func (i ExclusiveInterval) Inclusive() InclusiveInterval

Inclusive is an equivalent conversion of the ExclusiveInterval to the InclusiveInterval. Conversion precision is time.Nanosecond.

func (ExclusiveInterval) IsValid added in v2.27.0

func (i ExclusiveInterval) IsValid() bool

IsValid checks if the ExclusiveInterval does not overlap itself.

func (ExclusiveInterval) IsZero added in v2.27.0

func (i ExclusiveInterval) IsZero() bool

IsZero is a wrapper for Interval.IsZero().

func (ExclusiveInterval) PB added in v2.27.0

PB converts the ExclusiveInterval to the proto representation.

type InclusiveInterval added in v2.27.0

type InclusiveInterval Interval

InclusiveInterval is the closed Interval [StartTime, EndTime].

func (InclusiveInterval) Contains added in v2.27.0

func (i InclusiveInterval) Contains(t Time) bool

Contains returns `true` if the given Time t is contained in the InclusiveInterval.

func (InclusiveInterval) Exclusive added in v2.27.0

func (i InclusiveInterval) Exclusive() ExclusiveInterval

Exclusive is an equivalent conversion of the InclusiveInterval to the ExclusiveInterval. Conversion precision is time.Nanosecond.

func (InclusiveInterval) IsValid added in v2.27.0

func (i InclusiveInterval) IsValid() bool

IsValid checks if the InclusiveInterval does not overlap itself.

func (InclusiveInterval) IsZero added in v2.27.0

func (i InclusiveInterval) IsZero() bool

IsZero is a wrapper for Interval.IsZero().

func (InclusiveInterval) PB added in v2.27.0

PB converts the InclusiveInterval to the proto representation.

type Interval added in v2.26.0

type Interval struct {
	StartTime Time
	EndTime   Time
}

Interval is a common time interval. Should not be used directly, see InclusiveInterval and ExclusiveInterval instead.

func (Interval) IsZero added in v2.26.2

func (i Interval) IsZero() bool

IsZero checks if the interval both StartTime and EndTime are zero. Implementation is same for both InclusiveInterval and ExclusiveInterval.

type Time

type Time struct{ time.Time }

Time is a wrapper around time.Time with some useful methods.

func Date

func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time

Date constructs a Time from the given date parts.

func FromPB

func FromPB(t *timestamppb.Timestamp) Time

FromPB creates a Time from a protobuf timestamp.

func FromStd

func FromStd(t time.Time) Time

FromStd creates a Time from a standard time.Time.

func Now

func Now() Time

Now returns the current time.

func Unix added in v2.25.0

func Unix(sec, nsec int64) Time

Unix constructs a Time from the given unix epoch time.

func (Time) Add

func (t Time) Add(d time.Duration) Time

Add wraps the standard function.

func (Time) AddDate

func (t Time) AddDate(years, months, days int) Time

AddDate wraps the standard function.

func (Time) After

func (t Time) After(u Time) bool

After wraps the standard function.

func (Time) Before

func (t Time) Before(u Time) bool

Before wraps the standard function.

func (Time) Between

func (t Time) Between(start, end Time) bool

Between returns true if time is between the given bounds.

func (Time) Compare added in v2.26.0

func (t Time) Compare(u Time) int

Compare wraps the standard function.

func (Time) EndOfDay

func (t Time) EndOfDay() Time

EndOfDay returns the end of the day.

func (Time) EndOfMonth

func (t Time) EndOfMonth() Time

EndOfMonth returns the end of the month.

func (Time) EndOfWeek

func (t Time) EndOfWeek() Time

EndOfWeek returns the end of the week according to the defined StartOfWeek global variable.

func (Time) Equal

func (t Time) Equal(u Time) bool

Equal wraps the standard function.

func (Time) In

func (t Time) In(loc *time.Location) Time

In wraps the standard function.

func (Time) Local

func (t Time) Local() Time

Local wraps the standard function.

func (Time) LocalWeekday

func (t Time) LocalWeekday() int

LocalWeekday returns the circular-shifted weekday number [0; 6] according to the defined StartOfWeek global variable.

func (Time) MarshalBinary

func (t Time) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for the defined MarshalFormat global variable.

func (Time) MarshalText

func (t Time) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface for the defined MarshalFormat global variable.

func (Time) PB

func (t Time) PB() *timestamppb.Timestamp

PB converts a Time to a protobuf timestamp.

func (Time) Round

func (t Time) Round(d time.Duration) Time

Round wraps the standard function.

func (*Time) RuMonthName

func (t *Time) RuMonthName() string

RuMonthName returns the name of month in Russian.

func (*Time) RuMonthNamePrepositional

func (t *Time) RuMonthNamePrepositional() string

RuMonthNamePrepositional returns the name of month in Russian in prepositional case.

func (*Time) Scan

func (t *Time) Scan(src any) error

Scan implements the sql.Scanner interface for the defined SQLFormat global variable. Scans the local time.

func (Time) StartOfDay

func (t Time) StartOfDay() Time

StartOfDay returns the start of the day.

func (Time) StartOfMonth

func (t Time) StartOfMonth() Time

StartOfMonth returns the start of the month.

func (Time) StartOfWeek

func (t Time) StartOfWeek() Time

StartOfWeek returns the start of the week according to the defined StartOfWeek global variable.

func (Time) Std

func (t Time) Std() time.Time

Std converts a Time to a standard time.Time.

func (Time) Sub

func (t Time) Sub(u Time) time.Duration

Sub wraps the standard function.

func (Time) Truncate

func (t Time) Truncate(d time.Duration) Time

Truncate wraps the standard function.

func (Time) UTC

func (t Time) UTC() Time

UTC wraps the standard function.

func (*Time) UnmarshalBinary

func (t *Time) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. Returns the local time.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for the defined MarshalFormat global variable. Returns the local time.

func (*Time) UnmarshalText

func (t *Time) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for the defined MarshalFormat global variable. Returns the local time.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements the driver.Valuer interface for the defined SQLFormat global variable.

func (Time) ZoneBounds

func (t Time) ZoneBounds() (start, end Time)

ZoneBounds wraps the standard function.

Jump to

Keyboard shortcuts

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