(typ oid.Oid, s []byte)
| 196 | } |
| 197 | |
| 198 | func parseTime(typ oid.Oid, s []byte) (time.Time, error) { |
| 199 | str := string(s) |
| 200 | |
| 201 | f := "15:04:05" |
| 202 | if typ == oid.T_timetz { |
| 203 | f = "15:04:05-07" |
| 204 | // PostgreSQL just sends the hour if the minute and second is 0: |
| 205 | // 22:04:59+00 |
| 206 | // 22:04:59+08 |
| 207 | // 22:04:59+08:30 |
| 208 | // 22:04:59+08:30:40 |
| 209 | // 23:00:00.112321+02:12:13 |
| 210 | // So add those to the format string. |
| 211 | c := strings.Count(str, ":") |
| 212 | if c > 3 { |
| 213 | f = "15:04:05-07:00:00" |
| 214 | } else if c > 2 { |
| 215 | f = "15:04:05-07:00" |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // Go doesn't parse 24:00, so manually set that to midnight on Jan 2. 24:00 |
| 220 | // is never with subseconds but may have a timezone: |
| 221 | // 24:00:00 |
| 222 | // 24:00:00+08 |
| 223 | // 24:00:00-08:01:01 |
| 224 | var is2400Time bool |
| 225 | if strings.HasPrefix(str, "24:00:00") { |
| 226 | is2400Time = true |
| 227 | if len(str) > 8 { |
| 228 | str = "00:00:00" + str[8:] |
| 229 | } else { |
| 230 | str = "00:00:00" |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | t, err := time.Parse(f, str) |
| 235 | if err != nil { |
| 236 | return time.Time{}, errors.New("pq: " + err.Error()) |
| 237 | } |
| 238 | if is2400Time { |
| 239 | t = t.Add(24 * time.Hour) |
| 240 | } |
| 241 | // TODO(v2): it uses UTC, which it shouldn't. But I'm afraid changing it now |
| 242 | // will break people's code. |
| 243 | //if typ == oid.T_time { |
| 244 | // // Don't use UTC but time.FixedZone("", 0) |
| 245 | // t = t.In(globalLocationCache.getLocation(0)) |
| 246 | //} |
| 247 | return t, nil |
| 248 | } |
| 249 | |
| 250 | var ( |
| 251 | infinityTSEnabled = false |
no test coverage detected
searching dependent graphs…