decodeTime decodes int64 microseconds since midnight into a time string.
(data []byte)
| 591 | |
| 592 | // decodeTime decodes int64 microseconds since midnight into a time string. |
| 593 | func decodeTime(data []byte) (string, error) { |
| 594 | if len(data) < 8 { |
| 595 | return "", fmt.Errorf("insufficient data for time: got %d bytes, need 8", len(data)) |
| 596 | } |
| 597 | micros := int64(binary.BigEndian.Uint64(data)) |
| 598 | hours := micros / 3600000000 |
| 599 | micros %= 3600000000 |
| 600 | minutes := micros / 60000000 |
| 601 | micros %= 60000000 |
| 602 | seconds := micros / 1000000 |
| 603 | micros %= 1000000 |
| 604 | if micros > 0 { |
| 605 | return fmt.Sprintf("%02d:%02d:%02d.%06d", hours, minutes, seconds, micros), nil |
| 606 | } |
| 607 | return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds), nil |
| 608 | } |
| 609 | |
| 610 | // encodeInterval encodes an INTERVAL value in PostgreSQL binary format: |
| 611 | // int64 microseconds + int32 days + int32 months = 16 bytes. |
no outgoing calls