Documentation ¶
Index ¶
- Variables
- func FixedOffsetTimeZoneToLocation(offset int, origRepr string) *time.Location
- func ReplaceLibPQTimePrefix(s string) string
- type TimeTZ
- func MakeTimeTZ(t timeofday.TimeOfDay, offsetSecs int32) TimeTZ
- func MakeTimeTZFromLocation(t timeofday.TimeOfDay, loc *time.Location) TimeTZ
- func MakeTimeTZFromTime(t time.Time) TimeTZ
- func MakeTimeTZFromTimeAllow2400(t time.Time) TimeTZ
- func Now() TimeTZ
- func ParseTimeTZ(now time.Time, s string, precision time.Duration) (_ TimeTZ, dependsOnContext bool, _ error)
Constants ¶
This section is empty.
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 // LibPQTimePrefix is the prefix lib/pq prints time-type datatypes with. LibPQTimePrefix = "0000-01-01" )
Functions ¶
func FixedOffsetTimeZoneToLocation ¶
FixedOffsetTimeZoneToLocation creates a time.Location with a set offset and with a name that can be marshaled by crdb between nodes.
func ReplaceLibPQTimePrefix ¶
ReplaceLibPQTimePrefix replaces unparsable lib/pq dates used for timestamps (0000-01-01) with timestamps that can be parsed by date libraries.
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 ¶
MakeTimeTZ creates a TimeTZ from a TimeOfDay and offset.
func MakeTimeTZFromLocation ¶
MakeTimeTZFromLocation creates a TimeTZ from a TimeOfDay and time.Location.
func MakeTimeTZFromTime ¶
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 ¶
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 ParseTimeTZ ¶
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) ToDuration ¶
ToDuration returns the TimeTZ as an offset duration from UTC midnight.