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

Function encodeDate

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

Source from the content-addressed store, hash-verified

461const pgEpochMicros = pgEpochDays * 24 * 60 * 60 * 1000000
462
463func encodeDate(v interface{}) []byte {
464 buf := make([]byte, 4)
465 var days int32
466
467 switch val := v.(type) {
468 case time.Time:
469 // Days since PostgreSQL epoch (2000-01-01)
470 unixDays := val.Unix() / 86400
471 days = int32(unixDays - pgEpochDays)
472 case string:
473 // Try to parse date string
474 t, err := time.Parse("2006-01-02", val)
475 if err != nil {
476 return nil
477 }
478 unixDays := t.Unix() / 86400
479 days = int32(unixDays - pgEpochDays)
480 default:
481 return nil
482 }
483
484 binary.BigEndian.PutUint32(buf, uint32(days))
485 return buf
486}
487
488func encodeTimestamp(v interface{}) []byte {
489 buf := make([]byte, 8)

Callers 2

TestEncodeDateFunction · 0.85
encodeBinaryFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEncodeDateFunction · 0.68