date

package
v0.0.0-...-86e9f11 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package date implements optimized date-parsing routines specific to the date formats that we support.

Currently, only RFC3339Nano dates are supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration struct {
	Year, Month, Day int
}

A Duration represents a calendar duration with year, month, and day components. This is intended to be used to represent expiration times on a granularity of days. Use time.Duration to represent durations smaller than one day.

func ParseDuration

func ParseDuration(s string) (Duration, bool)

ParseDuration parses a duration string.

func (Duration) Add

func (d Duration) Add(t Time) Time

Add adds d to t.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Duration) String

func (d Duration) String() string

String implements io.Stringer

func (Duration) Sub

func (d Duration) Sub(t Time) Time

Sub subtracts d from t.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler

func (Duration) Zero

func (d Duration) Zero() bool

Zero returns whether d is equal to the zero value of a Duration.

type Time

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

A Time represents a date and time with a nanosecond component. This representation allows for faster extraction of date components than time.Time, at the cost of slower conversion to Unix times.

This representation cannot store years below 0 or above 16,383. Years falling outside that range will be truncated to fit within that range.

func Date

func Date(year, month, day, hour, min, sec, ns int) Time

Date constructs a Time from components. Values of month, day, hour, min, sec, and ns outside their usual ranges will be normalized. Values for year outside of the range [0, 16383] will be truncated to fit within that range.

func FromTime

func FromTime(t time.Time) Time

FromTime returns a Time equivalent to t.

func Now

func Now() Time

Now returns the current time.

func Parse

func Parse(data []byte) (Time, bool)

Parse parses a date string from data and returns the associated time and true, or the zero time value and false if the buffer did not contain a recognzied date format.

Parse attempts to recognize strings that (approximately) match RFC3339 timestamps with optional nanosecond precision and timezone/offset components. Parse will automatically ignore leading and trailing whitespace as long as the middle characters of data are unambiguously a timestamp.

func Unix

func Unix(sec, ns int64) Time

Unix returns a Time from the given Unix time in seconds and nanoseconds.

func UnixMicro

func UnixMicro(us int64) Time

UnixMicro returns a Time from the given Unix time in microseconds.

func (Time) Add

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

Add adds d to t.

func (Time) After

func (t Time) After(t2 Time) bool

After returns whether t is after t2.

func (Time) AppendRFC3339Nano

func (t Time) AppendRFC3339Nano(b []byte) []byte

AppendRFC3339Nano appends t formatted as an RFC3339 compliant string (including nanoseconds) to b. This method is functionally equivalent to:

t.Time().AppendFormat(b, time.RFC3339Nano)

func (Time) Before

func (t Time) Before(t2 Time) bool

Before returns whether t is before t2.

func (Time) Day

func (t Time) Day() int

Day returns the day component of t.

func (Time) Equal

func (t Time) Equal(t2 Time) bool

Equal returns whether t == t2.

func (Time) Hour

func (t Time) Hour() int

Hour returns the hour component of t.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero returns whether t is the zero value, corresponding to January 1st of year zero.

func (Time) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Time) Minute

func (t Time) Minute() int

Minute returns the minute component of t.

func (Time) Month

func (t Time) Month() int

Month returns the month component of t.

func (Time) Nanosecond

func (t Time) Nanosecond() int

Nanosecond returns the nanosecond component of t.

func (Time) Quarter

func (t Time) Quarter() int

func (Time) Round

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

Round rounds t to the nearest multiple of d.

func (Time) Second

func (t Time) Second() int

Second returns the second component of t.

func (Time) String

func (t Time) String() string

String implements io.Stringer. The returned string is meant to be used for debugging purposes.

func (Time) Time

func (t Time) Time() time.Time

Time returns t as a time.Time.

func (Time) Truncate

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

Truncate rounds t down to a multiple of d.

func (Time) Unix

func (t Time) Unix() int64

Unix returns t as the number of seconds since the Unix epoch.

func (Time) UnixMicro

func (t Time) UnixMicro() int64

UnixMicro returns t as the number of microseconds since the Unix epoch.

func (Time) UnixNano

func (t Time) UnixNano() int64

UnixNano returns t as the number of nanoseconds since the Unix epoch.

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (Time) Year

func (t Time) Year() int

Year returns the year component of t.

Jump to

Keyboard shortcuts

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