Class JDFDate

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, java.util.Comparator<JDFDate>

    public class JDFDate
    extends java.lang.Object
    implements java.lang.Comparable<java.lang.Object>, java.lang.Cloneable, java.util.Comparator<JDFDate>
    class to manipulate date and time according to ISO 8601
    the date and time are in local time with the respective time zone specified
    • Constructor Summary

      Constructors 
      Constructor Description
      JDFDate()
      Allocates a JDFDate object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
      JDFDate​(long iTime)
      Allocates a JDFDate object and initializes it so that it represents the time point, expressed in milliseconds after January 1, 1970, 0:00:00 GMT.
      JDFDate​(java.lang.String strDateTime)
      Allocates a JDFDate object and initializes it so that the JDFDate represents a date set by strDateTime Format of strDateTime
      JDFDate​(java.lang.String strDateTime, int defaultHour, int defaultMinute)  
      JDFDate​(JDFDate other)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      JDFDate addOffset​(int seconds, int minutes, int hours, int days)
      add a given offset to this
      note: multiple calls stack
      boolean after​(long other)
      true, if this is after other
      boolean after​(JDFDate other)
      Deprecated.
      use isLater
      boolean before​(long other)
      true, if this is before other
      boolean before​(JDFDate other)
      Deprecated.
      use isEarlier
      JDFDate clone()  
      int compare​(JDFDate d0, JDFDate d1)  
      int compareTo​(java.lang.Object arg0)  
      static JDFDate createDate​(java.lang.String date)
      factory style constructor that catches all exceptions and returns null if date is invalid
      JDFDate createDateFromDuration​(JDFDuration duration, int hour, int minute)
      create a date with a relative offset defined in duration
      boolean equals​(java.lang.Object other)
      Compares two JDFDates for equality.
      The result is true if and only if the argument is not null and is a JDFDate object that represents the same point in time, to the millisecond, as this object.
      java.util.GregorianCalendar getCalendar()  
      java.lang.String getDateISO()
      the date formated as defined in ISO 8601
      the date is in local time with the respective time zone specified
      java.lang.String getDateTime()
      returns the date and time of this in none ISO pattern 'yyyyMMddHHmmss'
      java.lang.String getDateTimeISO()
      format the date and time as an ISO 8601 conform String
      the date and time are in local time with the respective time zone specified
      java.lang.String getDateTimeISOBD()
      Deprecated.
      use @see getDateISO()
      int getDay()
      get the day of month as an integer
      static int getDefaultHour()  
      java.lang.String getFormattedDateTime​(java.lang.String format)
      returns the date and time of this in nonean arbitrary pattern
      int getHour()  
      int getMinute()  
      int getMonth()
      get the month as an integer
      int getSecond()  
      java.util.Date getTime()
      Deprecated. 
      long getTimeInMillis()
      get the time in milliseconds
      java.lang.String getTimeISO()
      format the time into a ISO conform String
      the time is in local time
      java.lang.String getTimeZoneISO()
      the TimeZone as spezified in ISO 8601 +/-10:00 for example
      int getTimeZoneOffsetInMillis()  
      int getYear()
      get the year as an integer
      int hashCode()
      hashCode complements equals() to fulfill the equals/hashCode contract
      boolean isEarlier​(JDFDate x)
      Tests if this date is before the specified date.
      boolean isLater​(JDFDate x)
      Tests if this date is after the specified date.
      static boolean isWantISOMilliseconds()  
      static void setDefaultHour​(int defaultHour)
      Setter for defaultHour attribute.
      void setOffset​(int iOffset)
      Deprecated.
      use addOffset
      JDFDate setTime​(int h, int m, int s)
      set the time without modifying the date
      void setTime​(java.util.Date date)
      Deprecated. 
      JDFDate setTimeInMillis​(long l)
      set this time milliseconds
      JDFDate setTimeZoneOffsetInMillis​(int timeZoneOffsetInMillis)  
      static void setWantISOMilliseconds​(boolean wantISOMilliseconds)  
      void setYear​(int newYear)
      not performance optimized dirty hack...
      java.lang.String toString()
      for debug purpose
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • DATETIMEISO_MILLI

        public static final java.lang.String DATETIMEISO_MILLI
        See Also:
        Constant Field Values
      • DATETIMEISO_0

        public static final java.lang.String DATETIMEISO_0
        iso - seconds are 0
        See Also:
        Constant Field Values
      • DATETIMEISO_00

        public static final java.lang.String DATETIMEISO_00
        iso - seconds + minutes are 0
        See Also:
        Constant Field Values
      • DATETIMEISO_000

        public static final java.lang.String DATETIMEISO_000
        iso - seconds + minutes + hours are 0
        See Also:
        Constant Field Values
      • DATETIMEREADABLE

        public static final java.lang.String DATETIMEREADABLE
        See Also:
        Constant Field Values
      • DATENUMERIC_DDMM

        public static final java.lang.String DATENUMERIC_DDMM
        See Also:
        Constant Field Values
      • DATENUMERIC_MMDD

        public static final java.lang.String DATENUMERIC_MMDD
        See Also:
        Constant Field Values
      • DATETIMENUMERIC_DDMM

        public static final java.lang.String DATETIMENUMERIC_DDMM
        See Also:
        Constant Field Values
      • DATETIMENUMERIC_MMDD

        public static final java.lang.String DATETIMENUMERIC_MMDD
        See Also:
        Constant Field Values
    • Constructor Detail

      • JDFDate

        public JDFDate()
        Allocates a JDFDate object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond. Also sets the current time zone to the system default time zone
      • JDFDate

        public JDFDate​(long iTime)
        Allocates a JDFDate object and initializes it so that it represents the time point, expressed in milliseconds after January 1, 1970, 0:00:00 GMT. Also sets the current time zone to the system default time zone
        Parameters:
        iTime - current time in milliseconds after January 1, 1970, 0:00:00 GMT. Use JDFDuration instead. This class will be modified to handle only JDFDate objects
      • JDFDate

        public JDFDate​(JDFDate other)
        Parameters:
        other - the date to clone
      • JDFDate

        public JDFDate​(java.lang.String strDateTime)
                throws java.util.zip.DataFormatException
        Allocates a JDFDate object and initializes it so that the JDFDate represents a date set by strDateTime Format of strDateTime

        Valid DataTime Strings are:

      • "yyyy-mm-ddThh:mm:ss.sss+hh:00"
      • "yyyy-mm-ddThh:mm:ss+hh:00"
      • "yyyy-mm-ddThh:mm:ss-hh:00"
      • "yyyy-mm-ddThh:mm:ssZ"
      • Attention!
        you can enter milliseconds, but getDateTimeISO() still returns the time rounded to full seconds. Only long getTimeInMillis() returns the exact time

Parameters:
strDateTime - formatted date and time
Throws:
java.util.zip.DataFormatException - if strDateTime is not a valid DateTime Attention! you can enter milliseconds, but getDateTimeISO() still returns the time rounded to full seconds only long getTimeInMillis() returns the exact time
  • Method Detail

    • isWantISOMilliseconds

      public static boolean isWantISOMilliseconds()
      Returns:
      the wantISOMilliseconds
    • setWantISOMilliseconds

      public static void setWantISOMilliseconds​(boolean wantISOMilliseconds)
      Parameters:
      wantISOMilliseconds - the wantISOMilliseconds to set
    • setDefaultHour

      public static void setDefaultHour​(int defaultHour)
      Setter for defaultHour attribute.
      Parameters:
      defaultHour - the defaultHour to set
    • getDefaultHour

      public static int getDefaultHour()
      Returns:
      the defaultHour
    • createDate

      public static JDFDate createDate​(java.lang.String date)
      factory style constructor that catches all exceptions and returns null if date is invalid
      Parameters:
      date - the formatted date string
      Returns:
      the JDFDate , null if date is not a valid string
    • toString

      public java.lang.String toString()
      for debug purpose
      Overrides:
      toString in class java.lang.Object
      Returns:
      Object informations
    • getFormattedDateTime

      public java.lang.String getFormattedDateTime​(java.lang.String format)
      returns the date and time of this in nonean arbitrary pattern
      Parameters:
      format - the format string using FastDateFormat formatting
      Returns:
      String - the date as specified by the pattern
      Throws:
      java.lang.IllegalArgumentException
    • getDateTime

      public java.lang.String getDateTime()
      returns the date and time of this in none ISO pattern 'yyyyMMddHHmmss'
      Returns:
      String - the date in pattern yyyyMMddHHmmss
    • setOffset

      @Deprecated
      public void setOffset​(int iOffset)
      Deprecated.
      use addOffset
      setOffset: set the offset to this time. Note: The time stored in this is not resetted if you want an offset based on current time use 'public MyDate(int iOffset)'
      Parameters:
      iOffset - offset time in seconds
    • addOffset

      public JDFDate addOffset​(int seconds,
                               int minutes,
                               int hours,
                               int days)
      add a given offset to this
      note: multiple calls stack
      Parameters:
      seconds - seconds to add to this
      minutes - minutes to add to this
      hours - hours to add to this
      days - days to add to this
    • createDateFromDuration

      public JDFDate createDateFromDuration​(JDFDuration duration,
                                            int hour,
                                            int minute)
      create a date with a relative offset defined in duration
      Parameters:
      duration -
      hour - the fixed hour, if -1 don't set
      minute - the fixed minute, if -1 don't set
      Returns:
    • getDateTimeISO

      public java.lang.String getDateTimeISO()
      format the date and time as an ISO 8601 conform String
      the date and time are in local time with the respective time zone specified
      Returns:
      date and time as String of form yyyy-mm-ddThh:mm:ss+zz:00
    • getDateTimeISOBD

      @Deprecated
      public java.lang.String getDateTimeISOBD()
      Deprecated.
      use @see getDateISO()
      format the date with no time added
      Returns:
      date and time as String of form yyyy-mm-dd
    • getDateISO

      public java.lang.String getDateISO()
      the date formated as defined in ISO 8601
      the date is in local time with the respective time zone specified
      Returns:
      String: the date of this of form yyyy-mm-dd
    • getTimeISO

      public java.lang.String getTimeISO()
      format the time into a ISO conform String
      the time is in local time
      Returns:
      String: the time of this ISO 8601 in format hh:mm:ss
    • getTimeZoneISO

      public java.lang.String getTimeZoneISO()
      the TimeZone as spezified in ISO 8601 +/-10:00 for example
      Returns:
      String: the timezone
    • isLater

      public boolean isLater​(JDFDate x)
      Tests if this date is after the specified date.
      Parameters:
      x - the date you wish to know if it is later than this
      Returns:
      true if and only if the instant represented by this Date object is strictly later than the instant represented by x; false otherwise.
    • isEarlier

      public boolean isEarlier​(JDFDate x)
      Tests if this date is before the specified date.
      Parameters:
      x - the date you wish to know if it is eariler than this
      Returns:
      true if and only if the instant of time represented by this Date object is strictly earlier than the instant represented by x; false otherwise.
    • getTimeInMillis

      public long getTimeInMillis()
      get the time in milliseconds
      Returns:
      long - the time in milliseconds
    • setTimeInMillis

      public JDFDate setTimeInMillis​(long l)
      set this time milliseconds
      Parameters:
      l - time in milliseconds
    • getCalendar

      public java.util.GregorianCalendar getCalendar()
      Returns:
      the GregorianCalendar for this date
    • setTime

      public JDFDate setTime​(int h,
                             int m,
                             int s)
      set the time without modifying the date
      Parameters:
      h -
      m -
      s -
    • before

      @Deprecated
      public boolean before​(JDFDate other)
      Deprecated.
      use isEarlier
      true, if this is before other
      Parameters:
      other - the time in milliseconds since 1970 (e.g. from System.currentTimeMillis())
      Returns:
      true if this is before other
    • before

      public boolean before​(long other)
      true, if this is before other
      Parameters:
      other - the time in milliseconds since 1970 (e.g. from System.currentTimeMillis())
      Returns:
      true if this is before other
    • after

      @Deprecated
      public boolean after​(JDFDate other)
      Deprecated.
      use isLater
      true, if this is after other, also true if other==null
      Parameters:
      other -
      Returns:
      true if this date is after other
    • after

      public boolean after​(long other)
      true, if this is after other
      Parameters:
      other - the time in milliseconds since 1970 (e.g. from System.currentTimeMillis())
      Returns:
      true if this date is after other
    • getTime

      @Deprecated
      public java.util.Date getTime()
      Deprecated.
      why the %&$/ is this called getTime, when it returns a date???
      Returns:
    • getMonth

      public int getMonth()
      get the month as an integer
      Returns:
      (1-12)
    • getYear

      public int getYear()
      get the year as an integer
      Returns:
      the year
    • getDay

      public int getDay()
      get the day of month as an integer
      Returns:
      the year
    • setTime

      @Deprecated
      public void setTime​(java.util.Date date)
      Deprecated.
      why the %&$/ is this called setTime, when it uses a date???
      Parameters:
      date -
    • equals

      public boolean equals​(java.lang.Object other)
      Compares two JDFDates for equality.
      The result is true if and only if the argument is not null and is a JDFDate object that represents the same point in time, to the millisecond, as this object.

      Thus, two JDFDate objects are equal if and only if the getTimeInMillis method returns the same long value for both.

      Specified by:
      equals in interface java.util.Comparator<JDFDate>
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      hashCode complements equals() to fulfill the equals/hashCode contract
      Overrides:
      hashCode in class java.lang.Object
    • compareTo

      public int compareTo​(java.lang.Object arg0)
      Specified by:
      compareTo in interface java.lang.Comparable<java.lang.Object>
      See Also:
      the value 0 if the argument is a Date equal to this Date; a value less than 0 if the argument is a Date after this Date; and a value greater than 0 if the argument is a Date before this Date.
    • setTimeZoneOffsetInMillis

      public JDFDate setTimeZoneOffsetInMillis​(int timeZoneOffsetInMillis)
      Parameters:
      timeZoneOffsetInMillis - The timeZoneOffsetInMillis to set.
    • getTimeZoneOffsetInMillis

      public int getTimeZoneOffsetInMillis()
      Returns:
      Returns the timeZoneOffsetInMillis.
    • clone

      public JDFDate clone()
      Overrides:
      clone in class java.lang.Object
      See Also:
      Object.clone()
    • compare

      public int compare​(JDFDate d0,
                         JDFDate d1)
      Specified by:
      compare in interface java.util.Comparator<JDFDate>
      Parameters:
      d0 -
      d1 -
      Returns:
      See Also:
      Comparator.compare(java.lang.Object, java.lang.Object)
    • getHour

      public int getHour()
      Returns:
    • getMinute

      public int getMinute()
      Returns:
    • getSecond

      public int getSecond()
      Returns:
    • setYear

      public void setYear​(int newYear)
      not performance optimized dirty hack...
      Parameters:
      newYear -