Package period has types that represent ISO-8601 periods of time.
The two core types are
ISOString- an ISO-8601 stringPeriod- a struct with the seven numbers years, months, weeks, days, hours, minutes and seconds.
These two can be converted to the other.
Period also allows various calculations to be made. Its fields each hold up to 19 digits precision.
The API is now stable for v1.
The old version of this was github.com/rickb777/date/period, which had very limited number range and used fixed-point arithmetic.
The new version, here, depends instead on github.com/govalues/decimal, which gives a huge (but finite) number range. There is now a 'weeks' field, which the old version did not have (it followed time.Time API patterns, which don't have weeks).
These functions have changed:
Newnow needs one more input parameter for the weeks field (7 parameters in total)NewYMDstill exists; there is alsoNewYMWD, which will often be more appropriate.
These methods have changed:
YearsDecimal,MonthsDecimal,WeeksDecimal,DaysDecimal,HoursDecimal,MinutesDecimalandSecondsDecimalreturn the fields asdecimal.Decimal. They replace the oldYearsFloat,MonthsFloat,DaysFloat,HoursFloat,MinutesFloatandSecondsFloatmethods.Years,Months,Weeks,Days,Hours,MinutesandSecondsstill returnintas before.DaysIncWeeksandDaysIncWeeksDecimalwere added to return d + w * 7, which provides the behaviour similar to the oldDaysandDaysFloatmethods.- The old
ModuloDayswas dropped now that weeks are implemented fully. OnlyYMDis nowOnlyYMWDScaleandScaleWithOverflowCheckhave been replaced withMul, which returns the multiplication product and a possibleerror.