Class JDFDate

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

public class JDFDate extends Object implements Comparable<Object>, Cloneable, 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
  • Field Details

  • Constructor Details

    • 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(String strDateTime) throws 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:
      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
    • JDFDate

      public JDFDate(String strDateTime, int defaultHour, int defaultMinute) throws DataFormatException
      Throws:
      DataFormatException
  • Method Details

    • 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(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 String toString()
      for debug purpose
      Overrides:
      toString in class Object
      Returns:
      Object informations
    • getFormattedDateTime

      public String getFormattedDateTime(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:
      IllegalArgumentException
    • getDateTime

      public String getDateTime()
      returns the date and time of this in non ISO pattern 'yyyyMMddHHmmss'
      Returns:
      String - the date in pattern yyyyMMddHHmmss
    • getDateTimeReadable

      public String getDateTimeReadable()
      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 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 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 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 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 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 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 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(Date date)
      Deprecated.
      why the %&$/ is this called setTime, when it uses a date???
      Parameters:
      date -
    • equals

      public boolean equals(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 Comparator<JDFDate>
      Overrides:
      equals in class Object
    • hashCode

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

      public int compareTo(Object arg0)
      Specified by:
      compareTo in interface Comparable<Object>
      See Also:
    • 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 Object
      See Also:
    • compare

      public int compare(JDFDate d0, JDFDate d1)
      Specified by:
      compare in interface Comparator<JDFDate>
      Parameters:
      d0 -
      d1 -
      Returns:
      See Also:
    • 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 -