Doesn't float64(d)/float64(time.Millisecond) work?
Hi,When I want to get a duration in milliseconds with sub-millisecond precision, I currently have to do:d := time.Since(start)msec := d.Seconds() * float64(time.Second/time.Millisecond)My other option is to use the Nanoseconds() method that return an int64, convert to float64 and then scale.I'd like to introduce two methods Microseconds() and Milliseconds() that return float64.// Microseconds returns the duration as a floating point number of microseconds.func (d *duration) Microseconds() float64// Milliseconds returns the duration as a floating point number of milliseconds.func (d *duration) Milliseconds() float64There are already Microsecond and Millisecond constants, and method to convert a Duration to all the other exported multipliers (Nanosecond, Second, Minute, Hour). I think we should at least provide them by symmetry.What do people think of my suggestion? If nobody objects, I'd probably write the method and send the code for review.Cheers,--
--
Hi,When I want to get a duration in milliseconds with sub-millisecond precision, I currently have to do:d := time.Since(start)msec := d.Seconds() * float64(time.Second/time.Millisecond)
Yes, this is for display. Personally I find that reading that something took 23.65ms is easier to read than 0.02365s.
I know that I can use d.Seconds() * 1000 (or other variations, the factor is probably not going to change soon) and that a d.Milliseconds() method is probably redundant but so are d.Minutes() or d.Hours() (with factor of 1/60 and 1/3600).
Apparently most of the people think this is not needed, so I'll just keep them in my own util library. Thank you all for the opinions.
Regards,
Does anyone object to the proposal to add methods Milliseconds and Microseconds?I know that Go is trying to be minimalist and certainly those two aren't needed. However, continuing that logic why are there Hours and Minutes? They're certainly easily calculable in exactly the same ways as described as above.