MCPcopy Create free account
hub / github.com/PostHog/duckgres / decodeTime

Function decodeTime

server/types.go:593–608  ·  view source on GitHub ↗

decodeTime decodes int64 microseconds since midnight into a time string.

(data []byte)

Source from the content-addressed store, hash-verified

591
592// decodeTime decodes int64 microseconds since midnight into a time string.
593func 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.

Callers 3

TestEncodeDecodeTimeFunction · 0.85
decodeBinaryCopyFunction · 0.85
decodeBinaryFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEncodeDecodeTimeFunction · 0.68