Masterminds / sprig

Useful template functions for Go templates.
http://masterminds.github.io/sprig/
MIT License
4.07k stars 423 forks source link

fix: massively improve durationRound function, add support for durations #364

Open FlorianLoch opened 1 year ago

FlorianLoch commented 1 year ago

durationRound function was quite broken in the sense it did not support time.Duration (also stated in the documentation).

Furthermore, I improved the algorithm and added more tests.

Nevertheless, I think this function is actually misleading - as it is more a floor than a round. Changing that would be to invasive I guess, I therefore pointed it out in the docs.

There is one breaking change contained: so far an int64 passed into durationRound was considered a duration in nanoseconds. I am not sure that really matches the expectation of the user. Especially, as it is not consistent with duration.