texsoft.java.util
Class XsDateTime

java.lang.Object
  |
  +--texsoft.java.util.XsDateTime
All Implemented Interfaces:
java.lang.Comparable

public class XsDateTime
extends java.lang.Object
implements java.lang.Comparable

The XsDateTime represents a monent in time, with a XsDate and an optional XsTime objects.


Constructor Summary
XsDateTime()
          Creates a new empty XsDateTime object.
XsDateTime(java.util.GregorianCalendar cal)
          Creates a new XsDateTime object set to cal's date and time.
XsDateTime(long timestamp)
          Creates a new XsDateTime object set to timestamp in milliseconds since 1970-01-01 0:00:00.
XsDateTime(java.lang.String s)
          Creates a new XsDateTime object, with date and time set from the string.
XsDateTime(java.lang.String d, java.lang.String t)
          Creates a new XsDateTime object, with date and time set from the strings.
XsDateTime(XsDate d)
          Creates a new XsDateTime object, set date to d and time to null.
XsDateTime(XsDate d, XsTime t)
          Creates a new XsDateTime object, set date to d and time to t.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
static XsDateTime getCurrent()
          Returns a new XsDateTime object set from to system date and time.
 XsDate getDate()
          Get the date component.
 XsTime getTime()
          Get the time component.
 boolean hasTime()
          Returns true if the time component is not null.
static void main(java.lang.String[] args)
          Some simple test code.
 void setDate(XsDate date)
          Set a new date value.
 void setDateTime(java.util.GregorianCalendar cal)
          Set date and time from the passed GregorianCalendar object.
 void setDateTime(long timestamp)
          Set date and time to the timestamp in milliseconds since 1970-01-01 0:00:00.
 void setDateTime(java.lang.String s)
          Set the date and time values based on the string argument.
 void setDateTime(XsDate d, XsTime t)
          Set new date and time values for this object.
 void setTime(XsTime time)
          Set a new time value.
 java.util.GregorianCalendar toGregorianCalendar()
          Returns date and time as a GregorianCalendar object.
 long toMilliseconds()
          Return date and time as timestamp in milliseconds since 1970-01-01 0:00:00.
 java.lang.String toString()
          Returns date and time as string in the format YYYY-MM-DD [HH:MM:SS].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XsDateTime

public XsDateTime()
Creates a new empty XsDateTime object.

Date component is set to empty XsDate, time component is set to null.


XsDateTime

public XsDateTime(java.lang.String s)
Creates a new XsDateTime object, with date and time set from the string.

The format of the argument is a date value in the one of the formats recognized by XsDate.setDate(String), followed by an optional time value in the format recognized by XsTime.setTime(String) separed from the date by one or more whitespace characters.

Parameters:
s - date and optional time in one of the recognized String formats.
See Also:
XsDate.setDate(String), XsTime.setTime(String)

XsDateTime

public XsDateTime(java.lang.String d,
                  java.lang.String t)
Creates a new XsDateTime object, with date and time set from the strings.

The format of the arguments is a date value in the one of the formats recognized by XsDate.setDate(String), and a time value in the format recognized by XsTime.setTime(String). The time is optional and can be null.

Parameters:
d - date value in one of the recognized String formats.
t - time value in one of the recognized String formats.
See Also:
XsDate.setDate(String), XsTime.setTime(String)

XsDateTime

public XsDateTime(XsDate d)
Creates a new XsDateTime object, set date to d and time to null.

Parameters:
d - date value.

XsDateTime

public XsDateTime(XsDate d,
                  XsTime t)
Creates a new XsDateTime object, set date to d and time to t.

Time value is optional and can be null.

Parameters:
d - date value.
t - time value.

XsDateTime

public XsDateTime(java.util.GregorianCalendar cal)
Creates a new XsDateTime object set to cal's date and time.

Parameters:
cal - time and date value.

XsDateTime

public XsDateTime(long timestamp)
Creates a new XsDateTime object set to timestamp in milliseconds since 1970-01-01 0:00:00.

Parameters:
timestamp - date and time as timestamp in milliseconds since 1970-01-01 0:00:00.
Method Detail

setDateTime

public void setDateTime(XsDate d,
                        XsTime t)
Set new date and time values for this object. Time value is optional and can be null.

Parameters:
d - date value.
t - time value.

setDateTime

public void setDateTime(java.lang.String s)
Set the date and time values based on the string argument.

The format of the argument is a date value in the one of the formats recognized by XsDate.setDate(String), followed by an optional time value in the format recognized by XsTime.setTime(String) separed from the date by one or more whitespace characters.

Parameters:
s - date and optional time in one of the recognized String formats.
See Also:
XsDate.setDate(String), XsTime.setTime(String)

setDateTime

public void setDateTime(java.util.GregorianCalendar cal)
Set date and time from the passed GregorianCalendar object.

Parameters:
cal - new date and time in as GregorianCalendar object.

setDateTime

public void setDateTime(long timestamp)
Set date and time to the timestamp in milliseconds since 1970-01-01 0:00:00.

Parameters:
timestamp - new date and time as timestamp in milliseconds since 1970-01-01 0:00:00.

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The argument can be another XsDateTime object or a XsDate object. If a XsDate object is passed, it is managed as a XsDateTime object with time set to null.

First the dates value are compared, if them are equal then the time values are compared. A null time is defined to be less that time 0:00:00.

If compared to null returns a positive value.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this object.

getDate

public XsDate getDate()
Get the date component.

Returns:
date value.

getTime

public XsTime getTime()
Get the time component.

Returns:
time value.

setDate

public void setDate(XsDate date)
Set a new date value.

Parameters:
date - new date value.

setTime

public void setTime(XsTime time)
Set a new time value.

Parameters:
time - new time value.

hasTime

public boolean hasTime()
Returns true if the time component is not null.

Returns:
true if the time component is not null.

getCurrent

public static XsDateTime getCurrent()
Returns a new XsDateTime object set from to system date and time.

Returns:
object set with the current date and time.

toString

public java.lang.String toString()
Returns date and time as string in the format YYYY-MM-DD [HH:MM:SS].

Overrides:
toString in class java.lang.Object
Returns:
string representation of the date and time in the format YYYY-MM-DD [HH:MM:SS]

toGregorianCalendar

public java.util.GregorianCalendar toGregorianCalendar()
Returns date and time as a GregorianCalendar object.

Returns:
GregorianCalendar object set with the date and time of this object.

toMilliseconds

public long toMilliseconds()
Return date and time as timestamp in milliseconds since 1970-01-01 0:00:00.

Returns:
date and time value as a timestamp in milliseconds since 1970-01-01 0:00:00.

main

public static void main(java.lang.String[] args)
Some simple test code.

Parameters:
args - command line arguments.