MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Encode

Method Encode

pkg/util/duration/duration.go:372–385  ·  view source on GitHub ↗

Encode returns three integers such that the original Duration is recoverable (using Decode) and the first int will approximately sort a collection of encoded Durations.

()

Source from the content-addressed store, hash-verified

370// (using Decode) and the first int will approximately sort a collection of
371// encoded Durations.
372func (d Duration) Encode() (sortNanos int64, months int64, days int64, err error) {
373 // The number of whole years equivalent to any value of Duration always fits
374 // in an int64. Use this to compute a conservative estimate of overflow.
375 //
376 // TODO(dan): Compute overflow exactly, then document that EncodeBigInt can be
377 // used in overflow cases.
378 years := d.Months/12 + d.Days/DaysPerMonth/12 + d.nanos/nanosInMonth/12
379 if years > maxYearsInDuration || years < minYearsInDuration {
380 return 0, 0, 0, errEncodeOverflow
381 }
382
383 totalNanos := d.Months*nanosInMonth + d.Days*nanosInDay + d.nanos
384 return totalNanos, d.Months, d.Days, nil
385}
386
387// EncodeBigInt is the same as Encode, except that it always returns
388// successfully and is slower.

Callers 5

EncodeDurationAscendingFunction · 0.80
EncodeDurationDescendingFunction · 0.80
PrettyPrintValueEncodedFunction · 0.80
StringBytesMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected