Class DateTimeUtils


  • public class DateTimeUtils
    extends java.lang.Object
    Provides a number of utility operations for working with dates, times and timestamps.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.time.format.DateTimeFormatter[] DATE_FORMATS
      An array of date format specifications that NanoDB recognizes.
      private static java.time.format.DateTimeFormatter[] DATETIME_FORMATS
      An array of date/time format specifications that NanoDB recognizes.
      private static java.time.format.DateTimeFormatter[] TIME_FORMATS
      An array of time format specifications that NanoDB recognizes.
    • Constructor Summary

      Constructors 
      Constructor Description
      DateTimeUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.time.LocalDate parseDate​(java.lang.String s)
      Attempts to parse a string into a date value using the formats specified in DATE_FORMATS.
      static java.time.LocalDateTime parseDateTime​(java.lang.String s)
      Attempts to parse a string into a date/time value using the formats specified in DATETIME_FORMATS.
      static java.time.temporal.TemporalAmount parseInterval​(java.lang.String s)
      Attempts to parse a string into some kind of "temporal amount" or INTERVAL value.
      static java.time.temporal.Temporal parseTemporal​(java.lang.String s)
      Attempts to parse a string into some kind of temporal value using the formats specified in DATETIME_FORMATS, DATE_FORMATS, and TIME_FORMATS.
      static java.time.LocalTime parseTime​(java.lang.String s)
      Attempts to parse a string into a time value using the formats specified in TIME_FORMATS.
      • Methods inherited from class java.lang.Object

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

      • DATE_FORMATS

        private static final java.time.format.DateTimeFormatter[] DATE_FORMATS
        An array of date format specifications that NanoDB recognizes. New formats can be added to this array to expand what NanoDB is able to parse.
      • TIME_FORMATS

        private static final java.time.format.DateTimeFormatter[] TIME_FORMATS
        An array of time format specifications that NanoDB recognizes. New formats can be added to this array to expand what NanoDB is able to parse.
      • DATETIME_FORMATS

        private static final java.time.format.DateTimeFormatter[] DATETIME_FORMATS
        An array of date/time format specifications that NanoDB recognizes. New formats can be added to this array to expand what NanoDB is able to parse.
    • Constructor Detail

      • DateTimeUtils

        public DateTimeUtils()
    • Method Detail

      • parseDateTime

        public static java.time.LocalDateTime parseDateTime​(java.lang.String s)
        Attempts to parse a string into a date/time value using the formats specified in DATETIME_FORMATS.
        Parameters:
        s - the string to attempt to parse into a date/time
        Returns:
        an object holding the date/time value
        Throws:
        java.time.format.DateTimeParseException - if the string couldn't be parsed into a date/time value.
      • parseDate

        public static java.time.LocalDate parseDate​(java.lang.String s)
        Attempts to parse a string into a date value using the formats specified in DATE_FORMATS.
        Parameters:
        s - the string to attempt to parse into a date
        Returns:
        an object holding the date value
        Throws:
        java.time.format.DateTimeParseException - if the string couldn't be parsed into a date value.
      • parseTime

        public static java.time.LocalTime parseTime​(java.lang.String s)
        Attempts to parse a string into a time value using the formats specified in TIME_FORMATS.
        Parameters:
        s - the string to attempt to parse into a time
        Returns:
        an object holding the time value
        Throws:
        java.time.format.DateTimeParseException - if the string couldn't be parsed into a time value.
      • parseTemporal

        public static java.time.temporal.Temporal parseTemporal​(java.lang.String s)
        Attempts to parse a string into some kind of temporal value using the formats specified in DATETIME_FORMATS, DATE_FORMATS, and TIME_FORMATS. Attempts are made in this order, so a date/time will be produced if possible, then a date, and finally a time.
        Parameters:
        s - the string to attempt to parse into a temporal value
        Returns:
        an object holding the temporal value
        Throws:
        java.time.format.DateTimeParseException - if the string couldn't be parsed into a temporal value.
      • parseInterval

        public static java.time.temporal.TemporalAmount parseInterval​(java.lang.String s)
        Attempts to parse a string into some kind of "temporal amount" or INTERVAL value. Only one interval format is supported at this time: "N [YEAR|MONTH|WEEK|DAY|HOUR|MINUTE|SECOND]S?", where N is an integer. The units may be singular or plural; e.g. both "YEAR" and "YEARS" is supported.
        Parameters:
        s - the string to attempt to parse into a temporal amount
        Returns:
        an object holding the temporal amount
        Throws:
        java.time.format.DateTimeParseException - if the string couldn't be parsed into a temporal amount.