Class PeriodParser


  • final class PeriodParser
    extends java.lang.Object
    An period parser that creates an instance of Period from a string using the ISO8601 period format PnYnMnDTnHnMn.nS.
    • Field Detail

      • INSTANCE

        private static final PeriodParser INSTANCE
        The singleton instance.
      • TOKEN_SEQUENCE

        private static final java.lang.String TOKEN_SEQUENCE
        Used to validate the correct sequence of tokens.
        See Also:
        Constant Field Values
      • ZERO

        private static final java.lang.String ZERO
        The standard string representing a zero period.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PeriodParser

        private PeriodParser()
        Restricted constructor.
    • Method Detail

      • getInstance

        static PeriodParser getInstance()
        Gets the singleton instance of the parser.
        Returns:
        the instance of the parser
      • parse

        Period parse​(java.lang.String text)
        Obtains an instance of Period from a string.

        This will parse the string produced by toString() which is a subset of the ISO8601 period format PnYnMnDTnHnMn.nS.

        The string consists of a series of numbers with a suffix identifying their meaning. The values, and suffixes, must be in the sequence year, month, day, hour, minute, second. Any of the number/suffix pairs may be omitted providing at least one is present. If the period is zero, the value is normally represented as PT0S. The numbers must consist of ASCII digits. Any of the numbers may be negative. Negative zero is not accepted. The number of nanoseconds is expressed as an optional fraction of the seconds. There must be at least one digit before any decimal point. There must be between 1 and 9 inclusive digits after any decimal point. The letters will all be accepted in upper or lower case. The decimal point may be either a dot or a comma.

        Parameters:
        text - the input string in the format PnYnMnDTnHnMn.nS, validated not null
        Returns:
        the created Period, never null
        Throws:
        CalendricalParseException - if the text cannot be parsed to a Period
      • prepareTime

        private java.lang.String prepareTime​(PeriodParser.ParseValues values,
                                             java.lang.String s,
                                             int baseIndex)
      • validateCharactersAndOrdering

        private void validateCharactersAndOrdering​(java.lang.String s,
                                                   java.lang.String text)