Documentation ¶
Index ¶
- Constants
- Variables
- type Clock
- type DateTimeSpan
- func (ts DateTimeSpan) Contains(other DateTimeSpan) bool
- func (ts DateTimeSpan) Empty() bool
- func (ts DateTimeSpan) From() LocalDateTime
- func (ts DateTimeSpan) MarshalJSON() ([]byte, error)
- func (ts DateTimeSpan) NullableTo() NullableLocalDateTime
- func (ts DateTimeSpan) Overlaps(other DateTimeSpan) bool
- func (ts DateTimeSpan) Subtract(span DateTimeSpan) []DateTimeSpan
- func (ts DateTimeSpan) TimeSpan() LocalTimeSpan
- func (ts DateTimeSpan) To() LocalDateTime
- type Duration
- type LocalDate
- func (d LocalDate) AddDate(years, months, days int) LocalDate
- func (d LocalDate) After(u LocalDate) bool
- func (d LocalDate) BeforeOrEqual(u LocalDate) bool
- func (d LocalDate) Date() (year int, month time.Month, day int)
- func (d LocalDate) End() LocalDateTime
- func (d LocalDate) Equal(u LocalDate) bool
- func (d LocalDate) GetStartOfDayUTC() time.Time
- func (d LocalDate) IsNull() bool
- func (d LocalDate) MarshalJSON() ([]byte, error)
- func (d LocalDate) MarshalText() ([]byte, error)
- func (d LocalDate) Next() LocalDate
- func (d *LocalDate) Scan(value interface{}) error
- func (d LocalDate) Start() LocalDateTime
- func (d LocalDate) String() string
- func (d *LocalDate) UnmarshalJSON(data []byte) error
- func (d *LocalDate) UnmarshalText(text []byte) error
- func (d LocalDate) Value() (driver.Value, error)
- func (d LocalDate) Weekday() Weekday
- func (d LocalDate) WithTime(localTime LocalTime) LocalDateTime
- func (d LocalDate) Year() int
- type LocalDateTime
- func (ldt LocalDateTime) Add(d Duration) LocalDateTime
- func (ldt LocalDateTime) AddDate(years, months, days int) LocalDateTime
- func (ldt LocalDateTime) After(other LocalDateTime) bool
- func (ldt LocalDateTime) Before(other LocalDateTime) bool
- func (ldt LocalDateTime) Date() LocalDate
- func (ldt LocalDateTime) Earlier(other LocalDateTime) LocalDateTime
- func (ldt LocalDateTime) GoTime(location *time.Location) time.Time
- func (ldt LocalDateTime) IsNull() bool
- func (ldt LocalDateTime) MarshalJSON() ([]byte, error)
- func (ldt *LocalDateTime) Scan(value interface{}) error
- func (ldt LocalDateTime) String() string
- func (ldt LocalDateTime) Sub(u LocalDateTime) Duration
- func (ldt LocalDateTime) Time() LocalTime
- func (ldt *LocalDateTime) UnmarshalJSON(data []byte) error
- func (ldt LocalDateTime) Value() (driver.Value, error)
- func (ldt LocalDateTime) Weekday() Weekday
- type LocalTime
- func (t LocalTime) After(other LocalTime) bool
- func (t LocalTime) Before(other LocalTime) bool
- func (t LocalTime) Hour() int
- func (t LocalTime) MarshalJSON() ([]byte, error)
- func (t LocalTime) Minutes() int
- func (t *LocalTime) Scan(value interface{}) error
- func (t LocalTime) String() string
- func (t *LocalTime) UnmarshalJSON(data []byte) error
- func (t LocalTime) Value() (driver.Value, error)
- type LocalTimeSpan
- func (ts LocalTimeSpan) Contains(dateTimeSpan DateTimeSpan) bool
- func (ts LocalTimeSpan) DateTimeSpanWithinOneDay(date LocalDate) DateTimeSpan
- func (ts LocalTimeSpan) Duration() Duration
- func (ts LocalTimeSpan) From() LocalTime
- func (ts LocalTimeSpan) Overlaps(other LocalTimeSpan) bool
- func (ts LocalTimeSpan) OverlapsDateTimeSpan(dateTimeSpan DateTimeSpan) bool
- func (ts LocalTimeSpan) To() LocalTime
- func (ts LocalTimeSpan) Valid() bool
- type NullableLocalDate
- type NullableLocalDateTime
- type Period
- func MustNewOneDayPeriod(date LocalDate) Period
- func MustNewOpenPeriodFrom(from LocalDate) Period
- func MustNewPeriod(from LocalDate, to LocalDate) Period
- func NewOneDayPeriod(date LocalDate) (Period, error)
- func NewOpenPeriodFrom(from LocalDate) (Period, error)
- func NewPeriod(from LocalDate, to LocalDate) (Period, error)
- type Source
- type TimeCtxKey
- type UnixTimeStamp
- type Weekday
Constants ¶
const ( Nanosecond Duration = 1 Microsecond = 1000 * Nanosecond Millisecond = 1000 * Microsecond Second = 1000 * Millisecond Minute = 60 * Second Hour = 60 * Minute )
Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions.
const LocalDateFormat = "2006-01-02" // yyyy-mm-dd
LocalDateFormat is used to render LocalDate as string
Variables ¶
var CurrentTimeKey = TimeCtxKey("current_time")
TimeKey is key to keep current time in context
var ErrPeriodInvalidFromAfterTo = errors.New(`Invalid time period - "from" is after "to"`)
ErrPeriodInvalidFromAfterTo is returned when Period creating is called with invalid parameters: from > to
var ErrPeriodInvalidParamNull = errors.New(`Invalid time period - date is null`)
ErrPeriodInvalidParamNull is returned when Period creating is called with invalid parameters: from or to is NullLocalDate
var Midnight = MustCreateNewLocalTime(0, 0)
var NullLocalDate = LocalDate{/* contains filtered or unexported fields */}
NullLocalDate is used to represent missing date value
var NullLocalDateTime = LocalDateTime{/* contains filtered or unexported fields */}
NullLocalDateTime is used to represent missing LocalDateTime value
var NullLocalTime = LocalTime{/* contains filtered or unexported fields */}
NullLocalTime is used to represent missing date value
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface { Today(ctx context.Context) LocalDate Now(ctx context.Context) LocalDateTime GoTime(ctx context.Context) time.Time ToUnixTimestamp(ctx context.Context, localDateTime LocalDateTime) UnixTimeStamp }
Clock provides information about current time
type DateTimeSpan ¶
type DateTimeSpan struct {
// contains filtered or unexported fields
}
DateTimeSpan represents time span between two moments
func MustNewOpenDateTimeSpanFrom ¶
func MustNewOpenDateTimeSpanFrom(from LocalDateTime) DateTimeSpan
func NewDateTimeSpan ¶
func NewDateTimeSpan(from LocalDateTime, to LocalDateTime) DateTimeSpan
NewDateTimeSpan creates DateTimeSpan instance
func NewOpenDateTimeSpanFrom ¶
func NewOpenDateTimeSpanFrom(from LocalDateTime) (DateTimeSpan, error)
NewOpenDateTimeSpanFrom creates DateTimeSpan that represents a set of days between "from" (inclusive) and eternity
func (DateTimeSpan) Contains ¶
func (ts DateTimeSpan) Contains(other DateTimeSpan) bool
Contains checks if DateTimeSpan fully covers other DateTimeSpan
func (DateTimeSpan) Empty ¶
func (ts DateTimeSpan) Empty() bool
Empty checks if DateTimeStamp has zero duration
func (DateTimeSpan) From ¶
func (ts DateTimeSpan) From() LocalDateTime
From returns start of DateTimeSpan
func (DateTimeSpan) MarshalJSON ¶
func (ts DateTimeSpan) MarshalJSON() ([]byte, error)
func (DateTimeSpan) NullableTo ¶
func (ts DateTimeSpan) NullableTo() NullableLocalDateTime
NullableTo returns last day of a period or null
func (DateTimeSpan) Overlaps ¶
func (ts DateTimeSpan) Overlaps(other DateTimeSpan) bool
Overlaps checks if DateTimeSpan overlaps other DateTimeSpan
func (DateTimeSpan) Subtract ¶
func (ts DateTimeSpan) Subtract(span DateTimeSpan) []DateTimeSpan
func (DateTimeSpan) TimeSpan ¶
func (ts DateTimeSpan) TimeSpan() LocalTimeSpan
TimeSpan creates LocalTimeSpan based on this object start and stop time of a day. Start and stop must be on the same day and start can't be after end.
type Duration ¶
type Duration int64
A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years.
func CalculateDuration ¶
func CalculateDuration(from LocalDateTime, to LocalDateTime) Duration
CalculateDuration returns time duration between two DateTimes
type LocalDate ¶
type LocalDate struct {
// contains filtered or unexported fields
}
LocalDate represents a date without taking into account a timezone
func MustParseLocalDate ¶
MustParseLocalDate parses string into date using LocalDateFormat and panics if it is impossible
func NewLocalDate ¶
NewLocalDate creates instances of LocalDate
func ParseLocalDate ¶
ParseLocalDate parses string into date using LocalDateFormat
func ToLocalDate ¶
ToLocalDate converts date from go's time.Time to LocalDate.
func (LocalDate) AddDate ¶
AddDate returns the date corresponding to adding the given number of years, months and days to d.
func (LocalDate) BeforeOrEqual ¶
BeforeOrEqual reports wheter the date d is before or equal to u.
func (LocalDate) End ¶
func (d LocalDate) End() LocalDateTime
func (LocalDate) GetStartOfDayUTC ¶
GetStartOfDayUTC returns Time value that represent beginning of a day (00:00 AM) at UTC timezone
func (LocalDate) MarshalJSON ¶
MarshalJSON marshals date to JSON
func (LocalDate) MarshalText ¶
MarshalText serializes this date type to string
func (LocalDate) Start ¶
func (d LocalDate) Start() LocalDateTime
func (*LocalDate) UnmarshalJSON ¶
UnmarshalJSON parses JSON string into date using LocalDateFormat
func (*LocalDate) UnmarshalText ¶
UnmarshalText parses string into date using LocalDateFormat
func (LocalDate) WithTime ¶
func (d LocalDate) WithTime(localTime LocalTime) LocalDateTime
WithTime creates time.Time instance when combined with LocalTime
type LocalDateTime ¶
type LocalDateTime struct {
// contains filtered or unexported fields
}
LocalDateTime represents a date and time without taking into account a timezone
func Earlier ¶
func Earlier(dateTime1, dateTime2 LocalDateTime) LocalDateTime
func MustParseLocalDateTime ¶
func MustParseLocalDateTime(datetime string) LocalDateTime
MustParseLocalDateTime parses string into LocalDateTime
func NewLocalDateTime ¶
func NewLocalDateTime(t time.Time) LocalDateTime
NewLocalDateTime creates instances of LocalDateTime
func ParseLocalDateTime ¶
func ParseLocalDateTime(datetime string) (LocalDateTime, error)
ParseLocalDateTime parses string into LocalDateTime
func (LocalDateTime) Add ¶
func (ldt LocalDateTime) Add(d Duration) LocalDateTime
Add returns the date-time equal to ldt+d.
func (LocalDateTime) AddDate ¶
func (ldt LocalDateTime) AddDate(years, months, days int) LocalDateTime
AddDate returns the date-time increased by the given number of years, months and days.
func (LocalDateTime) After ¶
func (ldt LocalDateTime) After(other LocalDateTime) bool
After reports whether this object if after method argument
func (LocalDateTime) Before ¶
func (ldt LocalDateTime) Before(other LocalDateTime) bool
Before reports whether this object if before method argument
func (LocalDateTime) Date ¶
func (ldt LocalDateTime) Date() LocalDate
Date returns the date component from LocalDateTime
func (LocalDateTime) Earlier ¶
func (ldt LocalDateTime) Earlier(other LocalDateTime) LocalDateTime
func (LocalDateTime) GoTime ¶
func (ldt LocalDateTime) GoTime(location *time.Location) time.Time
GoTime returns converts LocalDateTime to time.Time, keeping same numeric date and time values and sets timezone
func (LocalDateTime) IsNull ¶
func (ldt LocalDateTime) IsNull() bool
IsNull checks whether this variable represents missing value
func (LocalDateTime) MarshalJSON ¶
func (ldt LocalDateTime) MarshalJSON() ([]byte, error)
MarshalJSON marshals date to JSON
func (*LocalDateTime) Scan ¶
func (ldt *LocalDateTime) Scan(value interface{}) error
Scan implements the Scanner interface.
func (LocalDateTime) String ¶
func (ldt LocalDateTime) String() string
func (LocalDateTime) Sub ¶
func (ldt LocalDateTime) Sub(u LocalDateTime) Duration
Sub returns the duration ldt-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute ldt-d for a duration d, use Add(-d).
func (LocalDateTime) Time ¶
func (ldt LocalDateTime) Time() LocalTime
Time returns the time component from LocalDateTime
func (*LocalDateTime) UnmarshalJSON ¶
func (ldt *LocalDateTime) UnmarshalJSON(data []byte) error
UnmarshalJSON parses JSON string into LocalDateTime
func (LocalDateTime) Value ¶
func (ldt LocalDateTime) Value() (driver.Value, error)
Value implements the sql driver Valuer interface.
func (LocalDateTime) Weekday ¶
func (ldt LocalDateTime) Weekday() Weekday
Weekday returns weekday of a given date
type LocalTime ¶
type LocalTime struct {
// contains filtered or unexported fields
}
LocalTime represents time of a day without taking into account a timezone
func MustCreateNewLocalTime ¶
MustCreateNewLocalTime is like NewLocalTime but panics on error
func MustParseLocalTime ¶
MustParseLocalTime parses string in form of "15:04"
func NewLocalTime ¶
NewLocalTime creates instances of LocalTime
func ParseLocalTime ¶
ParseLocalTime parses string into LocalTime
func ToLocalTime ¶
ToLocalTime converts time from go's time.Time to LocalTime.
func (LocalTime) MarshalJSON ¶
MarshalJSON marshals locat time to JSON
func (*LocalTime) UnmarshalJSON ¶
UnmarshalJSON parses JSON string into LocalTime
type LocalTimeSpan ¶
type LocalTimeSpan struct {
// contains filtered or unexported fields
}
LocalTimeSpan represents a span between two LocalTime instances
func MustParseTimeSpan ¶
func MustParseTimeSpan(value string) LocalTimeSpan
MustParseTimeSpan parses string in form of "15:04-15:04" into LocalTimeSpan
func NewTimeSpan ¶
func NewTimeSpan(from LocalTime, to LocalTime) LocalTimeSpan
NewTimeSpan creates new LocalTimeSpan
func (LocalTimeSpan) Contains ¶
func (ts LocalTimeSpan) Contains(dateTimeSpan DateTimeSpan) bool
Contains check if LocalTimeSpan contains DateTimeSpan
func (LocalTimeSpan) DateTimeSpanWithinOneDay ¶
func (ts LocalTimeSpan) DateTimeSpanWithinOneDay(date LocalDate) DateTimeSpan
DateTimeSpanWithinOneDay creates DateTimeSpan with start and end on the given day and with time corresponding to LocalTimeSpan start and end.
func (LocalTimeSpan) Duration ¶
func (ts LocalTimeSpan) Duration() Duration
func (LocalTimeSpan) From ¶
func (ts LocalTimeSpan) From() LocalTime
From returns start of LocalTimeSpan
func (LocalTimeSpan) Overlaps ¶
func (ts LocalTimeSpan) Overlaps(other LocalTimeSpan) bool
Overlaps checks if LocalTimeSpan overlaps other LocalTimeSpan
func (LocalTimeSpan) OverlapsDateTimeSpan ¶
func (ts LocalTimeSpan) OverlapsDateTimeSpan(dateTimeSpan DateTimeSpan) bool
OverlapsDateTimeSpan checks if LocalTimeSpan overlaps DateTimeSpan
func (LocalTimeSpan) Valid ¶
func (ts LocalTimeSpan) Valid() bool
type NullableLocalDate ¶
NullableLocalDate represents a LocalDate that may be null. It implements the sql.Scanner interface so it can be used as a scan destination, similar to sql.NullString.
func (*NullableLocalDate) Scan ¶
func (d *NullableLocalDate) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullableLocalDateTime ¶
type NullableLocalDateTime struct { DateTime LocalDateTime Valid bool }
NullableLocalDateTime represents a LocalDateTime that may be null. It implements the sql.Scanner interface so it can be used as a scan destination, similar to sql.NullString.
func (*NullableLocalDateTime) Scan ¶
func (d *NullableLocalDateTime) Scan(value interface{}) error
Scan implements the Scanner interface.
type Period ¶
type Period struct {
// contains filtered or unexported fields
}
Period represents a set of days between two dates (inclusive)
func MustNewOneDayPeriod ¶
func MustNewOpenPeriodFrom ¶
func MustNewPeriod ¶
func NewOneDayPeriod ¶
NewOneDayPeriod creates Period that represents a single day
func NewOpenPeriodFrom ¶
NewOpenPeriodFrom creates Period that represents a set of days between "from" (inclusive) and eternity
func NewPeriod ¶
NewPeriod creates Period that represents a set of days between two dates: "from" (inclusive) and "to" (inclusive)
func (Period) NullableTo ¶
func (p Period) NullableTo() NullableLocalDate
NullableTo returns last day of a period or null
func (Period) ToDateTimeSpan ¶
func (p Period) ToDateTimeSpan() DateTimeSpan
type UnixTimeStamp ¶
type UnixTimeStamp int64
UnixTimeStamp represents number of seconds elapsed since January 1, 1970 UTC.
func (*UnixTimeStamp) Scan ¶
func (uts *UnixTimeStamp) Scan(value interface{}) error
Scan implements the Scanner interface.
type Weekday ¶
Weekday represents day of a week
Constants representing days of a week
func ParseWeekday ¶
ParseWeekday parses string into Weekday
func (Weekday) MarshalJSON ¶
MarshalJSON marshals date to JSON
func (Weekday) MarshalText ¶
MarshalText serializes this date type to string
func (*Weekday) UnmarshalText ¶
UnmarshalText parses string into weekday