Class CDateTime

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<com.ibm.icu.util.Calendar>

    public class CDateTime
    extends com.ibm.icu.util.GregorianCalendar
    A convenience data type provided to aid in wrapping a datetime value used with datetime data elements. Refer to DateTimeDataElement
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.ibm.icu.util.Calendar

        com.ibm.icu.util.Calendar.FormatConfiguration, com.ibm.icu.util.Calendar.WeekData
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DAY_OF_QUARTER  
      static int QUARTER  
      static int WEEK_OF_QUARTER  
      • Fields inherited from class com.ibm.icu.util.GregorianCalendar

        AD, BC
      • Fields inherited from class com.ibm.icu.util.Calendar

        AM, AM_PM, APRIL, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DOW_LOCAL, DST_OFFSET, ERA, EXTENDED_YEAR, FEBRUARY, FRIDAY, HOUR, HOUR_OF_DAY, IS_LEAP_MONTH, JANUARY, JULIAN_DAY, JULY, JUNE, MARCH, MAY, MILLISECOND, MILLISECONDS_IN_DAY, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, WALLTIME_FIRST, WALLTIME_LAST, WALLTIME_NEXT_VALID, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, WEEKDAY, WEEKEND, WEEKEND_CEASE, WEEKEND_ONSET, YEAR, YEAR_WOY, ZONE_OFFSET
    • Constructor Summary

      Constructors 
      Constructor Description
      CDateTime()
      A zero-arg default constructor
      CDateTime​(int year, int month, int date)
      A constructor that creates an instance for a specified year, month and date
      CDateTime​(int year, int month, int date, int hour, int minute)
      A constructor that creates an instance for a specified year, month, date, hour and minute
      CDateTime​(int year, int month, int date, int hour, int minute, int second)
      A constructor that creates an instance for a specified year, month, date, hour and minute
      CDateTime​(long lTimeInMillis)
      A constructor that creates an instance from a given long value
      CDateTime​(com.ibm.icu.util.Calendar c)
      A constructor that creates an instance from a given Calendar value
      CDateTime​(com.ibm.icu.util.TimeZone tz)
      A constructor that creates a default instance for a given timezone
      CDateTime​(com.ibm.icu.util.TimeZone tz, com.ibm.icu.util.ULocale locale)
      A constructor that creates a default instance for a given timezone and locale
      CDateTime​(com.ibm.icu.util.TimeZone tz, java.util.Locale locale)
      Deprecated.
      CDateTime​(com.ibm.icu.util.ULocale locale)
      A constructor that creates a default instance for a given locale
      CDateTime​(java.util.Date d)
      A constructor that creates an instance from a given java.util.Date value.
      CDateTime​(java.util.Locale aLocale)
      Deprecated.
      use CDateTime(ULocale) instead.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int unit, int step)  
      boolean after​(java.lang.Object when)  
      CDateTime backward​(int iUnit, int iStep)
      A convenient method used in building the ticks for a datetime scale.
      boolean before​(java.lang.Object when)  
      void clearAbove​(int iUnit)
      Reset all units for this datetime instance above a specified unit.
      void clearAbove​(int iUnit, boolean always)
      Reset all units for this datetime instance above a specified unit.
      void clearBelow​(int iUnit)
      Zeroes out all units for this datetime instance below a specified unit.
      void clearBelow​(int iUnit, boolean always)
      Zeroes out all units for this datetime instance below a specified unit.
      static double computeDifference​(CDateTime cdt1, CDateTime cdt2, int iUnit)
      Computes the difference between two given datetime values as a fraction for the requested field.
      static double computeDifference​(CDateTime cdt1, CDateTime cdt2, int iUnit, boolean trimBelow)
      Computes the difference between two given datetime values as a fraction for the requested field.
      static int computeUnit​(DataSetIterator dsi)
      Walks through all values in a dataset and computes the least significant unit for which a difference was noted.
      static int computeUnit​(CDateTime[] cdta)
      Walks through all values in a datetime array and computes the least significant unit for which a difference was noted.
      CDateTime forward​(int iUnit, int iStep)
      A convenient method used in building the ticks for a datetime scale.
      java.util.Date getDateTime()  
      int getDay()
      Returns the day of the month associated with this instance
      static int getDifference​(CDateTime cdt1, CDateTime cdt2)
      Returns the most significant datetime unit in which there's a difference or 0 if there is no difference.
      int getHour()
      Returns the hour (military) associated with this instance
      static int getMaximumDaysIn​(int iYear)
      Returns the number of days for a particular year
      static int getMaximumDaysIn​(int iMonth, int iYear)
      Returns the number of days for a particular (month,year) combination
      int getMinute()
      Returns the minute associated with this instance
      int getMonth()
      Returns the month (0-based) associated with this instance
      static java.lang.String getPreferredFormat​(int iUnit)
      Returns a preferred format specifier for tick labels that represent axis values that will be computed based on the difference between cdt1 and cdt2
      static int getPreferredUnit​(CDateTime minDateTime, CDateTime maxDateTime)
      Returns a preferred format specifier for given data-time values will be computed based on the difference between minDateTime and maxDateTime
      int getSecond()
      Returns the second associated with this instance
      CDateTime getUnitStart​(int iUnit)
      returns a CDateTime, whose value equals to the unit start of the current instance
      int getYear()
      Returns the year associated with this instance
      static double inMillis​(int iUnit)
      A convenience method provided to return the number of milliseconds available in a given unit
      boolean isFullDateTime()
      Represents if current value has both Date and Time.
      boolean isTimeOnly()
      The property timeOnly indicates that this instance of CDateTime only represents a Time value, the Date value will be ignored.
      static CDateTime parse​(java.lang.String sDateTimeValue)
      Parses a value formatted as MM-dd-yyyy HH:mm:ss and attempts to create an instance of this object
      void setTimeOnly​(boolean timeOnly)
      The property timeOnly indicates that this instance of CDateTime only represents a Time value, the Date value will be ignored.
      java.lang.String toString()  
      • Methods inherited from class com.ibm.icu.util.GregorianCalendar

        getActualMaximum, getActualMinimum, getGregorianChange, getType, hashCode, isEquivalentTo, isLeapYear, roll, setGregorianChange
      • Methods inherited from class com.ibm.icu.util.Calendar

        clear, clear, clone, compareTo, equals, fieldDifference, get, getAvailableLocales, getAvailableULocales, getDateTimeFormat, getDateTimeFormat, getDateTimePattern, getDayOfWeekType, getDisplayName, getDisplayName, getFieldCount, getFirstDayOfWeek, getGreatestMinimum, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getKeywordValuesForLocale, getLeastMaximum, getLocale, getMaximum, getMinimalDaysInFirstWeek, getMinimum, getRelatedYear, getRepeatedWallTimeOption, getSkippedWallTimeOption, getTime, getTimeInMillis, getTimeZone, getWeekData, getWeekDataForRegion, getWeekendTransition, haveDefaultCentury, isLenient, isSet, isWeekend, isWeekend, roll, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setRelatedYear, setRepeatedWallTimeOption, setSkippedWallTimeOption, setTime, setTimeInMillis, setTimeZone, setWeekData
      • Methods inherited from class java.lang.Object

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

      • CDateTime

        public CDateTime()
        A zero-arg default constructor
      • CDateTime

        public CDateTime​(java.util.Date d)
        A constructor that creates an instance from a given java.util.Date value. If it's an instance of java.sql.Date, it's Date only data. If it's an instance of java.sql.Time, it's Time only data. Otherwise, it means full date time value.
        Parameters:
        d - A previously defined Date instance
      • CDateTime

        public CDateTime​(com.ibm.icu.util.Calendar c)
        A constructor that creates an instance from a given Calendar value
        Parameters:
        c - A previously defined Calendar instance
      • CDateTime

        public CDateTime​(long lTimeInMillis)
        A constructor that creates an instance from a given long value
        Parameters:
        lTimeInMillis - The time defined in milliseconds
      • CDateTime

        public CDateTime​(int year,
                         int month,
                         int date)
        A constructor that creates an instance for a specified year, month and date
        Parameters:
        year - The year associated with this instance
        month - The month index (1-12) of the year (1-based)
        date - The day of the month associated with this instance
      • CDateTime

        public CDateTime​(int year,
                         int month,
                         int date,
                         int hour,
                         int minute)
        A constructor that creates an instance for a specified year, month, date, hour and minute
        Parameters:
        year - The year associated with this instance
        month - The month index (1-12) of the year (1-based)
        date - The day of the month associated with this instance
        hour - The hour (0-23) of the day (military) associated with this instance
        minute - The minute (0-59) of the hour associated with this instance
      • CDateTime

        public CDateTime​(int year,
                         int month,
                         int date,
                         int hour,
                         int minute,
                         int second)
        A constructor that creates an instance for a specified year, month, date, hour and minute
        Parameters:
        year - The year associated with this instance
        month - The month index (1-12) of the year (1-based)
        date - The day of the month associated with this instance
        hour - The hour (0-23) of the day (military) associated with this instance
        minute - The minute (0-59) of the hour associated with this instance
        second - The second (0-59) of the minute associated with this instance
      • CDateTime

        @Deprecated
        public CDateTime​(java.util.Locale aLocale)
        Deprecated.
        use CDateTime(ULocale) instead.
        A constructor that creates a default instance for a given locale
        Parameters:
        locale - The locale for which the instance is being created
      • CDateTime

        public CDateTime​(com.ibm.icu.util.ULocale locale)
        A constructor that creates a default instance for a given locale
        Parameters:
        locale - The locale for which the instance is being created
        Since:
        2.1
      • CDateTime

        public CDateTime​(com.ibm.icu.util.TimeZone tz)
        A constructor that creates a default instance for a given timezone
        Parameters:
        tz - The timezone for which the instance is being created
      • CDateTime

        @Deprecated
        public CDateTime​(com.ibm.icu.util.TimeZone tz,
                         java.util.Locale locale)
        Deprecated.
        A constructor that creates a default instance for a given timezone and locale
        Parameters:
        tz - The timezone for which the instance is being created
        locale - The locale for which the instance is being created
      • CDateTime

        public CDateTime​(com.ibm.icu.util.TimeZone tz,
                         com.ibm.icu.util.ULocale locale)
        A constructor that creates a default instance for a given timezone and locale
        Parameters:
        tz - The timezone for which the instance is being created
        locale - The locale for which the instance is being created
    • Method Detail

      • backward

        public CDateTime backward​(int iUnit,
                                  int iStep)
        A convenient method used in building the ticks for a datetime scale. Computes a new datetime object relative to the existing one moving back by 'step' units.
        Parameters:
        iUnit -
        iStep -
        Returns:
        new instance
      • forward

        public CDateTime forward​(int iUnit,
                                 int iStep)
        A convenient method used in building the ticks for a datetime scale. Computes a new datetime object relative to the existing one moving forward by 'step' units.
        Parameters:
        iUnit -
        iStep -
        Returns:
        new instance
      • getYear

        public final int getYear()
        Returns the year associated with this instance
        Returns:
        The year associated with this instance
      • getMonth

        public final int getMonth()
        Returns the month (0-based) associated with this instance
        Returns:
        The month associated with this instance
      • getDay

        public final int getDay()
        Returns the day of the month associated with this instance
        Returns:
        The day of the month associated with this instance
      • getHour

        public final int getHour()
        Returns the hour (military) associated with this instance
        Returns:
        The hour associated with this instance
      • getMinute

        public final int getMinute()
        Returns the minute associated with this instance
        Returns:
        The minute associated with this instance
      • getSecond

        public final int getSecond()
        Returns the second associated with this instance
        Returns:
        The second associated with this instance
      • getDifference

        public static final int getDifference​(CDateTime cdt1,
                                              CDateTime cdt2)
        Returns the most significant datetime unit in which there's a difference or 0 if there is no difference.
        Returns:
        The least significant 'Calendar' unit in which a difference occurred
      • getPreferredFormat

        public static final java.lang.String getPreferredFormat​(int iUnit)
        Returns a preferred format specifier for tick labels that represent axis values that will be computed based on the difference between cdt1 and cdt2
        Parameters:
        iUnit - The unit for which a preferred pattern is being requested
        Returns:
        A preferred datetime format pattern for the given unit
      • getPreferredUnit

        public static final int getPreferredUnit​(CDateTime minDateTime,
                                                 CDateTime maxDateTime)
        Returns a preferred format specifier for given data-time values will be computed based on the difference between minDateTime and maxDateTime
        Parameters:
        minDateTime - The minimum data-time value
        maxDateTime - The maximum data-time value
        Returns:
        A preferred datetime unit for the given values
      • computeDifference

        public static final double computeDifference​(CDateTime cdt1,
                                                     CDateTime cdt2,
                                                     int iUnit)
        Computes the difference between two given datetime values as a fraction for the requested field.
        Parameters:
        cdt1 - The first datetime value
        cdt2 - The second datetime value
        iUnit - The field with respect to which the difference is being computed as a fraction
        Returns:
        The fractional difference between the two specified datetime values
      • computeDifference

        public static final double computeDifference​(CDateTime cdt1,
                                                     CDateTime cdt2,
                                                     int iUnit,
                                                     boolean trimBelow)
        Computes the difference between two given datetime values as a fraction for the requested field.
        Parameters:
        cdt1 - The first datetime value
        cdt2 - The second datetime value
        iUnit - The field with respect to which the difference is being computed as a fraction
        trimBelow - Specifies if trim the unit below the given unit.
        Returns:
        The fractional difference between the two specified datetime values
      • computeUnit

        public static final int computeUnit​(DataSetIterator dsi)
        Walks through all values in a dataset and computes the least significant unit for which a difference was noted.
        Parameters:
        dsi - The dataset iterator that facilitates visiting individual values
        Returns:
        The least significant unit for which a difference in datetime values was noted
      • computeUnit

        public static final int computeUnit​(CDateTime[] cdta)
                                     throws ChartException
        Walks through all values in a datetime array and computes the least significant unit for which a difference was noted.
        Parameters:
        cdta - A datetime array for which the least significant unit difference is to be computed
        Returns:
        The least significant unit for which a difference in datetime values was noted
        Throws:
        ChartException
      • getMaximumDaysIn

        public static final int getMaximumDaysIn​(int iMonth,
                                                 int iYear)
        Returns the number of days for a particular (month,year) combination
        Parameters:
        iMonth - The month (0-11) for which the day count is to be retrieved
        iYear - The year for which the day count is to be retrieved
        Returns:
        number of days
      • getMaximumDaysIn

        public static final int getMaximumDaysIn​(int iYear)
        Returns the number of days for a particular year
        Parameters:
        iYear - The year for which the day count is to be retrieved
        Returns:
        The number of days in the specified year
      • inMillis

        public static final double inMillis​(int iUnit)
        A convenience method provided to return the number of milliseconds available in a given unit
        Parameters:
        iUnit - The unit for which the number of milliseconds are to be computed
        Returns:
        The number of milliseconds for the specified unit
      • clearBelow

        public final void clearBelow​(int iUnit)
        Zeroes out all units for this datetime instance below a specified unit. If it's full date time, no trim because original value should be used to format using time zone.
        Parameters:
        iUnit - The unit below which all values are to be zeroed out
      • clearBelow

        public final void clearBelow​(int iUnit,
                                     boolean always)
        Zeroes out all units for this datetime instance below a specified unit.
        Parameters:
        iUnit - The unit below which all values are to be zeroed out
        always - indicates if it's always trimmed no matter if it's full date time
      • clearAbove

        public final void clearAbove​(int iUnit)
        Reset all units for this datetime instance above a specified unit.
        Parameters:
        iUnit - The unit above which year values are to be reset
      • clearAbove

        public final void clearAbove​(int iUnit,
                                     boolean always)
        Reset all units for this datetime instance above a specified unit.
        Parameters:
        iUnit - The unit above which year values are to be reset
        always - indicates if it's always trimmed no matter if it's full date time
      • getUnitStart

        public CDateTime getUnitStart​(int iUnit)
        returns a CDateTime, whose value equals to the unit start of the current instance
        Parameters:
        iUnit -
        Returns:
        new instance
      • parse

        public static CDateTime parse​(java.lang.String sDateTimeValue)
        Parses a value formatted as MM-dd-yyyy HH:mm:ss and attempts to create an instance of this object
        Parameters:
        sDateTimeValue - The value to be parsed
        Returns:
        An instance of the datetime value created
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class com.ibm.icu.util.Calendar
      • after

        public boolean after​(java.lang.Object when)
        Overrides:
        after in class com.ibm.icu.util.Calendar
      • before

        public boolean before​(java.lang.Object when)
        Overrides:
        before in class com.ibm.icu.util.Calendar
      • isTimeOnly

        public boolean isTimeOnly()
        The property timeOnly indicates that this instance of CDateTime only represents a Time value, the Date value will be ignored.
        Returns:
        true if time only.
      • isFullDateTime

        public boolean isFullDateTime()
        Represents if current value has both Date and Time. If yes, Timezone will be considered during formatting.
        Returns:
        true if current value has both Date and Time
      • setTimeOnly

        public void setTimeOnly​(boolean timeOnly)
        The property timeOnly indicates that this instance of CDateTime only represents a Time value, the Date value will be ignored.
        Parameters:
        timeOnly - The bTimeOnly to set.
      • add

        public void add​(int unit,
                        int step)
        Overrides:
        add in class com.ibm.icu.util.Calendar
      • getDateTime

        public java.util.Date getDateTime()