MCPcopy Create free account
hub / github.com/dolthub/doltgresql / FromBigInt

Function FromBigInt

postgres/parser/duration/duration.go:216–232  ·  view source on GitHub ↗

FromBigInt converts a big.Int number of nanoseconds to a duration. Inverse conversion of AsBigInt. Boolean false if the result overflows.

(src *big.Int)

Source from the content-addressed store, hash-verified

214// FromBigInt converts a big.Int number of nanoseconds to a duration. Inverse
215// conversion of AsBigInt. Boolean false if the result overflows.
216func FromBigInt(src *big.Int) (Duration, bool) {
217 var rem big.Int
218 var monthsDec big.Int
219 monthsDec.QuoRem(src, bigNanosInMonth, &rem)
220 if !monthsDec.IsInt64() {
221 return Duration{}, false
222 }
223
224 var daysDec big.Int
225 var nanosRem big.Int
226 daysDec.QuoRem(&rem, bigNanosInDay, &nanosRem)
227 // Note: we do not need to check for overflow of daysDec because any
228 // excess bits were spilled into months above already.
229
230 d := Duration{Months: monthsDec.Int64(), Days: daysDec.Int64(), nanos: nanosRem.Int64()}
231 return d.normalize().round(), true
232}
233
234// AsInt64 converts a duration to an int64 number of seconds.
235// The conversion may overflow, in which case the boolean return

Callers

nothing calls this directly

Calls 3

normalizeMethod · 0.95
roundMethod · 0.80
Int64Method · 0.45

Tested by

no test coverage detected