timestamp

package
v0.0.0-...-6116d98 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Timestamp

type Timestamp struct {
	Time  time.Time
	Valid bool
}

Timestamp wraps a time.Time in a struct with a Valid bool so we can safely handle NULL values.

func Must

func Must(t Timestamp, err error) Timestamp

Must panics if err != nil.

func New

func New(t time.Time) Timestamp

New returns a Timestamp with the provided time.Time and Valid set to true.

func NewFromPtr

func NewFromPtr(t *time.Time) Timestamp

NewFromPtr wraps New to ensure that the provided *time.Time is not nil before deferencing it and creating a new Timestamp.

func Now

func Now() Timestamp

Now wraps time.Now with a Timestamp.

func Parse

func Parse(layout string, val string) (Timestamp, error)

Parse wraps time.Parse. It'll return an error if the underlying call to time.Parse returns an error.

func ParseInLocation

func ParseInLocation(layout string, val string, loc *time.Location) (Timestamp, error)

ParseInLocation wraps time.ParseInLocation. It'll return an error if the underlying call to time.ParseInLocation returns an error.

func (*Timestamp) IsNull

func (t *Timestamp) IsNull() bool

IsNull returns true if Timestamp.Valid == false.

func (Timestamp) MarshalJSON

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

MarshalJSON implements json.Marshaler. If the Timestamp is valid, it redirects to the time.Time's JSON marshaler; if it is not valid, it returns json.Marshal(nil).

func (*Timestamp) Scan

func (t *Timestamp) Scan(in interface{}) error

Scan implements driver.Scanner.

func (Timestamp) String

func (t Timestamp) String() string

String implements fmt.Stringer.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler. If the incoming []byte == "null", it'll return a Timestamp with Valid set to false. Otherwise, it'll attempt to parse the time.Time and return a Timestamp with Valid set to true if it's able.

func (Timestamp) Value

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

Value implements driver.Valuer.

Jump to

Keyboard shortcuts

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