FromBigInt converts a big.Int number of nanoseconds to a duration. Inverse conversion of AsBigInt. Boolean false if the result overflows.
(src *big.Int)
| 214 | // FromBigInt converts a big.Int number of nanoseconds to a duration. Inverse |
| 215 | // conversion of AsBigInt. Boolean false if the result overflows. |
| 216 | func 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 |