github.com/blend/go-sdk@v1.20220411.3/timeutil/milliseconds.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package timeutil 9 10 import ( 11 "math" 12 "time" 13 ) 14 15 // Milliseconds returns a duration as milliseconds. 16 func Milliseconds(d time.Duration) float64 { 17 return float64(d) / float64(time.Millisecond) 18 } 19 20 // FromMilliseconds returns a duration from a given float64 millis value. 21 func FromMilliseconds(millis float64) time.Duration { 22 // we use a `math.Ceil` here to avoid floating point precision issues. 23 // it will add, at most, a nanosecond error to the calculation. 24 return time.Duration(math.Ceil(millis * float64(time.Millisecond))) 25 }