time

package
v0.0.0-...-64dd8ac Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeWithTrailingZeroMsec deprecated

type TimeWithTrailingZeroMsec = TimeWrapper // nolint:golint

TimeWithTrailingZeroMsec overrides marshalling of time.Time. It keeps a format of initial unmarshalling in case when date has zero a fractional second (e.g. ".000"). For example, time.Time marshals 2018-03-15T00:00:00.000Z to 2018-03-15T00:00:00Z while TimeWithTrailingZeroMsec marshals to the initial 2018-03-15T00:00:00.000Z value.

Deprecated: use TimeWrapper instead.

type TimeWrapper

type TimeWrapper struct {
	time.Time
	// contains filtered or unexported fields
}

TimeWrapper overrides marshalling of time.Time. If a TimeWrapper is created from a time string, or unmarshalled from JSON, it saves the string literal, which it uses when marshalling. If a TimeWrapper is created using NewTime or a struct literal, it marshals with the default time.RFC3339 format.

func NewTime

func NewTime(t time.Time) *TimeWrapper

NewTime creates a TimeWrapper wrapped around the given time.Time. It functions as a normal time.Time object.

func NewTimeWithTrailingZeroMsec deprecated

func NewTimeWithTrailingZeroMsec(t time.Time, _ int) *TimeWrapper

NewTimeWithTrailingZeroMsec creates a TimeWrapper wrapped around the given time.Time.

Deprecated: use NewTime instead. For sub-zero precision, use ParseTimeWrapper on a string with the desired precision.

func ParseTimeWithTrailingZeroMsec deprecated

func ParseTimeWithTrailingZeroMsec(timeStr string) (*TimeWrapper, error)

ParseTimeWithTrailingZeroMsec parses a formatted string and returns the time value it represents.

Deprecated: use ParseTimeWrapper instead.

func ParseTimeWrapper

func ParseTimeWrapper(timeStr string) (*TimeWrapper, error)

ParseTimeWrapper parses a formatted string and returns the time value it represents.

func (*TimeWrapper) FormatToString

func (tm *TimeWrapper) FormatToString() string

FormatToString returns the string representation of this TimeWrapper. If it was unmarshalled from a JSON object, this returns the original string it was parsed from. Otherwise, this returns the time in the time.RFC3339Nano format.

func (TimeWrapper) MarshalJSON

func (tm TimeWrapper) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present. In case of zero sub-second precision presence, trailing zeros are included.

func (*TimeWrapper) UnmarshalJSON

func (tm *TimeWrapper) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format. The source string value is saved, and used if this is marshalled back to JSON.

Jump to

Keyboard shortcuts

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