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

Function encodeTimestamp

server/types.go:488–514  ·  view source on GitHub ↗
(v interface{})

Source from the content-addressed store, hash-verified

486}
487
488func encodeTimestamp(v interface{}) []byte {
489 buf := make([]byte, 8)
490 var micros int64
491
492 switch val := v.(type) {
493 case time.Time:
494 // Microseconds since PostgreSQL epoch (2000-01-01)
495 unixMicros := val.UnixMicro()
496 micros = unixMicros - pgEpochMicros
497 case string:
498 // Try to parse timestamp string
499 t, err := time.Parse("2006-01-02 15:04:05", val)
500 if err != nil {
501 t, err = time.Parse("2006-01-02T15:04:05Z", val)
502 if err != nil {
503 return nil
504 }
505 }
506 unixMicros := t.UnixMicro()
507 micros = unixMicros - pgEpochMicros
508 default:
509 return nil
510 }
511
512 binary.BigEndian.PutUint64(buf, uint64(micros))
513 return buf
514}
515
516func encodeBytea(v interface{}) []byte {
517 switch val := v.(type) {

Callers 3

TestEncodeTimestampFunction · 0.85
encodeBinaryFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestEncodeTimestampFunction · 0.68