Package org.cyclos.utils
Class DateTime
- java.lang.Object
-
- org.cyclos.utils.DateTime
-
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<DateTime>,IDate
public class DateTime extends Object implements IDate, Comparable<DateTime>, Cloneable, Serializable
Mutable class used to represent dates in the Cyclos API instead ofDate.
It represents a specific instant in time in a specific time zone (e.g.: the client TZ) with millisecond precision. It works in 'lenient' mode similar to the corresponding Calendar's mode with the difference that for inconsistent fields no exception is thrown.- Year
- Month (month of year):valid values are in the range 0 (January) - 11 (December)
- Date (day of month): valid values are in the range 1-31
- Hours (hour in day): valid values are in the range 0-23
- Minutes: valid values are in the range 0-59
- Seconds: valid values are in the range 0-59
- Milliseconds: (within the second) valid values are in the range 0-999
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringCLASS_NAMEstatic Comparator<DateTime>COMPARATORstatic intMAX_HOURstatic intMAX_MILLISECONDstatic intMAX_MINUTEstatic intMAX_MONTHstatic intMAX_SECONDstatic intMAX_YEAR
-
Constructor Summary
Constructors Constructor Description DateTime()DateTime(int year, int month, int date)Constructs aDateTimewith zero in the time fields (HMS).DateTime(int year, int month, int date, int hours, int minutes)Constructs aDateTimewith zero in the time fields (HMS).DateTime(int year, int month, int date, int hours, int minutes, int seconds)Constructs aDateTimewith zero in the time fields (HMS).DateTime(int year, int month, int date, int hours, int minutes, int seconds, int millis)Constructs aDateTimewith all its fields initialized.DateTime(int year, int month, int date, int hours, int minutes, int seconds, int millis, String timeZone)Constructs aDateTimewith all its fields initialized.DateTime(String string)DateTime(String string, boolean fillToDayEnd)DateTime(OffsetDateTime dt)Constructs aDateTimefrom anOffsetDateTimeDateTime(ZonedDateTime zdt)Constructs aDateTimefrom aZonedDateTime
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DateTimeadd(long elapsed)Adds the given number of milliseconds to this date time objectbooleanafter(DateTime dt)booleanafterOrEquals(DateTime dt)booleanbefore(DateTime dt)booleanbeforeOrEquals(DateTime dt)DateTimeclone()intcompareTo(DateTime dt)DateTimedecDate()DateTimedecMonth()DateTimedecYear()DateTimeduplicate()Makes a copy of this instance.booleanequals(Object obj)intgetDate()intgetHours()intgetMilliseconds()intgetMinutes()intgetMonth()intgetSeconds()StringgetTimeZone()intgetYear()inthashCode()DateTimeincDate()DateTimeincMonth()DateTimeincYear()booleanisSameDay(DateTime dt)static DateTimeof(OffsetDateTime dt)Null-safe conversion fromOffsetDateTimetoDateTimestatic DateTimeparse(String string)Parses the given String as aDateTime, returning null for blank stringsvoidsetDate(int date)Sets the day of the month.voidsetHMSM(int hours, int minutes, int seconds, int milliseconds)Sets only the time part (H=hours, M=minutes, S=seconds, M=milliseconds) without changing the date part (YMD)voidsetHours(int hours)voidsetMilliseconds(int milliseconds)voidsetMinutes(int minutes)voidsetMonth(int month)voidsetSeconds(int seconds)voidsetTimeZone(String timeZone)voidsetYear(int year)voidsetYMD(int year, int month, int date)Sets only the date part (Y=year, M=month, D=date (day of month)) without change the time part (HMS)StringtoDateString()LocalDatetoLocalDate()LocalDateTimetoLocalDateTime()OffsetDateTimetoOffsetDateTime(ZoneId zoneId)StringtoString()StringtoTimeString()
-
-
-
Field Detail
-
CLASS_NAME
public static final String CLASS_NAME
- See Also:
- Constant Field Values
-
COMPARATOR
public static final Comparator<DateTime> COMPARATOR
-
MAX_YEAR
public static final int MAX_YEAR
- See Also:
- Constant Field Values
-
MAX_MONTH
public static final int MAX_MONTH
- See Also:
- Constant Field Values
-
MAX_HOUR
public static final int MAX_HOUR
- See Also:
- Constant Field Values
-
MAX_MINUTE
public static final int MAX_MINUTE
- See Also:
- Constant Field Values
-
MAX_SECOND
public static final int MAX_SECOND
- See Also:
- Constant Field Values
-
MAX_MILLISECOND
public static final int MAX_MILLISECOND
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DateTime
public DateTime()
-
DateTime
public DateTime(int year, int month, int date)Constructs aDateTimewith zero in the time fields (HMS).
-
DateTime
public DateTime(int year, int month, int date, int hours, int minutes)Constructs aDateTimewith zero in the time fields (HMS).
-
DateTime
public DateTime(int year, int month, int date, int hours, int minutes, int seconds)Constructs aDateTimewith zero in the time fields (HMS).
-
DateTime
public DateTime(int year, int month, int date, int hours, int minutes, int seconds, int millis)Constructs aDateTimewith all its fields initialized.
-
DateTime
public DateTime(int year, int month, int date, int hours, int minutes, int seconds, int millis, String timeZone)Constructs aDateTimewith all its fields initialized.- Parameters:
month- it must be between 0 and 11 (same asDate)date- it must be between 1 and 31 (same asDate)hours- it must be between 0 and 23 (Hour in day)minutes- it must be between 0 and 59seconds- it must be between 0 and 59millis- it must be between 0 and 999timeZone- the timezone. Null means resolving the current user's configured timezone
-
DateTime
public DateTime(OffsetDateTime dt)
Constructs aDateTimefrom anOffsetDateTime
-
DateTime
public DateTime(String string)
-
DateTime
public DateTime(String string, boolean fillToDayEnd)
-
DateTime
public DateTime(ZonedDateTime zdt)
Constructs aDateTimefrom aZonedDateTime
-
-
Method Detail
-
of
public static DateTime of(OffsetDateTime dt)
Null-safe conversion fromOffsetDateTimetoDateTime
-
parse
public static DateTime parse(String string)
Parses the given String as aDateTime, returning null for blank strings
-
add
public DateTime add(long elapsed) throws IllegalArgumentException
Adds the given number of milliseconds to this date time object- Returns:
- this instance.
- Throws:
IllegalArgumentException- if elapsed time is negative.
-
after
public boolean after(DateTime dt)
-
afterOrEquals
public boolean afterOrEquals(DateTime dt)
-
before
public boolean before(DateTime dt)
-
beforeOrEquals
public boolean beforeOrEquals(DateTime dt)
-
compareTo
public int compareTo(DateTime dt)
- Specified by:
compareToin interfaceComparable<DateTime>
-
decDate
public DateTime decDate()
-
decMonth
public DateTime decMonth()
-
decYear
public DateTime decYear()
-
duplicate
public DateTime duplicate()
Makes a copy of this instance.
-
getDate
public int getDate()
-
getHours
public int getHours()
-
getMilliseconds
public int getMilliseconds()
-
getMinutes
public int getMinutes()
-
getMonth
public int getMonth()
-
getSeconds
public int getSeconds()
-
getTimeZone
public String getTimeZone()
-
getYear
public int getYear()
-
incDate
public DateTime incDate()
-
incMonth
public DateTime incMonth()
-
incYear
public DateTime incYear()
-
isSameDay
public boolean isSameDay(DateTime dt)
-
setDate
public void setDate(int date)
Sets the day of the month.- Parameters:
date- it must be between 1 and 31 (must be a valid value according to the month)
-
setHMSM
public void setHMSM(int hours, int minutes, int seconds, int milliseconds)Sets only the time part (H=hours, M=minutes, S=seconds, M=milliseconds) without changing the date part (YMD)- Parameters:
hours- it must be between 0 and 23 (Hour in day)
-
setHours
public void setHours(int hours)
- Parameters:
hours- it must be between 0 and 23 (Hour in day)
-
setMilliseconds
public void setMilliseconds(int milliseconds)
-
setMinutes
public void setMinutes(int minutes)
- Parameters:
minutes- it must be between 0 and 59
-
setMonth
public void setMonth(int month)
- Parameters:
month- it must be between 0 and 11 (same asDate)
-
setSeconds
public void setSeconds(int seconds)
- Parameters:
seconds- it must be between 0 and 59
-
setTimeZone
public void setTimeZone(String timeZone)
-
setYear
public void setYear(int year)
-
setYMD
public void setYMD(int year, int month, int date)Sets only the date part (Y=year, M=month, D=date (day of month)) without change the time part (HMS)
-
toDateString
public String toDateString()
-
toLocalDate
public LocalDate toLocalDate()
-
toLocalDateTime
public LocalDateTime toLocalDateTime()
-
toOffsetDateTime
public OffsetDateTime toOffsetDateTime(ZoneId zoneId)
-
toTimeString
public String toTimeString()
-
-