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 basic API exists but may yet change.
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:
New
now needs one more input parameter for the weeks field (7 parameters in total)NewYMD
still exists; there is alsoNewYMWD
, which will often be more appropriate.
These methods have changed:
YearsDecimal
,MonthsDecimal
,WeeksDecimal
,DaysDecimal
,HoursDecimal
,MinutesDecimal
andSecondsDecimal
return the fields asdecimal.Decimal
. They replace the oldYearsFloat
,MonthsFloat
,DaysFloat
,HoursFloat
,MinutesFloat
andSecondsFloat
methods.Years
,Months
,Weeks
,Days
,Hours
,Minutes
andSeconds
still returnint
as before.DaysIncWeeks
andDaysIncWeeksDecimal
were added to return d + w * 7, which provides the behaviour similar to the oldDays
andDaysFloat
methods.- The old
ModuloDays
was dropped now that weeks are implemented fully. OnlyYMD
is nowOnlyYMWD
Scale
andScaleWithOverflowCheck
have been replaced withMul
, which returns the multiplication product and a possibleerror
.