Package org.cip4.jdflib.util
Class JDFDate
java.lang.Object
org.cip4.jdflib.util.JDFDate
- All Implemented Interfaces:
Cloneable,Comparable<Object>,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
the date and time are in local time with the respective time zone specified
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringiso - seconds are 0static final Stringiso - seconds + minutes are 0static final Stringiso - seconds + minutes + hours are 0static final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionJDFDate()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.Allocates aJDFDateobject and initializes it so that the JDFDate represents a date set bystrDateTimeFormat ofstrDateTime -
Method Summary
Modifier and TypeMethodDescriptionaddOffset(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 otherbooleanDeprecated.use isLaterbooleanbefore(long other) true, if this is before otherbooleanDeprecated.use isEarlierclone()intintstatic JDFDatecreateDate(String date) factory style constructor that catches all exceptions and returns null if date is invalidcreateDateFromDuration(JDFDuration duration, int hour, int minute) create a date with a relative offset defined in durationbooleanCompares 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.the date formated as defined in ISO 8601
the date is in local time with the respective time zone specifiedreturns the date and time of this in non ISO pattern 'yyyyMMddHHmmss'format the date and time as an ISO 8601 conform String
the date and time are in local time with the respective time zone specifiedDeprecated.use @seegetDateISO()returns the date and time of this in none ISO pattern 'yyyyMMddHHmmss'intgetDay()get the day of month as an integerstatic intgetFormattedDateTime(String format) returns the date and time of this in nonean arbitrary patternintgetHour()intintgetMonth()get the month as an integerintgetTime()Deprecated.longget the time in millisecondsformat the time into a ISO conform String
the time is in local timethe TimeZone as spezified in ISO 8601 +/-10:00 for exampleintintgetYear()get the year as an integerinthashCode()hashCode complements equals() to fulfill the equals/hashCode contractbooleanTests if this date is before the specified date.booleanTests if this date is after the specified date.static booleanstatic voidsetDefaultHour(int defaultHour) Setter for defaultHour attribute.voidsetOffset(int iOffset) Deprecated.use addOffsetsetTime(int h, int m, int s) set the time without modifying the datevoidDeprecated.setTimeInMillis(long l) set this time millisecondssetTimeZoneOffsetInMillis(int timeZoneOffsetInMillis) static voidsetWantISOMilliseconds(boolean wantISOMilliseconds) voidsetYear(int newYear) not performance optimized dirty hack...toString()for debug purposeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
DATEISO
- See Also:
-
DATETIMEISO
- See Also:
-
DATETIMEISO_MILLI
- See Also:
-
DATETIMEISO_0
iso - seconds are 0- See Also:
-
DATETIMEISO_00
iso - seconds + minutes are 0- See Also:
-
DATETIMEISO_000
iso - seconds + minutes + hours are 0- See Also:
-
DATETIMEREADABLE
- See Also:
-
DATENUMERIC_DDMM
- See Also:
-
DATENUMERIC_MMDD
- See Also:
-
DATETIMENUMERIC_DDMM
- See Also:
-
DATETIMENUMERIC_MMDD
- See Also:
-
-
Constructor Details
-
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
- Parameters:
other- the date to clone
-
JDFDate
Allocates 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:
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
- 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
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
for debug purpose -
getFormattedDateTime
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:
IllegalArgumentException
-
getDateTime
returns the date and time of this in non ISO pattern 'yyyyMMddHHmmss'- Returns:
- String - the date in pattern yyyyMMddHHmmss
-
getDateTimeReadable
returns the date and time of this in none ISO pattern 'yyyyMMddHHmmss'- Returns:
- String - the date in pattern yyyyMMddHHmmss
-
setOffset
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
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
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
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.use @seegetDateISO()format the date with no time added- Returns:
- date and time as String of form yyyy-mm-dd
-
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
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
the TimeZone as spezified in ISO 8601 +/-10:00 for example- Returns:
- String: the timezone
-
isLater
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
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
set this time milliseconds- Parameters:
l- time in milliseconds
-
getCalendar
- Returns:
- the GregorianCalendar for this date
-
setTime
set the time without modifying the date- Parameters:
h-m-s-
-
before
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.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.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.why the %&$/ is this called setTime, when it uses a date???- Parameters:
date-
-
equals
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 interfaceComparator<JDFDate>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()hashCode complements equals() to fulfill the equals/hashCode contract -
compareTo
-
setTimeZoneOffsetInMillis
- Parameters:
timeZoneOffsetInMillis- The timeZoneOffsetInMillis to set.
-
getTimeZoneOffsetInMillis
public int getTimeZoneOffsetInMillis()- Returns:
- Returns the timeZoneOffsetInMillis.
-
clone
-
compare
- Specified by:
comparein interfaceComparator<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-
-