(data []byte)
| 965 | } |
| 966 | |
| 967 | func decodeTimestamp(data []byte) (time.Time, error) { |
| 968 | if len(data) < 8 { |
| 969 | return time.Time{}, fmt.Errorf("insufficient data for timestamp: got %d bytes, need 8", len(data)) |
| 970 | } |
| 971 | // Microseconds since PostgreSQL epoch (2000-01-01) |
| 972 | micros := int64(binary.BigEndian.Uint64(data)) |
| 973 | // Use time.Unix to avoid time.Duration overflow for dates far from epoch. |
| 974 | // time.Duration is int64 nanoseconds, which overflows at ~292 years. |
| 975 | const pgEpochUnix int64 = 946684800 // 2000-01-01 00:00:00 UTC in Unix seconds |
| 976 | secs := micros / 1_000_000 |
| 977 | remainMicros := micros % 1_000_000 |
| 978 | if remainMicros < 0 { |
| 979 | secs-- |
| 980 | remainMicros += 1_000_000 |
| 981 | } |
| 982 | return time.Unix(pgEpochUnix+secs, remainMicros*1000).UTC(), nil |
| 983 | } |
| 984 | |
| 985 | // decodeNumeric decodes PostgreSQL binary numeric format into a string. |
| 986 | func decodeNumeric(data []byte) (string, error) { |
no outgoing calls