ardanlabs / gotour

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tour: example2.go -- methods returns only integer part of hours

jarav opened this issue · comments

Context: https://tour.ardanlabs.com/tour/eng/methods/1

In example2.go, the methods setHours and hours, as they are, ignores any fractional part of hours.

I think they should be as follows:

// setHours sets the specified number of hours.
func (d *duration) setHours(h float64) {
	*d = duration(h*float64(hour))
}

// hours returns the duration as a floating point number of hours.
func (d duration) hours() float64 {
	hours := d / hour
	nsec := d % hour
	return float64(hours) + float64(nsec)*(1e-9/60/60)
}

Thank you for a wonderful resource.

Hmmm. Wonder why the code is using float since a duration is an int64. I have no problem changing it.

I get the same answer either way. I wonder how important this is

I updated the code, it will show in patch 26