util

package
v0.1.6-0...-5c25bcb Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeWithTrailingZeroMsec

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

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.

func NewTime

NewTime creates TimeWithTrailingZeroMsec without zero sub-second precision. It functions as a normal time.Time object.

func NewTimeWithTrailingZeroMsec

func NewTimeWithTrailingZeroMsec(t time.Time, trailingZerosMsecCount int) *TimeWithTrailingZeroMsec

NewTimeWithTrailingZeroMsec creates TimeWithTrailingZeroMsec with certain zero sub-second precision.

func ParseTimeWithTrailingZeroMsec

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

ParseTimeWithTrailingZeroMsec parses a formatted string and returns the time value it represents. In case of zero sub-second precision, it's kept and applied when e.g. unmarshal the time to JSON.

func (TimeWithTrailingZeroMsec) GetFormat

func (tm TimeWithTrailingZeroMsec) GetFormat() string

GetFormat returns customized time.RFC3339Nano with trailing zeros included in case of zero sub-second precision presence. Otherwise it returns time.RFC3339Nano.

func (TimeWithTrailingZeroMsec) MarshalJSON

func (tm TimeWithTrailingZeroMsec) 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 (*TimeWithTrailingZeroMsec) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format. In case of zero sub-second precision, it's kept and applied when e.g. unmarshal the time to JSON.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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