com.silverpeas.calendar
Class DateTime

java.lang.Object
  extended by java.util.Date
      extended by com.silverpeas.calendar.AbstractDateDatable<DateTime>
          extended by com.silverpeas.calendar.DateTime
All Implemented Interfaces:
Datable<DateTime>, Serializable, Cloneable, Comparable<Date>

public class DateTime
extends AbstractDateDatable<DateTime>

A date and time.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.silverpeas.calendar.Datable
ICAL_PATTERN, ICAL_UTC_PATTERN, ISO_8601_PATTERN, SHORT_ISO_8601_PATTERN
 
Constructor Summary
DateTime(Date aDate)
          Constructs a new date time from the specified Java date and with the host time zone as time zone.
DateTime(Date aDate, TimeZone timeZone)
          Constructs a new date time from the specified Java date and in the specified time zone.
 
Method Summary
 Date asDate()
          Gets the java Date representation of this datable.
 DateTime clone()
          Clones itself.
static DateTime dateTimeAt(int... timeParts)
          Creates a new date time from the specified parts of the time specification year month day hour minute second millisecond.
 boolean equals(Object obj)
           
 TimeZone getTimeZone()
          Gets the time zone for which this datable is defined.
 int hashCode()
           
 DateTime inTimeZone(TimeZone timeZone)
          Sets the time zone this datable is defined for.
 boolean isAfter(Date otherDate)
          Is the date in this datetime after the specified date.
 boolean isAfter(DateTime anotherDatable)
          Is this datable strictly after in time the specified another one?
 boolean isBefore(Date otherDate)
          Is the date in this datetime before the specified date.
 boolean isBefore(DateTime anotherDatable)
          Is this datable strictly before in time the specified another one?
 boolean isEqualTo(Date otherDate)
          Is the date in this datetime equal to the specified date.
 boolean isEqualTo(DateTime anotherDatable)
          Is this datable equal in time to the specified another one?
protected  DateTime newInstanceFrom(Date aDate)
          Create a new instance from a given date time in milliseconds.
static DateTime now()
          Creates a new date time set at now.
 Date toDate()
          Converts this date time to a date.
 String toICal()
          Gets the ISO 8601 textual representation of this date as it is in the iCal specification.
 String toICalInUTC()
          Gets the ISO 8601 textual representation of this date as it is in the iCal specification.
 String toISO8601()
          Gets an ISO 8601 textual representation of this datable by taking into account of its underlying timezone.
 String toShortISO8601()
          Gets an ISO 8601 textual representation of this datable by taking into account of its underlying timezone.
 
Methods inherited from class com.silverpeas.calendar.AbstractDateDatable
addDays, addHours, addMilliseconds, addMinutes, addMonths, addSeconds, addWeeks, addYears, getBeginOfDay, getBeginOfMonth, getBeginOfWeek, getBeginOfWeek, getBeginOfYear, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfWeek, getEndOfYear, getTimeDataTo, isDefined, isNotDefined
 
Methods inherited from class java.util.Date
after, before, compareTo, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, toString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateTime

public DateTime(Date aDate)
Constructs a new date time from the specified Java date and with the host time zone as time zone.

Parameters:
aDate - the Java date from which a date time is built.

DateTime

public DateTime(Date aDate,
                TimeZone timeZone)
Constructs a new date time from the specified Java date and in the specified time zone.

Parameters:
aDate - the Java date from which a date time is built.
timeZone - the time zone in which this date is set.
Method Detail

now

public static DateTime now()
Creates a new date time set at now.

Returns:
now date time.

dateTimeAt

public static DateTime dateTimeAt(int... timeParts)
Creates a new date time from the specified parts of the time specification year month day hour minute second millisecond. The hour, minute, second and millisecond parts are optional; if not passed, they are set at 0. For example, the following patterns are valid:

Parameters:
timeParts - the different parts of the date time to set in the following order: year, month, day, hour, minute, second, millisecond. The year, month, and day are mandatory whereas other time parts are optional. If one optional part isn't passed, then it is set to 0.
Returns:
a date time matching the specified date and time specification.

newInstanceFrom

protected DateTime newInstanceFrom(Date aDate)
Description copied from class: AbstractDateDatable
Create a new instance from a given date time in milliseconds.

Specified by:
newInstanceFrom in class AbstractDateDatable<DateTime>
Parameters:
aDate - the date time in milliseconds.
Returns:
the new datable instance corresponding to the given time in milliseconds.

clone

public DateTime clone()
Description copied from interface: Datable
Clones itself.

Specified by:
clone in interface Datable<DateTime>
Specified by:
clone in class AbstractDateDatable<DateTime>
Returns:
a clone to this datable.

asDate

public Date asDate()
Description copied from interface: Datable
Gets the java Date representation of this datable.

Returns:
a Date representation of this datable.

toISO8601

public String toISO8601()
Description copied from interface: Datable
Gets an ISO 8601 textual representation of this datable by taking into account of its underlying timezone. For date and time, the representation is at the accuracy to the second. The ISO 8601 format in which the date is returned is one of the more common in the Web, that is with the date and time separators (the hyphen for dates and the double-points for times): yyyy-MM-dd'T'HH:mm:ss where yyyy means the year in 4 digits, MM means the month in year in two digits, dd means the day in month in two digits, HH means the hour (24-o'clock) in two digits, mm means the minute in two digits, and ss the second in two digits.

Returns:
the ISO 8601 textual representation of this datable.

toShortISO8601

public String toShortISO8601()
Description copied from interface: Datable
Gets an ISO 8601 textual representation of this datable by taking into account of its underlying timezone. For date and time, the representation is at the accuracy to the minute. The ISO 8601 format in which the date is returned is one of the more common in the Web, that is with the date and time separators (the hyphen for dates and the double-points for times): yyyy-MM-dd'T'HH:mm:ss where yyyy means the year in 4 digits, MM means the month in year in two digits, dd means the day in month in two digits, HH means the hour (24-o'clock) in two digits, and mm means the minute in two digits.

Returns:
a short ISO 8601 textual representation of this datable.

toICal

public String toICal()
Description copied from interface: Datable
Gets the ISO 8601 textual representation of this date as it is in the iCal specification. The returned iCal date representation is in this datable's time zone. In the iCal specification, dates are represented in one of the ISO 8601 format, that is the complete format without any date and time separators (the hyphen character for dates and the double-points for times). In the iCal specification, no time zone information is added to the ISO 8601 representation of the date, nevertheless when the date is indicated in UTC, the 'Z' marker must be set in the date as required by the ISO 8601 standard.

Returns:
the iCal textual representation of this datable and in the timezone of this datable.

toICalInUTC

public String toICalInUTC()
Description copied from interface: Datable
Gets the ISO 8601 textual representation of this date as it is in the iCal specification. The returned iCal date representation is in explicitly set in UTC. In the iCal specification, dates are represented in one of the ISO 8601 format, that is the complete format without any date and time separators (the hyphen character for dates and the double-points for times). In the iCal specification, no time zone information is added to the ISO 8601 representation of the date, nevertheless when the date is indicated in UTC, the 'Z' marker must be set in the date as required by the ISO 8601 standard.

Returns:
the iCal textual representation of this datable and in UTC.

inTimeZone

public DateTime inTimeZone(TimeZone timeZone)
Description copied from interface: Datable
Sets the time zone this datable is defined for. If no time zone is set, then the default one is considered (the timezone of the host). The time zone can have no meaning with some datable types like for example simple date (day, month, and year).

Parameters:
timeZone - the time zone of this datable.
Returns:
itself.

getTimeZone

public TimeZone getTimeZone()
Description copied from interface: Datable
Gets the time zone for which this datable is defined.

Returns:
the time zone of this datable.

isBefore

public boolean isBefore(DateTime anotherDatable)
Description copied from interface: Datable
Is this datable strictly before in time the specified another one?

Parameters:
anotherDatable - the another datable to which this is compared.
Returns:
true if this datable is strictly before the another one.

isAfter

public boolean isAfter(DateTime anotherDatable)
Description copied from interface: Datable
Is this datable strictly after in time the specified another one?

Parameters:
anotherDatable - the another datable to which this is compared.
Returns:
true if this datable is strictly after the another one.

isEqualTo

public boolean isEqualTo(DateTime anotherDatable)
Description copied from interface: Datable
Is this datable equal in time to the specified another one?

Parameters:
anotherDatable - the another datable to which this is compared.
Returns:
true if this datable is equal with the another one.

equals

public boolean equals(Object obj)
Overrides:
equals in class Date

hashCode

public int hashCode()
Overrides:
hashCode in class Date

isBefore

public boolean isBefore(Date otherDate)
Is the date in this datetime before the specified date.

Parameters:
otherDate - the other date.
Returns:
true if the date part of this datetime is before the other date.

isAfter

public boolean isAfter(Date otherDate)
Is the date in this datetime after the specified date.

Parameters:
otherDate - the other date.
Returns:
true if the date part of this datetime is after the other date.

isEqualTo

public boolean isEqualTo(Date otherDate)
Is the date in this datetime equal to the specified date.

Parameters:
otherDate - the other date.
Returns:
true if the date part of this datetime is equal to the other date.

toDate

public Date toDate()
Converts this date time to a date. The time part of this date time is lost.

Returns:
a date representation of this date time.


Copyright © 2016 Silverpeas. All Rights Reserved.