Package org.cip4.jdflib.util
Class JDFDate
- java.lang.Object
-
- org.cip4.jdflib.util.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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDATEISOstatic java.lang.StringDATENUMERIC_DDMMstatic java.lang.StringDATENUMERIC_MMDDstatic java.lang.StringDATETIMEISOstatic java.lang.StringDATETIMEISO_0iso - seconds are 0static java.lang.StringDATETIMEISO_00iso - seconds + minutes are 0static java.lang.StringDATETIMEISO_000iso - seconds + minutes + hours are 0static java.lang.StringDATETIMEISO_MILLIstatic java.lang.StringDATETIMENUMERIC_DDMMstatic java.lang.StringDATETIMENUMERIC_MMDDstatic java.lang.StringDATETIMEREADABLE
-
Constructor Summary
Constructors Constructor Description JDFDate()Allocates aJDFDateobject and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.JDFDate(long iTime)Allocates aJDFDateobject 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 aJDFDateobject and initializes it so that the JDFDate represents a date set bystrDateTimeFormat ofstrDateTimeJDFDate(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 JDFDateaddOffset(int seconds, int minutes, int hours, int days)add a given offset to this
note: multiple calls stackbooleanafter(long other)true, if this is after otherbooleanafter(JDFDate other)Deprecated.use isLaterbooleanbefore(long other)true, if this is before otherbooleanbefore(JDFDate other)Deprecated.use isEarlierJDFDateclone()intcompare(JDFDate d0, JDFDate d1)intcompareTo(java.lang.Object arg0)static JDFDatecreateDate(java.lang.String date)factory style constructor that catches all exceptions and returns null if date is invalidJDFDatecreateDateFromDuration(JDFDuration duration, int hour, int minute)create a date with a relative offset defined in durationbooleanequals(java.lang.Object other)Compares two JDFDates for equality.
The result istrueif and only if the argument is notnulland is aJDFDateobject that represents the same point in time, to the millisecond, as this object.java.util.GregorianCalendargetCalendar()java.lang.StringgetDateISO()the date formated as defined in ISO 8601
the date is in local time with the respective time zone specifiedjava.lang.StringgetDateTime()returns the date and time of this in non ISO pattern 'yyyyMMddHHmmss'java.lang.StringgetDateTimeISO()format the date and time as an ISO 8601 conform String
the date and time are in local time with the respective time zone specifiedjava.lang.StringgetDateTimeISOBD()Deprecated.use @seegetDateISO()java.lang.StringgetDateTimeReadable()returns the date and time of this in none ISO pattern 'yyyyMMddHHmmss'intgetDay()get the day of month as an integerstatic intgetDefaultHour()java.lang.StringgetFormattedDateTime(java.lang.String format)returns the date and time of this in nonean arbitrary patternintgetHour()intgetMinute()intgetMonth()get the month as an integerintgetSecond()java.util.DategetTime()Deprecated.longgetTimeInMillis()get the time in millisecondsjava.lang.StringgetTimeISO()format the time into a ISO conform String
the time is in local timejava.lang.StringgetTimeZoneISO()the TimeZone as spezified in ISO 8601 +/-10:00 for exampleintgetTimeZoneOffsetInMillis()intgetYear()get the year as an integerinthashCode()hashCode complements equals() to fulfill the equals/hashCode contractbooleanisEarlier(JDFDate x)Tests if this date is before the specified date.booleanisLater(JDFDate x)Tests if this date is after the specified date.static booleanisWantISOMilliseconds()static voidsetDefaultHour(int defaultHour)Setter for defaultHour attribute.voidsetOffset(int iOffset)Deprecated.use addOffsetJDFDatesetTime(int h, int m, int s)set the time without modifying the datevoidsetTime(java.util.Date date)Deprecated.JDFDatesetTimeInMillis(long l)set this time millisecondsJDFDatesetTimeZoneOffsetInMillis(int timeZoneOffsetInMillis)static voidsetWantISOMilliseconds(boolean wantISOMilliseconds)voidsetYear(int newYear)not performance optimized dirty hack...java.lang.StringtoString()for debug purpose
-
-
-
Field Detail
-
DATEISO
public static final java.lang.String DATEISO
- See Also:
- Constant Field Values
-
DATETIMEISO
public static final java.lang.String DATETIMEISO
- See Also:
- Constant Field Values
-
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 aJDFDateobject 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 aJDFDateobject 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.DataFormatExceptionAllocates aJDFDateobject and initializes it so that the JDFDate represents a date set bystrDateTimeFormat ofstrDateTimeValid 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, butgetDateTimeISO()still returns the time rounded to full seconds. Onlylong 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
-
JDFDate
public JDFDate(java.lang.String strDateTime, int defaultHour, int defaultMinute) throws java.util.zip.DataFormatException- Throws:
java.util.zip.DataFormatException
-
-
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:
toStringin classjava.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 usingFastDateFormatformatting- 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 non ISO pattern 'yyyyMMddHHmmss'- Returns:
- String - the date in pattern yyyyMMddHHmmss
-
getDateTimeReadable
public java.lang.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 addOffsetsetOffset: 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 thisminutes- minutes to add to thishours- hours to add to thisdays- 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 setminute- 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 @seegetDateISO()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 isEarliertrue, 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 isLatertrue, 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 istrueif and only if the argument is notnulland is aJDFDateobject that represents the same point in time, to the millisecond, as this object.Thus, two
JDFDateobjects are equal if and only if thegetTimeInMillismethod returns the samelongvalue for both.- Specified by:
equalsin interfacejava.util.Comparator<JDFDate>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
hashCode complements equals() to fulfill the equals/hashCode contract- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public int compareTo(java.lang.Object arg0)
- Specified by:
compareToin interfacejava.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:
clonein classjava.lang.Object- See Also:
Object.clone()
-
compare
public int compare(JDFDate d0, JDFDate d1)
- Specified by:
comparein interfacejava.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-
-
-