cockroach: github.com/cockroachdb/cockroach/pkg/util/timetz Index | Files

package timetz

import "github.com/cockroachdb/cockroach/pkg/util/timetz"

Index

Package Files

timetz.go

Variables

var (
    // MaxTimeTZOffsetSecs is the maximum offset TimeTZ allows in seconds.
    // NOTE: postgres documentation mentions 14:59, but up to 15:59 is accepted.
    MaxTimeTZOffsetSecs = int32((15*time.Hour + 59*time.Minute) / time.Second)
    // MinTimeTZOffsetSecs is the minimum offset TimeTZ allows in seconds.
    // NOTE: postgres documentation mentions -14:59, but up to -15:59 is accepted.
    MinTimeTZOffsetSecs = -1 * MaxTimeTZOffsetSecs
)

type TimeTZ Uses

type TimeTZ struct {
    // TimeOfDay is the time since midnight in a given zone
    // dictated by OffsetSecs.
    timeofday.TimeOfDay
    // OffsetSecs is the offset of the zone, with the sign reversed.
    // e.g. -0800 (PDT) would have OffsetSecs of +8*60*60.
    // This is in line with the postgres implementation.
    // This means timeofday.Secs() + OffsetSecs = UTC secs.
    OffsetSecs int32
}

TimeTZ is an implementation of postgres' TimeTZ. Note that in this implementation, if time is equal in terms of UTC time the zone offset is further used to differentiate.

func MakeTimeTZ Uses

func MakeTimeTZ(t timeofday.TimeOfDay, offsetSecs int32) TimeTZ

MakeTimeTZ creates a TimeTZ from a TimeOfDay and offset.

func MakeTimeTZFromLocation Uses

func MakeTimeTZFromLocation(t timeofday.TimeOfDay, loc *time.Location) TimeTZ

MakeTimeTZFromLocation creates a TimeTZ from a TimeOfDay and time.Location.

func MakeTimeTZFromTime Uses

func MakeTimeTZFromTime(t time.Time) TimeTZ

MakeTimeTZFromTime creates a TimeTZ from a time.Time. It will be trimmed to microsecond precision. 2400 time will overflow to 0000. If 2400 is needed, use MakeTimeTZFromTimeAllow2400.

func MakeTimeTZFromTimeAllow2400 Uses

func MakeTimeTZFromTimeAllow2400(t time.Time) TimeTZ

MakeTimeTZFromTimeAllow2400 creates a TimeTZ from a time.Time, but factors in that Time2400 may be possible. This assumes either a lib/pq time or unix time is set. This should be used for storage and network deserialization, where 2400 time is allowed.

func Now Uses

func Now() TimeTZ

Now returns the TimeTZ of the current location.

func ParseTimeTZ Uses

func ParseTimeTZ(
    now time.Time, s string, precision time.Duration,
) (_ TimeTZ, dependsOnContext bool, _ error)

ParseTimeTZ parses and returns the TimeTZ represented by the provided string, or an error if parsing is unsuccessful.

The dependsOnContext return value indicates if we had to consult the given `now` value (either for the time or the local timezone).

func (*TimeTZ) After Uses

func (t *TimeTZ) After(other TimeTZ) bool

After returns whether the TimeTZ is after the other TimeTZ.

func (*TimeTZ) Before Uses

func (t *TimeTZ) Before(other TimeTZ) bool

Before returns whether the current is before the other TimeTZ.

func (*TimeTZ) Equal Uses

func (t *TimeTZ) Equal(other TimeTZ) bool

Equal returns whether the TimeTZ is equal to the other TimeTZ.

func (*TimeTZ) Round Uses

func (t *TimeTZ) Round(precision time.Duration) TimeTZ

Round rounds a DTimeTZ to the given duration.

func (*TimeTZ) String Uses

func (t *TimeTZ) String() string

String implements the Stringer interface.

func (*TimeTZ) ToDuration Uses

func (t *TimeTZ) ToDuration() time.Duration

ToDuration returns the TimeTZ as an offset duration from UTC midnight.

func (*TimeTZ) ToTime Uses

func (t *TimeTZ) ToTime() time.Time

ToTime converts a DTimeTZ to a time.Time, corrected to the given location.

Package timetz imports 8 packages (graph) and is imported by 17 packages. Updated 2020-07-05. Refresh now. Tools for package owners.