MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / timeFromDatumForComparison

Function timeFromDatumForComparison

pkg/sql/sem/tree/datum.go:2202–2228  ·  view source on GitHub ↗

timeFromDatumForComparison gets the time from a datum object to use strictly for comparison usage.

(ctx *EvalContext, d Datum)

Source from the content-addressed store, hash-verified

2200// timeFromDatumForComparison gets the time from a datum object to use
2201// strictly for comparison usage.
2202func timeFromDatumForComparison(ctx *EvalContext, d Datum) (time.Time, bool) {
2203 d = UnwrapDatum(ctx, d)
2204 switch t := d.(type) {
2205 case *DDate:
2206 ts, err := MakeDTimestampTZFromDate(ctx.GetLocation(), t)
2207 if err != nil {
2208 return time.Time{}, false
2209 }
2210 return ts.Time, true
2211 case *DTimestampTZ:
2212 return t.Time, true
2213 case *DTimestamp:
2214 // Normalize to the timezone of the context.
2215 _, zoneOffset := t.Time.In(ctx.GetLocation()).Zone()
2216 ts := t.Time.In(ctx.GetLocation()).Add(-time.Duration(zoneOffset) * time.Second)
2217 return ts, true
2218 case *DTime:
2219 // Normalize to the timezone of the context.
2220 toTime := timeofday.TimeOfDay(*t).ToTime()
2221 _, zoneOffsetSecs := toTime.In(ctx.GetLocation()).Zone()
2222 return toTime.In(ctx.GetLocation()).Add(-time.Duration(zoneOffsetSecs) * time.Second), true
2223 case *DTimeTZ:
2224 return t.ToTime(), true
2225 default:
2226 return time.Time{}, false
2227 }
2228}
2229
2230func compareTimestamps(ctx *EvalContext, l Datum, r Datum) int {
2231 lTime, lOk := timeFromDatumForComparison(ctx, l)

Callers 1

compareTimestampsFunction · 0.85

Calls 6

TimeOfDayTypeAlias · 0.92
UnwrapDatumFunction · 0.85
MakeDTimestampTZFromDateFunction · 0.85
AddMethod · 0.65
GetLocationMethod · 0.45
ToTimeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…