Obtains a
Period from a text string such as
PnYnMnD.
This will parse the string produced by
toString() which is
based on the ISO-8601 period formats
PnYnMnD and
PnW.
The string starts with an optional sign, denoted by the ASCII negative
or positive symbol. If negative, the whole period is negated.
The ASCII letter "P" is next in upper or lower case.
There are then four sections, each consisting of a number and a suffix.
At least one of the four sections must be present.
The sections have suffixes in ASCII of "Y", "M", "W" and "D" for
years, months, weeks and days, accepted in upper or lower case.
The suffixes must occur in order.
The number part of each section must consist of ASCII digits.
The number may be prefixed by the ASCII negative or positive symbol.
The number must parse to an
int.
The leading plus/minus sign, and negative values for other units are
not part of the ISO-8601 standard. In addition, ISO-8601 does not
permit mixing between the
PnYnMnD and
PnW formats.
Any week-based input is multiplied by 7 and treated as a number of days.
For example, the following are valid inputs:
"P2Y" -- Period.ofYears(2)
"P3M" -- Period.ofMonths(3)
"P4W" -- Period.ofWeeks(4)
"P5D" -- Period.ofDays(5)
"P1Y2M3D" -- Period.of(1, 2, 3)
"P1Y2M3W4D" -- Period.of(1, 2, 25)
"P-1Y2M" -- Period.of(-1, 2, 0)
"-P1Y2M" -- Period.of(-1, -2, 0)