timeFromDatumForComparison gets the time from a datum object to use strictly for comparison usage.
(ctx *EvalContext, d Datum)
| 2200 | // timeFromDatumForComparison gets the time from a datum object to use |
| 2201 | // strictly for comparison usage. |
| 2202 | func 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 | |
| 2230 | func compareTimestamps(ctx *EvalContext, l Datum, r Datum) int { |
| 2231 | lTime, lOk := timeFromDatumForComparison(ctx, l) |
no test coverage detected
searching dependent graphs…