Class ISODateTime

  • All Implemented Interfaces:
    ISOTemporal, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Date>

    public class ISODateTime
    extends AbstractISODateTime
    The class representing an ISO date time. If there is no explicit UTC offset (i.e. this is a floating value), the time is stored internally in terms of UTC.
    Author:
    Garret Wilson
    See Also:
    Serialized Form
    • Nested Class Summary

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        ISODateTime()
      Default constructor of a floating date time with the current time in terms of UTC.
        ISODateTime​(int year, int month, int day, int hours, int minutes, int seconds, int microseconds, ISOUTCOffset utcOffset)
      Full Constructor.
        ISODateTime​(int year, int month, int day, ISOTime time)
      Date components and time constructor.
        ISODateTime​(long time)
      Millisecond time constructor in terms of UTC.
        ISODateTime​(long time, java.util.TimeZone timeZone)
      Millisecond time constructor in terms of UTC.
      protected ISODateTime​(ISOTemporalComponents temporalComponents)
      Temporal component constructor.
        ISODateTime​(java.util.Date date)
      Date constructor in terms of UTC.
        ISODateTime​(java.util.Date date, java.util.TimeZone timeZone)
      Date constructor.
        ISODateTime​(java.util.TimeZone timeZone)
      Current time constructor in terms of UTC.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isMidnight()
      Returns whether the time, if any, represents midnight at the beginning of the day (00:00:00:00) in whatever UTC offset, if any, is indicated.
      java.util.Date toDate​(java.util.TimeZone timeZone)
      Returns a date that represents this temporal information in the given time zone.
      ISODate toISODate()
      Returns the date portion of this date and time.
      static ISODateTime valueOf​(java.lang.String string)
      Returns an ISO date time object holding the value of the specified string.
      static ISODateTime valueOfLenient​(java.lang.String string)
      Returns an ISO date time object holding the value of the specified string.
      static ISODateTime valueOfLiberal​(java.lang.String string)
      Returns an ISO date time object holding the value of the specified string.
      static ISODateTime valueOfTimestamp​(java.lang.String string)
      Returns an ISO date time object holding the value of the specified string.
      • Methods inherited from class java.util.Date

        after, before, clone, compareTo, equals, from, getDate, getHours, getMinutes, getSeconds, getTime, getTimezoneOffset, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toInstant, toLocaleString, UTC
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ISODateTime

        public ISODateTime()
        Default constructor of a floating date time with the current time in terms of UTC.
      • ISODateTime

        public ISODateTime​(java.util.TimeZone timeZone)
        Current time constructor in terms of UTC.
        Parameters:
        timeZone - The time zone in which the time should be interpreted.
        Throws:
        java.lang.NullPointerException - if the given time zone is null.
        java.lang.IllegalArgumentException - if a time zone was provided with an unsupported offset for the given time.
      • ISODateTime

        protected ISODateTime​(ISOTemporalComponents temporalComponents)
        Temporal component constructor.
        Parameters:
        temporalComponents - The temporal components from which to construct the class.
        Throws:
        java.lang.NullPointerException - if the given temporal components is null.
      • ISODateTime

        public ISODateTime​(int year,
                           int month,
                           int day,
                           ISOTime time)
        Date components and time constructor.
        Parameters:
        year - The year, 0-9999.
        month - The month, 1-12.
        day - The day, 1-31.
        time - The time.
        Throws:
        java.lang.NullPointerException - if the given time is null.
        java.lang.IllegalArgumentException - if one of the given arguments is outside the allowed range.
      • ISODateTime

        public ISODateTime​(int year,
                           int month,
                           int day,
                           int hours,
                           int minutes,
                           int seconds,
                           int microseconds,
                           ISOUTCOffset utcOffset)
        Full Constructor.
        Parameters:
        year - The year, 0-9999.
        month - The month, 1-12.
        day - The day, 1-31.
        hours - The hours, 0-23.
        minutes - The minutes, 0-59.
        seconds - The seconds, 0-60 (allowing leap-seconds; see ISO 8601:2004(E) 4.2.1).
        microseconds - The microseconds, 0-999999.
        utcOffset - The UTC offset, or null if no UTC offset is known.
        Throws:
        java.lang.IllegalArgumentException - if one of the given arguments is outside the allowed range.
      • ISODateTime

        public ISODateTime​(java.util.Date date)
        Date constructor in terms of UTC.
        Parameters:
        date - The date representing the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
        Throws:
        java.lang.NullPointerException - if the given date is null.
      • ISODateTime

        public ISODateTime​(java.util.Date date,
                           java.util.TimeZone timeZone)
        Date constructor.
        Parameters:
        date - The date representing the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
        timeZone - The time zone in which the time should be interpreted.
        Throws:
        java.lang.NullPointerException - if the given date and/or time zone is null.
        java.lang.IllegalArgumentException - if a time zone was provided with an unsupported offset for the given time.
      • ISODateTime

        public ISODateTime​(long time)
        Millisecond time constructor in terms of UTC.
        Parameters:
        time - The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
      • ISODateTime

        public ISODateTime​(long time,
                           java.util.TimeZone timeZone)
        Millisecond time constructor in terms of UTC.
        Parameters:
        time - The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
        timeZone - The time zone in which the time should be interpreted.
        Throws:
        java.lang.NullPointerException - if the given time zone is null.
        java.lang.IllegalArgumentException - if a time zone was provided with an unsupported offset for the given time.
    • Method Detail

      • isMidnight

        public boolean isMidnight()
        Returns whether the time, if any, represents midnight at the beginning of the day (00:00:00:00) in whatever UTC offset, if any, is indicated.

        If this method returns true, it indicates that AbstractISODateTime.getISOTime() is not null, as this date and time can only indicate midnight when there is an ISO time component present.

        Returns:
        true if this time represents midnight at the beginning of the day (00:00:00:00) in whatever UTC offset, if any, is indicated.
        See Also:
        ISOTime.isMidnight()
      • toDate

        public java.util.Date toDate​(java.util.TimeZone timeZone)
        Returns a date that represents this temporal information in the given time zone.
        Specified by:
        toDate in class AbstractISODateTime
        Parameters:
        timeZone - The time zone which the date should represent.
        Returns:
        The date this object represents in relation to the given time zone.
        Throws:
        java.lang.NullPointerException - if the given time zone is null.
      • toISODate

        public ISODate toISODate()
        Returns the date portion of this date and time.
        Specified by:
        toISODate in class AbstractISODateTime
        Returns:
        A date and time object with only the date part of this instance.
      • valueOf

        public static ISODateTime valueOf​(java.lang.String string)
                                   throws ArgumentSyntaxException
        Returns an ISO date time object holding the value of the specified string.
        Parameters:
        string - The string to be parsed as a date time.
        Returns:
        An ISO date time object represented by the string.
        Throws:
        java.lang.NullPointerException - if the given string is null
        ArgumentSyntaxException - if the given string does not have the correct syntax.
      • valueOfLenient

        public static ISODateTime valueOfLenient​(java.lang.String string)
                                          throws ArgumentSyntaxException
        Returns an ISO date time object holding the value of the specified string.

        Lenient parsing makes the following allowances:

        • Seconds are considered optional.
        • Whitespace before and after the date/time is allowed.
        • The looser RFC 3339 Internet timestamp format is allowed, allowing the UTC designator, 90, for example.
        Parameters:
        string - The string to be parsed as a date time.
        Returns:
        An ISO date time object represented by the string.
        Throws:
        java.lang.NullPointerException - if the given string is null
        ArgumentSyntaxException - if the given string does not have the correct syntax.
      • valueOfLiberal

        public static ISODateTime valueOfLiberal​(java.lang.String string)
                                          throws ArgumentSyntaxException
        Returns an ISO date time object holding the value of the specified string.

        Liberal parsing makes the following allowances:

        • Seconds are considered optional.
        • Whitespace before and after the date/time is allowed.
        • The looser RFC 3339 Internet timestamp format is allowed, allowing the UTC designator, 90, for example.
        • Delimiters are optional.
        Parameters:
        string - The string to be parsed as a date time.
        Returns:
        An ISO date time object represented by the string.
        Throws:
        java.lang.NullPointerException - if the given string is null
        ArgumentSyntaxException - if the given string does not have the correct syntax.
      • valueOfTimestamp

        public static ISODateTime valueOfTimestamp​(java.lang.String string)
                                            throws ArgumentSyntaxException
        Returns an ISO date time object holding the value of the specified string. The looser RFC 3339 Internet timestamp format is allowed, which is used in "W3C Date and Time Formats" as well as portions of WebDAV.
        Parameters:
        string - The string to be parsed as a date time.
        Returns:
        An ISO date time object represented by the string.
        Throws:
        java.lang.NullPointerException - if the given string is null
        ArgumentSyntaxException - if the given string does not have the correct syntax.
        See Also:
        RFC 3339, RFC 2518, W3C Date and Time Formats