datetime

package
v0.0.0-...-88db892 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DBFormat is the date format used to store date in mysql db
	DBFormat = "2006-01-02 15:04:05"
)
View Source
const DateOnlyFormat = "2006-01-02"

DateOnlyFormat defines the format to store/parse the time for DateOnly struct

View Source
const TimeOnlyFormat = "15:04" //"15:04:05.999999999"

TimeOnlyFormat defines the format to store/parse the time for TimeOnly struct

Variables

This section is empty.

Functions

func Bod

func Bod(t time.Time) time.Time

Bod returns the beginning of day time within a particular timezone http://stackoverflow.com/questions/25254443/return-local-beginning-of-day-time-object-in-go

func GetTimeAndWeekday

func GetTimeAndWeekday(timeDateTime time.Time) (time.Time, uint)

GetTimeAndWeekday converts the time in seconds to a hh:mm only and its weekday bitmask

func IsBetween

func IsBetween(dateTime, startTime, endTime time.Time) bool

IsBetween checks whether startTime <= dateTime < endTime

func IsExpired

func IsExpired(dateTime time.Time, seconds int) bool

IsExpired check whether the time is expired after <seconds> second(s)

func IsScheduled

func IsScheduled(t time.Time, d time.Duration) bool

IsScheduled returns true if t falls on a multiple of d. If d is 15 minutes, then IsScheduled returns true if t falls on any quarter of the hour, false otherwise.

func IsWeekday

func IsWeekday(t time.Time) bool

IsWeekday returns true if t is a weekday

func Max

func Max(a time.Time, b time.Time) time.Time

Max returns the later time.

func Millisecond

func Millisecond(input time.Time) int64

Millisecond returns number of milliseconds elapsed since January 1, 1970 UTC,until the input time. NOTE: a date before the year 1678 or after 2262 cannot be represented correctly

func NextQuarterOfHour

func NextQuarterOfHour(t time.Time) time.Time

NextQuarterOfHour returns the next quarter of an hour from t. if t is already on the quarter, then return t.

func NowInMS

func NowInMS() int64

NowInMS returns number of million seconds elapsed since January 1, 1970 UTC till now NOTE: a date before the year 1678 or after 2262 cannot be represented correctly

func RoundUp

func RoundUp(t time.Time, d time.Duration) time.Time

RoundUp returns the result of rounding t to the next multiple of d (since the zero time). RoundUp returns t unchanged if d <= 0 or t is a multiple of d.

func UnixWithMS

func UnixWithMS(ts int64) time.Time

UnixWithMS returns the local Time corresponding to the given Unix milliseconds since January 1, 1970 UTC

Types

type DateOnly

type DateOnly time.Time

DateOnly type wraps json marshal and unmarshal operations on time.Time type using DateOnly format

func DateOnlyFromString

func DateOnlyFromString(ctx context.Context, input string) DateOnly

DateOnlyFromString creates DateOnly from a string

func (*DateOnly) GobDecode

func (t *DateOnly) GobDecode(data []byte) error

GobDecode implements the GOB interface

func (*DateOnly) GobEncode

func (t *DateOnly) GobEncode() ([]byte, error)

GobEncode implements the GOB interface

func (*DateOnly) IsEmpty

func (t *DateOnly) IsEmpty() bool

IsEmpty tests whether DateOnly is zero value (0001-01-01 00:00:00),

func (*DateOnly) MarshalJSON

func (t *DateOnly) MarshalJSON() ([]byte, error)

MarshalJSON marshals a DateOnly type to json

func (*DateOnly) ParseString

func (t *DateOnly) ParseString(input string) error

ParseString parses a string and modifies the receiver

func (*DateOnly) Scan

func (t *DateOnly) Scan(value interface{}) error

Scan implements the database/sql scanner interface

func (*DateOnly) String

func (t *DateOnly) String() string

String returns the string representation of DateOnly date value

func (*DateOnly) UnmarshalJSON

func (t *DateOnly) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals DateOnly type from json

func (DateOnly) Value

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

Value implements the database/sql valuer interface

type Duration

type Duration struct {
	time.Duration
}

Duration is struct which wraps time.Duration and implements json.Unmarshaler and json.Marshaler copied from https://github.com/golang/go/issues/4712

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() (b []byte, err error)

MarshalJSON implements json.Marshaler interface

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshaler interface

type RFC3339

type RFC3339 time.Time

RFC3339 type wraps json marshal and unmarshal operations on time.Time type using RFC3339 format

func FromString

func FromString(ctx context.Context, input string) RFC3339

FromString create RFC3339 from string

func Now

func Now() RFC3339

Now returns the current local time.

func (RFC3339) EncodeValues

func (t RFC3339) EncodeValues(key string, v *url.Values) error

EncodeValues allows us to use go-querystring and encode grabtime

func (RFC3339) Equal

func (t RFC3339) Equal(u RFC3339) bool

Equal allow go-cmp to test equality

func (*RFC3339) GobDecode

func (t *RFC3339) GobDecode(data []byte) error

GobDecode implements the GOB interface

func (*RFC3339) GobEncode

func (t *RFC3339) GobEncode() ([]byte, error)

GobEncode implements the GOB interface

func (*RFC3339) IsEmpty

func (t *RFC3339) IsEmpty() bool

IsEmpty test whether RFC3339 is zero value (0001-01-01 00:00:00),

func (*RFC3339) IsInvalid

func (t *RFC3339) IsInvalid() bool

IsInvalid tests whether RFC3339 is valid value

func (RFC3339) MarshalJSON

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

MarshalJSON marshal RFC3339 type to json

func (*RFC3339) ParseString

func (t *RFC3339) ParseString(input string) error

ParseString parse string and modify receiver

func (*RFC3339) Scan

func (t *RFC3339) Scan(src interface{}) error

Scan implements the sql.Scan interface

func (RFC3339) String

func (t RFC3339) String() string

String returns the string representation of RFC3339 time value

func (*RFC3339) UnmarshalJSON

func (t *RFC3339) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshal RFC3339 from json

func (RFC3339) Value

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

Value implements sql/driver/Valuer interface in order to convert from this type to db storage

type TimeOnly

type TimeOnly time.Time

TimeOnly type wraps json marshal and unmarshal operations on time.Time type using TimeOnly format

func TimeOnlyFromString

func TimeOnlyFromString(ctx context.Context, input string) TimeOnly

TimeOnlyFromString create TimeOnly from string

func (*TimeOnly) GobDecode

func (t *TimeOnly) GobDecode(data []byte) error

GobDecode implements the GOB interface

func (*TimeOnly) GobEncode

func (t *TimeOnly) GobEncode() ([]byte, error)

GobEncode implements the GOB interface

func (*TimeOnly) IsEmpty

func (t *TimeOnly) IsEmpty() bool

IsEmpty test whether TimeOnly is zero value (0001-01-01 00:00:00),

func (*TimeOnly) MarshalJSON

func (t *TimeOnly) MarshalJSON() ([]byte, error)

MarshalJSON marshal TimeOnly type to json

func (*TimeOnly) ParseString

func (t *TimeOnly) ParseString(input string) error

ParseString parse string and modify receiver

func (*TimeOnly) String

func (t *TimeOnly) String() string

String returns the string representation of TimeOnly time value

func (*TimeOnly) UnmarshalJSON

func (t *TimeOnly) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshal TimeOnly from json

Jump to

Keyboard shortcuts

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