timetz

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)

Functions

This section is empty.

Types

type TimeTZ

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

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

MakeTimeTZ creates a TimeTZ from a TimeOfDay and offset.

func MakeTimeTZFromLocation

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

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

func MakeTimeTZFromTime

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

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

func Now() TimeTZ

Now returns the TimeTZ of the current location.

func ParseTimeTZ

func ParseTimeTZ(
	now time.Time, dateStyle pgdate.DateStyle, 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

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

After returns whether the TimeTZ is after the other TimeTZ.

func (*TimeTZ) Before

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

Before returns whether the current is before the other TimeTZ.

func (*TimeTZ) Equal

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

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

func (*TimeTZ) Round

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

Round rounds a DTimeTZ to the given duration.

func (*TimeTZ) String

func (t *TimeTZ) String() string

String implements the Stringer interface.

func (*TimeTZ) ToDuration

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

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

func (*TimeTZ) ToTime

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

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

Jump to

Keyboard shortcuts

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