buildTimestamptzRowValue converts a PostgreSQL timestamp/timestamptz value into a RowValue. PostgreSQL supports dates outside the google.protobuf.Timestamp range (0001-01-01 to 9999-12-31); for those, fall back to a string instead of crashing response marshaling with "seconds out of range".
(typeName string, t time.Time, scale int32)
| 136 | // (0001-01-01 to 9999-12-31); for those, fall back to a string instead of crashing |
| 137 | // response marshaling with "seconds out of range". |
| 138 | func buildTimestamptzRowValue(typeName string, t time.Time, scale int32) *v1pb.RowValue { |
| 139 | ts := timestamppb.New(t) |
| 140 | if err := ts.CheckValid(); err != nil { |
| 141 | return util.BuildStringRowValue(formatPGTimestamp(t, typeName != "TIMESTAMP")) |
| 142 | } |
| 143 | if typeName == "TIMESTAMP" { |
| 144 | return &v1pb.RowValue{ |
| 145 | Kind: &v1pb.RowValue_TimestampValue{ |
| 146 | TimestampValue: &v1pb.RowValue_Timestamp{ |
| 147 | GoogleTimestamp: ts, |
| 148 | Accuracy: scale, |
| 149 | }, |
| 150 | }, |
| 151 | } |
| 152 | } |
| 153 | zone, offset := t.Zone() |
| 154 | return &v1pb.RowValue{ |
| 155 | Kind: &v1pb.RowValue_TimestampTzValue{ |
| 156 | TimestampTzValue: &v1pb.RowValue_TimestampTZ{ |
| 157 | GoogleTimestamp: ts, |
| 158 | Zone: zone, |
| 159 | Offset: int32(offset), |
| 160 | Accuracy: scale, |
| 161 | }, |
| 162 | }, |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // formatPGTimestamp renders a time.Time using PostgreSQL's text representation rather |
| 167 | // than RFC3339: a space separator, no zone for timestamp without time zone, and a " BC" |