Closed adewale closed 7 years ago
After thinking about this more (and with a nudge from Tom Insam on Twitter: https://twitter.com/tominsam/status/737849740168073217 ) I've realised that this problem can't be solved (with the current implementation and design) for the following units:
The above are why time.Duration: https://golang.org/pkg/time/#Duration doesn't handle any unit larger than hours.
One way to surface these issues is to add the following lines to the TestParse function in durafmt_test.go
{8760 * time.Hour, "1 year"}, {17520 * time.Hour, "2 years"},
One workaround might be to remove the formatting of any unit larger than an hour.
As you can see from this gist: https://gist.github.com/adewale/da804cc1db00c26e4892eb0da6463789 durafmt incorrectly calculates the duration in some scenarios.
A duration that should be "1 year 1 day" becomes "1 year 1 month 3 days"