Class JS4JDate

  • All Implemented Interfaces:
    Serializable, Cloneable, Comparable<Date>

    public class JS4JDate
    extends Date
    Special object extends java.util.Date with special constructors taking specific date formatted strings. The toString implementation provides a formatted date suitable for sorting in the format "yyyy/MM/ddTHH:mm:ss.SSS(Z)"
    See Also:
    Serialized Form
    • Field Detail

      • CREATE_DATE_FORMAT

        public static final String CREATE_DATE_FORMAT
        Format for parsing the create date string: 2004/08/04-07:23:15.987(-0400)
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_0

        public static final String CREATE_DATE_FORMAT_0
        Format for parsing the create date string: 2004/08/04-07:23:15.987 which is assumed to be 0000 (Greenwich Mean Time).
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_1

        public static final String CREATE_DATE_FORMAT_1
        Format for parsing the create date string: 2004/08/04-07:23:15 which is assumed to be 0000 (Greenwich Mean Time) with 0 milliseconds.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_10

        public static final String CREATE_DATE_FORMAT_10
        Format for parsing the create date string: 2004/08/04 07:23:15.987123 which is assumed to be 0000 (Greenwich Mean Time).
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_11

        public static final String CREATE_DATE_FORMAT_11
        Format for parsing the create date string: Monday, 22 Sep 1959 08:12:34 which is assumed to be UTC (GMT)
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_12

        public static final String CREATE_DATE_FORMAT_12
        Format for parsing the create date string: January 05 2018 00:44:45 which is assumed to be UTC (GMT)
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_2

        public static final String CREATE_DATE_FORMAT_2
        Format for parsing the create date string: 2004/08/04-07:23 which is assumed to be 0000 (Greenwich Mean Time) with 0 seconds and milliseconds.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_3

        public static final String CREATE_DATE_FORMAT_3
        Format for parsing the create date string: 2004/08/04-07 which is assumed to be 0000 (Greenwich Mean Time) with 0 minutes, seconds and milliseconds.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_4

        public static final String CREATE_DATE_FORMAT_4
        Format for parsing the create date string: 2004/08/04 which is assumed to be 0000 (Greenwich Mean Time) at midnight.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_5

        public static final String CREATE_DATE_FORMAT_5
        Format for parsing the create date string: 2004/08/04-07:23:15(-0400) which is assumed to be -0400 (Eastern Daylight Time) with 0 milliseconds.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_6

        public static final String CREATE_DATE_FORMAT_6
        Format for parsing the create date string: 2004/08/04-07:23(-0400) which is assumed to be -0400 (Eastern Daylight Time) with 0 seconds and milliseconds.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_7

        public static final String CREATE_DATE_FORMAT_7
        Format for parsing the create date string: 2004/08/04-07(-0400) which is assumed to be -0400 (Eastern Daylight Time) with 0 minutes, seconds and milliseconds.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_8

        public static final String CREATE_DATE_FORMAT_8
        Format for parsing the create date string: 2004/08/04(-0400) which is assumed to be -0400 (Eastern Daylight Time) at midnight.
        See Also:
        Constant Field Values
      • CREATE_DATE_FORMAT_9

        public static final String CREATE_DATE_FORMAT_9
        Format for parsing the create date string: 2004/08/04T07Z which is assumed to be 07:00:00.000 Zulu (UTC) Time.
        See Also:
        Constant Field Values
      • m_strClassName

        public static final String m_strClassName
      • UNDEFINED_JS4JDate_Milliseconds

        public static final long UNDEFINED_JS4JDate_Milliseconds
        Number of milliseconds past the 1/1/70 midnight epoch used to define an undefined date
        See Also:
        Constant Field Values
      • UNDEFINED_JS4JDate

        public static final JS4JDate UNDEFINED_JS4JDate
        An undefined version of this object. The undefined version is the epoch date + 1 created by newJS4JDate(1).
      • UNDEFINED_JS4JDate_String

        public static final String UNDEFINED_JS4JDate_String
        Intended to be equal to "1970-01-01 00:00:00.000001". That should be the result obtained from the calculation used here. In any case, that calculation should reflect the ways in which the elements involved are related. Note: This form of string for a timestamp can inserted via JDBC into a DB2 field of type Timestamp, but it requires a value that extends to six decimal places for seconds. Values shorter than that may be padded, but that may lead to warnings, if not errors, when loading data (and may complicate other things, as well).
    • Constructor Detail

      • JS4JDate

        public JS4JDate()
        Constructor forJS4JDate using the current date/time.
      • JS4JDate

        public JS4JDate​(Date date)
        Constructor initializing the time to the date supplied.
        Parameters:
        date - the date for thisJS4JDate.
      • JS4JDate

        public JS4JDate​(double dDate)
        Constructor initializing the time to the value supplied.
        Parameters:
        dDate - the number of milliseconds since the epoch (midnight, 1/1/70 0000).
      • JS4JDate

        public JS4JDate​(int iYear,
                        int iMonth,
                        int iDay,
                        int iHours,
                        int iMinutes,
                        int iSeconds,
                        int iMilliseconds,
                        String strTimeZone)
                 throws Exception
        Create anJS4JDate object from the supplied date information.
        Parameters:
        iYear - 2, 3 or 4 digit year. If less than 4 digits, 2000 is added to the supplied value.
        iMonth - number of the month where 1=January, 12=December.
        iDay - number of the day of the month where the first day is 1.
        iHours - hours within the day from 0 through 23.
        iMinutes - minutes within the hour from 0 through 59.
        iSeconds - seconds within the minute from 0 through 59.
        iMilliseconds - milliseconds within the second from 0 through 999.
        strTimeZone - the timezone (e.g., "+0000" is Greenwich Mean Time, "-0400" is Eastern Daylight Time). If no timezone is supplied then "+0000" is used as a default.
        Throws:
        Exception - if the values for Day is invalid for the Month, or if an invalid Timezone is supplied (Exception), or if one of the values is not within their allowed range (ExceptionInvalidParam).
      • JS4JDate

        public JS4JDate​(long lDate)
        Constructor initializing the time to the value supplied.
        Parameters:
        lDate - the number of milliseconds since the epoch (midnight, 1/1/70 0000).
    • Method Detail

      • getHexTime

        public static String getHexTime()
        Returns:
        a String of hexadecimal characters representing the current time in milliseconds. This can be used as a name for temporary assets.
      • isUndefined

        public static boolean isUndefined​(JS4JDate date)
        Tests for equality to the UNDEFINED_JS4JDate which is one millisecond after the epoch date (midnight 1/1/1970 GMT). This is used to identify and/or initialize anJS4JDate value that has yet to receive a valid value. Typically used for comparisons to glean if the value has been set properly.
        Parameters:
        date - the date to be tested to see if it is undefined
        Returns:
        whether (true) or not (false) the supplied date is undefined (meaning it is null or its Date.getTime() returns a value of 1L
        See Also:
        isUndefined(JS4JDate)
      • isUndefined

        public static boolean isUndefined​(Date date)
        Tests for equality to the UNDEFINED_JS4JDate which is one millisecond after the epoch date (midnight 1/1/1970 GMT). This is used to identify and/or initialize anJS4JDate value that has yet to receive a valid value. Typically used for comparisons to glean if the value has been set properly.
        Parameters:
        date - the date to be tested to see if it is undefined
        Returns:
        whether (true) or not (false) the supplied date is undefined (meaning it is null or its Date.getTime() returns a value of 1L
        See Also:
        isUndefined(JS4JDate)
      • makeFormattedDate

        public static String makeFormattedDate​(Date date,
                                               String strFormat,
                                               String strTimeZone)
        Create a formatted string showing the date in the JS4JDate date format for 0000 (Greenwich Mean Time).
        Parameters:
        date - the date to be transformed into the string.
        strFormat - the date format to be returned. If the format is ill defined, the standard JS4JDate Date format is used (CREATE_DATE_FORMAT).
        strTimeZone - the format of the timezone using +/-hhmm
        Returns:
        a formatted string showing the local date in the JS4JDate date format
        See Also:
        CREATE_DATE_FORMAT
      • makeFormattedLocalDate

        public static String makeFormattedLocalDate​(Date date)
        Create a formatted string showing the local date in the JS4JDate date format
        Parameters:
        date - the date to be transformed into the string.
        Returns:
        a formatted string showing the local date in the JS4JDate date format
        See Also:
        CREATE_DATE_FORMAT
      • MAX_TIME

        public static long MAX_TIME()
      • MAX_VALUE

        public static JS4JDate MAX_VALUE()
        Returns:
        the largest date that matches the JS4JDate Date Format for any timezone. The value is the date "9999/12/30-23:59:59.999(+0000)" -- the extra day allows for any timezone to be added and still have a 4 digit year.
      • MIN_VALUE

        public static JS4JDate MIN_VALUE()
        Returns:
        the earliest date that matches the JS4JDate Date Format for any timezone. The value is the date of the epoch "1970/01/01-00:00:00.000(+0000)"
      • parseTimeZoneFromListEntry

        public static String parseTimeZoneFromListEntry​(String strTimeZoneListEntry)
        Find the timezone string by parsing the timezone list entry formed by the getTimeZoneList routine.
        Parameters:
        strTimeZoneListEntry - the timezone list entry from the getTimeZoneList method comprising the timezone offset from GMT followed by a space and then the TimeZone ID. For example, "+0100 Europe/Paris" or "-0500 EST" or "+0000 GMT" would return "+0100", "-0500", or "+0000" respectively.
        Returns:
        the timezone in the form +/-hhmm (e.g., +0000 is GMT, -0500 is Eastern Standard Time, +0100 is Europe/Paris. If the passed timezone list entry is null, empty, or does not comply with the expected format, the GMT timezone "+0000" is returned.
      • undefinedForNull

        public static JS4JDate undefinedForNull​(JS4JDate date)
        Converts the inputJS4JDate to an undefinedJS4JDate if the inputJS4JDate is null.
        Parameters:
        date - JS4JDate to be tested against null and converted.
        Returns:
        An undefinedJS4JDate if the inputJS4JDate was null, otherwise, the inputJS4JDate is echoed back.
      • compareTo

        public int compareTo​(JS4JDate date)
        Compares this date with the supplied date and returns -1 if this date is less than the supplied date, 0 if equal, or 1 if greater than the supplied date.
        Parameters:
        date - the date to compare against this date
        Returns:
        -1 if this date is less than the supplied date, 0 if equal, or 1 if greater than the supplied date.
      • equals

        public boolean equals​(Object obj)
        Overrides:
        equals in class Date
      • getDay

        public long getDay​(String strTimeZone)
        Get the day of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the day applies. If this value is null or empty, "+0000" is used.
        Returns:
        the day of this date for the specified timezone.
      • getHours

        public long getHours​(String strTimeZone)
        Get the hours of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the hours apply. If this value is null or empty, "+0000" is used.
        Returns:
        the hours of this date for the specified timezone.
      • getMilliseconds

        public long getMilliseconds​(String strTimeZone)
        Get the milliseconds of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the milliseconds apply. If this value is null or empty, "+0000" is used.
        Returns:
        the milliseconds of this date for the specified timezone.
      • getMinutes

        public long getMinutes​(String strTimeZone)
        Get the minutesr of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the minutes apply. If this value is null or empty, "+0000" is used.
        Returns:
        the month of this date for the specified timezone.
      • getMonth

        public long getMonth​(String strTimeZone)
        Get the month of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the month applies. If this value is null or empty, "+0000" is used.
        Returns:
        the month of this date for the specified timezone.
      • getSeconds

        public long getSeconds​(String strTimeZone)
        Get the seconds of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the seconds apply. If this value is null or empty, "+0000" is used.
        Returns:
        the seconds of this date for the specified timezone.
      • getYear

        public long getYear​(String strTimeZone)
        Get the year of this date for the specified timezone.
        Parameters:
        strTimeZone - the timezone for which the year applies. If this value is null or empty, "+0000" is used.
        Returns:
        the year of this date for the specified timezone.
      • isUndefined

        public boolean isUndefined()
        Tests for equality to the UNDEFINED_JS4JDate which is one second after the epoch date (midnight 1/1/1970 GMT). This is used to identify and/or initialize anJS4JDate value that has yet to receive a valid value. Typically used for comparisons to glean if the value has been set properly.
        Returns:
        whether (true) or not (false) this object is undefined
        See Also:
        isUndefined(JS4JDate)
      • setDay

        public void setDay​(int iDay,
                           String strTimeZone)
        Set the day of this date to the specified day.
        Parameters:
        iDay - the day of the month (first day is 1).
        strTimeZone - the timezone for which the day applies. If this value is null or empty, "+0000" is used.
      • setHours

        public void setHours​(int iHours,
                             String strTimeZone)
        Set the hours of this date to the specified hours.
        Parameters:
        iHours - the hours within the day (0=midnight).
        strTimeZone - the timezone for which the hours apply. If this value is null or empty, "+0000" is used.
      • setMilliseconds

        public void setMilliseconds​(int iMilliseconds,
                                    String strTimeZone)
        Set the milliseconds of this date to the specified seconds.
        Parameters:
        iMilliseconds - the milliseconds within the second [0..999].
        strTimeZone - the timezone for which the milliseconds apply. If this value is null or empty, "+0000" is used.
      • setMinutes

        public void setMinutes​(int iMinutes,
                               String strTimeZone)
        Set the minutes of this date to the specified minutes.
        Parameters:
        iMinutes - the minutes within the hour [0..59].
        strTimeZone - the timezone for which the minutes apply. If this value is null or empty, "+0000" is used.
      • setMonth

        public void setMonth​(int iMonth,
                             String strTimeZone)
        Set the month of this date to the specified month.
        Parameters:
        iMonth - the one-based counting month number (e.g., 1=January).
        strTimeZone - the timezone for which the month applies. If this value is null or empty, "+0000" is used.
      • setSeconds

        public void setSeconds​(int iSeconds,
                               String strTimeZone)
        Set the seconds of this date to the specified seconds.
        Parameters:
        iSeconds - the seconds within the minute [0..59].
        strTimeZone - the timezone for which the seconds apply. If this value is null or empty, "+0000" is used.
      • setYear

        public void setYear​(int iYear,
                            String strTimeZone)
        Set the year of this date to the specified year.
        Parameters:
        iYear - the complete, 4 digit year (yeah, Y10K bug... ;^)
        strTimeZone - the timezone for which the year applies. If this value is null or empty, "+0000" is used.
      • toDate

        public Date toDate()
      • toString

        public String toString()
        Overrides:
        toString in class Date
        Returns:
        the formatted date using "yyyy-MM-ddTHH:mm:ss.SSS(Z)" where yyyy is the 4 digit year, MM is the 2 digit month, dd is the 2 digit day, HH is the 2 digit hours, mm is the 2 digit minutes, ss is the 2 digit seconds, SSS is the 3 digit milliseconds, and Z is GMT (e.g., +0000). For example, August 4th, 2004 at 7:15:35.456 AM Greenwich Mean Time is "2004-08-04T07:15:35.456Z"
        See Also:
        toString(String)
      • toString

        public String toString​(String strTimeZone)
        Return a String containing formatted date in the specified timezone.
        Parameters:
        strTimeZone - the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "0000-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.
        Returns:
        the formatted date using "yyyy/MM/dd-HH:mm:ss.SSS(Z)" where yyyy is the 4 digit year, MM is the 2 digit month, dd is the 2 digit day, HH is the 2 digit hours, mm is the 2 digit minutes, ss is the 2 digit seconds, SSS is the 3 digit milliseconds, and z is the 3 character timezone. For example, August 4th, 2004 at 7:15:35.456 AM Greenwich Mean Time is "2004/08/04-07:15:35.456(+0000)"
        See Also:
        toString()
      • toString

        public String toString​(String strFormat,
                               String strTimeZone)
        Return a String containing formatted date in the specified timezone.
        Parameters:
        strFormat - the desired date format to be returned. If the format is invalid, the standard JS4JDate Date format is used (CREATE_DATE_FORMAT).
        strTimeZone - the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "0000-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.
        Returns:
        the formatted date using "yyyy/MM/dd-HH:mm:ss.SSS(Z)" where yyyy is the 4 digit year, MM is the 2 digit month, dd is the 2 digit day, HH is the 2 digit hours, mm is the 2 digit minutes, ss is the 2 digit seconds, SSS is the 3 digit milliseconds, and z is the 3 character timezone. For example, August 4th, 2004 at 7:15:35.456 AM Greenwich Mean Time is "2004/08/04-07:15:35.456(0000)"
        See Also:
        toString(), CREATE_DATE_FORMAT
      • toStringCookie

        public String toStringCookie()
        Returns:
        the formatted date using "yyyy-MM-dd HH:mm:ss.SSS" where yyyy is the 4 digit year, MM is the 2 digit month, dd is the 2 digit day, HH is the 2 digit hours, mm is the 2 digit minutes, ss is the 2 digit seconds, SSS is the 3 digit milliseconds in GMT timezone (e.g., +0000). For example, August 4th, 2004 at 7:15:35.456 AM Greenwich Mean Time is "2004-08-04 07:15:35.456"
        See Also:
        toString(String)
      • toStringDateTime

        public String toStringDateTime()
        Returns:
        the formatted date using "yyyy-MM-ddTHH:mm:ss.SSSZ" where yyyy is the 4 digit year, MM is the 2 digit month, dd is the 2 digit day, HH is the 2 digit hours, mm is the 2 digit minutes, ss is the 2 digit seconds, SSS is the 3 digit milliseconds, and , and Z is GMT (e.g., +0000). For example, August 4th, 2004 at 7:15:35.456 AM Greenwich Mean Time is "2004/08/04T07:15:35.456(0000)"
        See Also:
        toString(String)
      • toStringDBTimestamp

        public String toStringDBTimestamp()
        Returns:
        the formatted date using "yyyy-MM-dd HH:mm:ss.SSS" where yyyy is the 4 digit year, MM is the 2 digit month, dd is the 2 digit day, HH is the 2 digit hours, mm is the 2 digit minutes, ss is the 2 digit seconds, SSS is the 3 digit milliseconds in GMT timezone (e.g., +0000). For example, August 4th, 2004 at 7:15:35.456 AM Greenwich Mean Time is "2004-08-04 07:15:35.456"
        See Also:
        toString(String)