Class ITU


  • public class ITU
    extends java.lang.Object
    The main access to the parse and formatting functions in this library.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ITU()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String format​(java.time.OffsetDateTime offsetDateTime)
      Format the input as an RFC-3339 formatted date-time in the timezone of the input.
      static java.lang.String format​(java.time.OffsetDateTime offsetDateTime, int fractionDigits)
      Format the input as an RFC-3339 formatted date-time in the timezone of the input, with the specified number of fraction digits.
      static java.lang.String formatUtc​(java.time.OffsetDateTime offsetDateTime)
      Format the input as an RFC-3339 formatted date-time in the UTC timezone with second resolution.
      static java.lang.String formatUtc​(java.time.OffsetDateTime offsetDateTime, int fractionDigits)
      Format the input as an RFC-3339 formatted date-time in the UTC timezone
      static java.lang.String formatUtc​(java.time.OffsetDateTime offsetDateTime, Field lastIncluded)
      Format the input as an ISO format string, limited to the granularity of the specified field, in the UTC timezone.
      static java.lang.String formatUtcMicro​(java.time.OffsetDateTime offsetDateTime)
      Format the input as an RFC-3339 formatted date-time in the UTC timezone with microsecond resolution.
      static java.lang.String formatUtcMilli​(java.time.OffsetDateTime offsetDateTime)
      Format the input as an RFC-3339 formatted date-time in the UTC timezone with millisecond resolution.
      static java.lang.String formatUtcNano​(java.time.OffsetDateTime offsetDateTime)
      Format the input as an RFC-3339 formatted date-time in the UTC timezone with nanosecond resolution
      private static boolean isAllowed​(TemporalType needle, TemporalType... allowed)  
      static boolean isValid​(java.lang.String text)
      Check if the dateTime is valid according to the RFC-3339 specification
      static boolean isValid​(java.lang.String text, TemporalType... types)
      Check if the input is valid for one of the specified types
      static void parse​(java.lang.String text, TemporalConsumer temporalConsumer)
      Parse the input, and use callbacks for the type of date/date-time it contains.
      static <T> T parse​(java.lang.String text, TemporalHandler<T> temporalHandler)
      Parse the input, and use callbacks for the type of date/date-time it contains.
      static java.time.OffsetDateTime parseDateTime​(java.lang.String text)
      Parse an RFC-3339 formatted date-time to an OffsetDateTime
      static java.time.OffsetDateTime parseDateTime​(java.lang.String text, java.text.ParsePosition position)  
      static Duration parseDuration​(java.lang.String text)
      Parses a duration string, a strict subset of ISO 8601 durations.
      static Duration parseDuration​(java.lang.String text, int offset)
      Parses a duration string starting at the specified offset.
      static DateTime parseLenient​(java.lang.String text)
      Parse an ISO formatted date and optionally time to a DateTime.
      static DateTime parseLenient​(java.lang.String text, ParseConfig parseConfig)
      Allows parsing leniently with to control some aspects of the parsing
      static DateTime parseLenient​(java.lang.String text, ParseConfig parseConfig, java.text.ParsePosition position)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ITU

        private ITU()
    • Method Detail

      • parseDateTime

        public static java.time.OffsetDateTime parseDateTime​(java.lang.String text)
        Parse an RFC-3339 formatted date-time to an OffsetDateTime
        Parameters:
        text - The text to parse
        Returns:
        The date and time parsed
      • parseDuration

        public static Duration parseDuration​(java.lang.String text)
        Parses a duration string, a strict subset of ISO 8601 durations.

        This method supports time-based durations with the following units:

        • Weeks (`W`)
        • Days (`D`)
        • Hours (`H`)
        • Minutes (`M`)
        • Seconds (`S`), including fractional seconds up to nanosecond precision
        The following units are explicitly not allowed to avoid ambiguity:
        • Years (`Y`)
        • Months (`M` in the date section)

        Negative durations are supported and must be prefixed with `-P`, as specified in ISO 8601. The parsed duration will be represented using a long for total seconds and an int for nanosecond precision. The nanosecond component is always positive, with the sign absorbed by the seconds field, following Java and ISO 8601 conventions.

        Examples of Valid Input
        • P2DT3H4M5.678901234S → 2 days, 3 hours, 4 minutes, 5.678901234 seconds
        • PT5M30S → 5 minutes, 30 seconds
        • -PT2.5S → Negative 2.5 seconds
        • -P1D → Negative 1 day
        Examples of Invalid Input
        • P1Y2M3DT4H → Contains `Y` and `M`
        • PT → Missing time values after `T`
        • P-1D → Incorrect negative placement

        Parameters:
        text - the duration string to parse
        Returns:
        a Duration instance representing the parsed duration
        Throws:
        java.time.format.DateTimeParseException - if the input does not conform to the expected format
      • parseDuration

        public static Duration parseDuration​(java.lang.String text,
                                             int offset)
        Parses a duration string starting at the specified offset. See parseDuration(String) for more information.
        Parameters:
        text - The text to parse
        offset - the offset in the text to start at
        Returns:
        a Duration instance representing the parsed duration
        Throws:
        java.time.format.DateTimeParseException - if the input does not conform to the expected format
      • parseDateTime

        public static java.time.OffsetDateTime parseDateTime​(java.lang.String text,
                                                             java.text.ParsePosition position)
      • parseLenient

        public static DateTime parseLenient​(java.lang.String text)
        Parse an ISO formatted date and optionally time to a DateTime. The result has rudimentary checks for correctness, but will not be aware of number of days per specific month or leap-years.
        Parameters:
        text - The text to parse
        Returns:
        The date and time parsed
      • parseLenient

        public static DateTime parseLenient​(java.lang.String text,
                                            ParseConfig parseConfig)
        Allows parsing leniently with to control some aspects of the parsing
        Parameters:
        text - The text to parse
        parseConfig - The configuration to use for parsing
        Returns:
        The date-time parsed
      • parseLenient

        public static DateTime parseLenient​(java.lang.String text,
                                            ParseConfig parseConfig,
                                            java.text.ParsePosition position)
        Parameters:
        text - The text to parse
        parseConfig - The configuration to use for parsing
        position - The position to start parsing from. The index (and the errorIndex, if an error occurs) is updated after the parsing process has completed
        Returns:
        The date-time parsed
      • isValid

        public static boolean isValid​(java.lang.String text)
        Check if the dateTime is valid according to the RFC-3339 specification
        Parameters:
        text - The input to validate
        Returns:
        True if valid, otherwise false
      • formatUtc

        public static java.lang.String formatUtc​(java.time.OffsetDateTime offsetDateTime,
                                                 int fractionDigits)
        Format the input as an RFC-3339 formatted date-time in the UTC timezone
        Parameters:
        offsetDateTime - The date-time to format
        fractionDigits - The number of fraction digits in the second field
        Returns:
        The formatted string
      • formatUtc

        public static java.lang.String formatUtc​(java.time.OffsetDateTime offsetDateTime,
                                                 Field lastIncluded)
        Format the input as an ISO format string, limited to the granularity of the specified field, in the UTC timezone.
        Parameters:
        offsetDateTime - The date-time to format
        lastIncluded - The last included field
        Returns:
        The formatted string
      • format

        public static java.lang.String format​(java.time.OffsetDateTime offsetDateTime)
        Format the input as an RFC-3339 formatted date-time in the timezone of the input.
        Parameters:
        offsetDateTime - The date-time to format
        Returns:
        The formatted string
      • format

        public static java.lang.String format​(java.time.OffsetDateTime offsetDateTime,
                                              int fractionDigits)
        Format the input as an RFC-3339 formatted date-time in the timezone of the input, with the specified number of fraction digits.
        Parameters:
        offsetDateTime - The date-time to format
        fractionDigits - The number of fraction digits in the second field
        Returns:
        The formatted string
      • formatUtc

        public static java.lang.String formatUtc​(java.time.OffsetDateTime offsetDateTime)
        Format the input as an RFC-3339 formatted date-time in the UTC timezone with second resolution.
        Parameters:
        offsetDateTime - The date-time to format.
        Returns:
        The formatted string with second resolution.
      • formatUtcMilli

        public static java.lang.String formatUtcMilli​(java.time.OffsetDateTime offsetDateTime)
        Format the input as an RFC-3339 formatted date-time in the UTC timezone with millisecond resolution.
        Parameters:
        offsetDateTime - The date-time to format.
        Returns:
        The formatted string with millisecond resolution.
      • formatUtcMicro

        public static java.lang.String formatUtcMicro​(java.time.OffsetDateTime offsetDateTime)
        Format the input as an RFC-3339 formatted date-time in the UTC timezone with microsecond resolution.
        Parameters:
        offsetDateTime - The date-time to format
        Returns:
        The formatted string with microsecond resolution
      • formatUtcNano

        public static java.lang.String formatUtcNano​(java.time.OffsetDateTime offsetDateTime)
        Format the input as an RFC-3339 formatted date-time in the UTC timezone with nanosecond resolution
        Parameters:
        offsetDateTime - The date-time to format
        Returns:
        The formatted string with nanosecond resolution
      • parse

        public static void parse​(java.lang.String text,
                                 TemporalConsumer temporalConsumer)
        Parse the input, and use callbacks for the type of date/date-time it contains. This allows you to handle different granularity inputs with ease!
        Parameters:
        text - The text to parse as a date/date-time
        temporalConsumer - The consumer of the found date/date-time
      • parse

        public static <T> T parse​(java.lang.String text,
                                  TemporalHandler<T> temporalHandler)
        Parse the input, and use callbacks for the type of date/date-time it contains. This allows you to handle different granularity inputs with ease!
        Type Parameters:
        T - The type of Temporal returned
        Parameters:
        text - The text to parse as a date/date-time
        temporalHandler - The handler of the found date/date-time
        Returns:
        The temporal matching the type handled
      • isValid

        public static boolean isValid​(java.lang.String text,
                                      TemporalType... types)
        Check if the input is valid for one of the specified types
        Parameters:
        text - The input to check
        types - The types that are considered valid
        Returns:
        True if valid, otherwise false