Skip to content

Commit

Permalink
Simplify pgtime to time.Time conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Mar 16, 2024
1 parent 78a8cdb commit 7cb3e81
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions flow/connectors/postgres/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,8 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (
case qvalue.QValueKindTime:
timeVal := value.(pgtype.Time)
if timeVal.Valid {
var timeValStr any
timeValStr, err := timeVal.Value()
if err != nil {
return qvalue.QValue{}, fmt.Errorf("failed to parse time: %w", err)
}
// edge case, only Postgres supports this extreme value for time
timeValStr = strings.Replace(timeValStr.(string), "24:00:00.000000", "23:59:59.999999", 1)
t, err := time.Parse("15:04:05.999999", timeValStr.(string))
t = t.AddDate(1970, 0, 0)
if err != nil {
return qvalue.QValue{}, fmt.Errorf("failed to parse time: %w", err)
}
val = qvalue.QValue{Kind: qvalue.QValueKindTime, Value: t}
// 1439999999 to prevent 24:00:00
val = qvalue.QValue{Kind: qvalue.QValueKindTime, Value: time.UnixMicro(min(timeVal.Microseconds, 1439999999))}
}
case qvalue.QValueKindTimeTZ:
timeVal := value.(string)
Expand Down

0 comments on commit 7cb3e81

Please sign in to comment.