Class MDfromHTMLDate

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

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

      • CREATE_DATE_FORMAT

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

        public static 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).
      • CREATE_DATE_FORMAT_1

        public static 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.
      • CREATE_DATE_FORMAT_10

        public static 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).
      • CREATE_DATE_FORMAT_11

        public static 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)
      • CREATE_DATE_FORMAT_12

        public static 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)
      • CREATE_DATE_FORMAT_2

        public static 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.
      • CREATE_DATE_FORMAT_3

        public static 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.
      • CREATE_DATE_FORMAT_4

        public static 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.
      • CREATE_DATE_FORMAT_5

        public static 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.
      • CREATE_DATE_FORMAT_6

        public static 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.
      • CREATE_DATE_FORMAT_7

        public static 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.
      • CREATE_DATE_FORMAT_8

        public static 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.
      • CREATE_DATE_FORMAT_9

        public static 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.
      • m_strClassName

        public static String m_strClassName
      • UNDEFINED_MDfromHTMLDate_Milliseconds

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

        public static final MDfromHTMLDate UNDEFINED_MDfromHTMLDate
        An undefined version of this object. The undefined version is the epoch date + 1 created by newMDfromHTMLDate(1).
      • UNDEFINED_MDfromHTML_DB2_Date_String

        public static final String UNDEFINED_MDfromHTML_DB2_Date_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

      • MDfromHTMLDate

        public MDfromHTMLDate()
        Constructor forMDfromHTMLDate using the current date/time.
      • MDfromHTMLDate

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

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

        public MDfromHTMLDate​(int iYear,
                              int iMonth,
                              int iDay,
                              int iHours,
                              int iMinutes,
                              int iSeconds,
                              int iMilliseconds,
                              String strTimeZone)
                       throws Exception
        Create anMDfromHTMLDate 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).
      • MDfromHTMLDate

        public MDfromHTMLDate​(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.
      • getShortTimeZoneList

        public static String[] getShortTimeZoneList()
        Return a list of timezone values. Each timezone value is followed by the list of timezones to which it relates.
        Returns:
        an array of timezone values followed by a space followed by the list of timezones to which the value applies.
      • getShortTimeZoneList

        public static String[] getShortTimeZoneList​(String strPrefix)
        Return a list of timezone values associated with the supplied prefix. Each timezone value is followed by the list of timezones to which it relates.
        Parameters:
        strPrefix - the prefix to be used as a filter on TimeZones
        Returns:
        an array of timezone values followed by a space followed by the list of timezones to which the value applies.
      • getTimeZoneList

        public static String[] getTimeZoneList()
        Returns:
        a sorted array of Strings containing the TimeZone identifiers, followed by the timezone offset from GMT enclosed in parentheses. For example, there is an entry "America/New_York (-0500)" as well as "EST (-0500)".
      • getTimeZoneList

        public static String[] getTimeZoneList​(String strPrefix)
        Parameters:
        strPrefix - the prefix to be compared against the timezone ID's as a filter. If the timezone id starts with the supplied prefix it will be included in the returned list. If the prefix is null or empty then all ID's will be returned.
        Returns:
        a sorted array of Strings containing the timezone offset from GMT followed by a space then the TimeZone ID. For example, there is an entry "-0500 America/New_York" as well as "-0500 EST" as well as "+0000 GMT" and "+0100 Europe/Paris".
      • isUndefined

        public static boolean isUndefined​(MDfromHTMLDate date)
        Tests for equality to the UNDEFINED_MDfromHTMLDate which is one millisecond after the epoch date (midnight 1/1/1970 GMT). This is used to identify and/or initialize anMDfromHTMLDate 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(MDfromHTMLDate)
      • isUndefined

        public static boolean isUndefined​(Date date)
        Tests for equality to the UNDEFINED_MDfromHTMLDate which is one millisecond after the epoch date (midnight 1/1/1970 GMT). This is used to identify and/or initialize anMDfromHTMLDate 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(MDfromHTMLDate)
      • main

        public static void main​(String[] args)
      • makeFormattedDate

        public static String makeFormattedDate​(Date date,
                                               String strFormat,
                                               String strTimeZone)
        Create a formatted string showing the date in theMDfromHTML 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 illdefined, the standardMDfromHTML Date format is used (CREATE_DATE_FORMAT).
        strTimeZone - the format of the timezone using +/-hhmm
        Returns:
        a formatted string showing the local date in theMDfromHTML date format
        See Also:
        CREATE_DATE_FORMAT
      • makeFormattedLocalDate

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

        public static long MAX_TIME()
      • MAX_VALUE

        public static MDfromHTMLDate MAX_VALUE()
        Returns:
        the largest date that matches theMDfromHTML 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 MDfromHTMLDate MIN_VALUE()
        Returns:
        the earliest date that matches theMDfromHTML 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 MDfromHTMLDate undefinedForNull​(MDfromHTMLDate date)
        Converts the inputMDfromHTMLDate to an undefinedMDfromHTMLDate if the inputMDfromHTMLDate is null.
        Parameters:
        date - MDfromHTMLDate to be tested against null and converted.
        Returns:
        An undefinedMDfromHTMLDate if the inputMDfromHTMLDate was null, otherwise, the inputMDfromHTMLDate is echoed back.
      • compareTo

        public int compareTo​(MDfromHTMLDate 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.
      • elapsedTime

        public long elapsedTime​(MDfromHTMLDate dateFrom)
        Calculate the number of elapsed milliseconds between the supplied date and this date. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of milliseconds since the epoch (midnight 1/1/70 0000) until the end date. If the start date is greater than the end date, then 0L is returned.
        Parameters:
        dateFrom - the date from which the elapsed time is calculated (e.g., until this date).
        Returns:
        the number of elapsed milliseconds between the start and end of this duration.
      • elapsedTime

        public long elapsedTime​(Date dateFrom)
        Calculate the number of elapsed milliseconds between the supplied date and this date. If no end date has been set, then the duration is 0L. If no start date has been set, then the duration is the number of milliseconds since the epoch (midnight 1/1/70 0000) until the end date. If the start date is greater than the end date, then 0L is returned.
        Parameters:
        dateFrom - the date from which the elapsed time is calculated (e.g., until this date).
        Returns:
        the number of elapsed milliseconds between the start and end of this duration.
      • 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_MDfromHTMLDate which is one second after the epoch date (midnight 1/1/1970 GMT). This is used to identify and/or initialize anMDfromHTMLDate 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(MDfromHTMLDate)
      • 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 standardMDfromHTML 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)