com.starteam.util
Class DateTime

java.lang.Object
  extended by com.starteam.util.DateTime
All Implemented Interfaces:
java.io.Serializable

public final class DateTime
extends java.lang.Object
implements java.io.Serializable

An SDK implementation of Date and Time whose internal representation is in UTC It provides transformations and converters to java.util.Date and to/from Ticks, to support interoperability with Microsoft.NET System.DateTime This class does not support millisecond precision.

See Also:
Serialized Form

Field Summary
static DateTime CURRENT_SERVER_TIME
          A date value that can signal the server to use its current time rather than any specific time sent by the client.
static double DATE_TIME_VALUE_NOT_SET
          Constant used in some properties to indicate this value has not been set.
static DateTime EARLIEST_SUPPORTED_TIME
          A date value representing January 1, 1899
static DateTime MAX_VALUE
          The largest DateTime this class can handle.
static DateTime MIN_VALUE
          The smallest DateTime this class can handle.
static DateTime VALUE_NOT_SET
          DateTime used in some properties to indicate this value has not been set.
 
Constructor Summary
DateTime()
          Creates a new DateTime from the current time.
DateTime(java.util.Date date)
          Creates a new DateTime from a java.util.Date
DateTime(double oletime)
          Creates a new DateTime given a double which is an DateTime representing the number of days since midnight January 1, 1899.
DateTime(int year, int month, int day)
          Creates a new DateTime from the specified parts
DateTime(int year, int month, int day, int hour, int minute, int second)
          Creates a new DateTime from the specified parts
DateTime(long javatime)
          Creates a new DateTime given a long value as would be returned from the Java Date class method getTime().
 
Method Summary
static DateTime add(DateTime time, TimeSpan delta)
          returns a DateTime composed by adding elapsed time to a DateTime instance
 DateTime add(TimeSpan delta)
          returns a DateTime composed by adding elapsed time to this DateTime instance
 int compareTo(DateTime date)
          Returns: > 0 if this date is after the given date; 0 if this date is the same as the given date; < 0 if this date is before the given date.
 boolean equals(java.lang.Object obj)
          Compare this DateTime with another one
static DateTime fromJavaDate(java.util.Date date)
          Creates an instance of a DateTime object from a java.util.Date object
static DateTime fromJavaMsec(long msec)
          Creates an instance of a DateTime object from a long value as would be returned from java.util.Date.getTime().
static double fromJavaMsecToOATime(long val)
          A helper method that converts a long (java.util.Date.getTime()) to a double (DateTime.toOATime())
static long fromJavaMsecToTicks(long msec)
          A helper method that converts a long (java.util.Date.getTime()) to a long .NET tick (System.DateTime.Ticks)
static DateTime fromOATime(double time)
          Creates an instance of a DateTime object from a double value as would be returned from DateTime.toOATime()
static long fromOATimeToJavaMsec(double dbl)
          A helper method that converts a double (DateTime.toOATime()) to a long (java.util.Date.getTime())
static long fromOATimeToTicks(double time)
          A helper method that converts a double ((DateTime.toOATime.toOATime()) to a .NET tick (System.DateTime.Ticks)
static DateTime fromTicks(long ticks)
          Creates an instance of a DateTime object from a long value as would be returned from the .NET property System.DateTime.Ticks
static long fromTicksToJavaMsec(long ticks)
          A helper method that converts a long .NET tick (System.DateTime.Ticks) to a long (java.util.Date.getTime())
static TimeSpan getElapsedTime(DateTime before, DateTime after)
          returns the elapsed time between two DateTime instances
 DateTime getUTCNoon()
          Returns a DateTime whose value is UTC noon of the current DateTime instance
 int hashCode()
          returns a unique hash for this DateTime
 boolean isAfter(DateTime date)
          Returns true if the given date is after this one in time
 boolean isBefore(DateTime date)
          Returns true if the given date is before this one in time
static DateTime now()
          Returns a new DateTime from the current time.
static DateTime subtract(DateTime time, TimeSpan delta)
          returns a DateTime composed by subtracting elapsed time from a DateTime instance
 DateTime subtract(TimeSpan delta)
          returns a DateTime composed by subtracting elapsed time from this DateTime instance
 Date toDate()
          return the Date part of this DateTime instance
 java.lang.String toISO8601String()
          Returns an ISO8601 string representation of this time using GMT as the timezone.
 java.util.Date toJavaDate()
          Returns an instance of a java.util.Date from this DateTime
 long toJavaMsec()
          Returns the Java based long time for this DateTime value.
 java.lang.String toLocalString()
          Simple display of the date using the default Locale and the DateFormat.LONG values for the date and time.
 java.lang.String toLocalString(int dateFormat, int timeFormat)
          returns a String representation of this DateTime instance formatted for the default locale
 double toOATime()
          Returns the DateTime's double value for this date.
 java.lang.String toString()
          Simple display of the date using the default Locale and the DateFormat.LONG values for the date and time.
 long toTicks()
          Returns the .NET equivalent Ticks for this DateTime instance
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EARLIEST_SUPPORTED_TIME

public static final DateTime EARLIEST_SUPPORTED_TIME
A date value representing January 1, 1899


CURRENT_SERVER_TIME

public static final DateTime CURRENT_SERVER_TIME
A date value that can signal the server to use its current time rather than any specific time sent by the client. Useful as an argument in some method calls.


DATE_TIME_VALUE_NOT_SET

public static final double DATE_TIME_VALUE_NOT_SET
Constant used in some properties to indicate this value has not been set.

See Also:
Constant Field Values

VALUE_NOT_SET

public static final DateTime VALUE_NOT_SET
DateTime used in some properties to indicate this value has not been set.


MIN_VALUE

public static final DateTime MIN_VALUE
The smallest DateTime this class can handle. Jan 01, 1900 00:00:00


MAX_VALUE

public static final DateTime MAX_VALUE
The largest DateTime this class can handle. Dec 31, 9999 12:59:59

Constructor Detail

DateTime

public DateTime()
Creates a new DateTime from the current time.


DateTime

public DateTime(int year,
                int month,
                int day)
Creates a new DateTime from the specified parts

Parameters:
year - 1900 - 9999
month - 0 - 11 (January == 0)
day - 1 - 31

DateTime

public DateTime(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second)
Creates a new DateTime from the specified parts

Parameters:
year - 1900 - 9999
month - 0 - 11 (January == 0)
day - 1 - 31
hour - 0 - 23
minute - 0 - 59
second - 0 - 59

DateTime

public DateTime(double oletime)
Creates a new DateTime given a double which is an DateTime representing the number of days since midnight January 1, 1899.

Parameters:
oletime - the number of days since midnight January 1, 1899.

DateTime

public DateTime(long javatime)
Creates a new DateTime given a long value as would be returned from the Java Date class method getTime().

Parameters:
javatime - - the value of java.util.Date.getTime()

DateTime

public DateTime(java.util.Date date)
Creates a new DateTime from a java.util.Date

Parameters:
date - - an instance of a java.util.Date object
Method Detail

now

public static DateTime now()
Returns a new DateTime from the current time.

Returns:
a new DateTime from the current time.

toOATime

public double toOATime()
Returns the DateTime's double value for this date.

Returns:
the DateTime's double value for this date.

toJavaMsec

public long toJavaMsec()
Returns the Java based long time for this DateTime value.

Returns:
the Java based long time for this DateTime value

toTicks

public long toTicks()
Returns the .NET equivalent Ticks for this DateTime instance

Returns:
the .NET equivalent Ticks for this DateTime instance

toJavaDate

public java.util.Date toJavaDate()
Returns an instance of a java.util.Date from this DateTime

Returns:
an instance of a java.util.Date from this DateTime

fromJavaMsec

public static DateTime fromJavaMsec(long msec)
Creates an instance of a DateTime object from a long value as would be returned from java.util.Date.getTime().

Parameters:
msec - - a long value as would be returned from java.util.Date.getTime()
Returns:
an instance of a DateTime object

fromJavaDate

public static DateTime fromJavaDate(java.util.Date date)
Creates an instance of a DateTime object from a java.util.Date object

Parameters:
date - - a java.util.Date instance
Returns:
an instance of a DateTime object

fromOATime

public static DateTime fromOATime(double time)
Creates an instance of a DateTime object from a double value as would be returned from DateTime.toOATime()

Parameters:
time - - a double value as would be returned from DateTime.toOATime()
Returns:
an instance of a DateTime object

fromTicks

public static DateTime fromTicks(long ticks)
Creates an instance of a DateTime object from a long value as would be returned from the .NET property System.DateTime.Ticks

Parameters:
ticks - a long value as would be returned from the .NET property System.DateTime.Ticks
Returns:
an instance of a DateTime object

fromOATimeToJavaMsec

public static long fromOATimeToJavaMsec(double dbl)
A helper method that converts a double (DateTime.toOATime()) to a long (java.util.Date.getTime())

Parameters:
dbl - a double as would be returned by DateTime.toOATime()
Returns:
a long as would be returned by java.util.Date.getTime()

fromOATimeToTicks

public static long fromOATimeToTicks(double time)
A helper method that converts a double ((DateTime.toOATime.toOATime()) to a .NET tick (System.DateTime.Ticks)

Parameters:
time - - a double as would be returned by DateTime.toOATime()
Returns:
a long as would be returned by System.DateTime.Ticks

fromJavaMsecToOATime

public static double fromJavaMsecToOATime(long val)
A helper method that converts a long (java.util.Date.getTime()) to a double (DateTime.toOATime())

Parameters:
val - - a long as would be returned by java.util.Date.getTime()
Returns:
a double as would be returned by DateTime.toOATime()

fromJavaMsecToTicks

public static long fromJavaMsecToTicks(long msec)
A helper method that converts a long (java.util.Date.getTime()) to a long .NET tick (System.DateTime.Ticks)

Parameters:
msec - - a long as would be returned by java.util.Date.getTime()
Returns:
a long as would be returned by System.DateTime.Ticks

fromTicksToJavaMsec

public static long fromTicksToJavaMsec(long ticks)
A helper method that converts a long .NET tick (System.DateTime.Ticks) to a long (java.util.Date.getTime())

Parameters:
ticks - - a long as would be returned by System.DateTime.Ticks
Returns:
a long as would be returned by java.util.Date.getTime()

getUTCNoon

public DateTime getUTCNoon()
Returns a DateTime whose value is UTC noon of the current DateTime instance

Returns:
a DateTime whose value is UTC noon of the current DateTime instance

toString

public java.lang.String toString()
Simple display of the date using the default Locale and the DateFormat.LONG values for the date and time.

Overrides:
toString in class java.lang.Object
Returns:
a simple display of the date using the default Locale and the DateFormat.LONG values for the date and time.

toLocalString

public java.lang.String toLocalString()
Simple display of the date using the default Locale and the DateFormat.LONG values for the date and time.

Returns:
a simple display of the date using the default Locale and the DateFormat.LONG values for the date and time.

toLocalString

public java.lang.String toLocalString(int dateFormat,
                                      int timeFormat)
returns a String representation of this DateTime instance formatted for the default locale

Parameters:
dateFormat - a date format descriptor
timeFormat - a time formate descriptor
Returns:
a String representation of this DateTime instance formatted for the default locale
See Also:
DateFormat

toISO8601String

public java.lang.String toISO8601String()
Returns an ISO8601 string representation of this time using GMT as the timezone.

Returns:
an ISO8601 string representation of this time using GMT as the timezone.
See Also:
ISO8601

hashCode

public int hashCode()
returns a unique hash for this DateTime

Overrides:
hashCode in class java.lang.Object
Returns:
a unique hash for this DateTime

equals

public boolean equals(java.lang.Object obj)
Compare this DateTime with another one

Overrides:
equals in class java.lang.Object
Parameters:
obj - the DateTiem instance to compare it with
Returns:
true if they have the same value, false otherwise

getElapsedTime

public static TimeSpan getElapsedTime(DateTime before,
                                      DateTime after)
returns the elapsed time between two DateTime instances

Parameters:
before - DateTime
after - DateTime
Returns:
TimeSpan; the elapsed time between two DateTime instances

add

public static DateTime add(DateTime time,
                           TimeSpan delta)
returns a DateTime composed by adding elapsed time to a DateTime instance

Parameters:
time - an existing DateTime
delta - the TimeSpan to add
Returns:
a new DateTime instance composed from the addition of elapsed time to the existing DateTime

add

public DateTime add(TimeSpan delta)
returns a DateTime composed by adding elapsed time to this DateTime instance

Parameters:
delta - the TimeSpan to add
Returns:
a new DateTime instance composed from the addition of elapsed time to this one

subtract

public static DateTime subtract(DateTime time,
                                TimeSpan delta)
returns a DateTime composed by subtracting elapsed time from a DateTime instance

Parameters:
time - an existing DateTime
delta - the TimeSpan to subtract
Returns:
a new DateTime instance composed from the subtraction of elapsed time from the existing DateTime

subtract

public DateTime subtract(TimeSpan delta)
returns a DateTime composed by subtracting elapsed time from this DateTime instance

Parameters:
delta - TimeSpan
Returns:
a new DateTime instance composed from the subtraction of elapsed time from this one

toDate

public Date toDate()
return the Date part of this DateTime instance

Returns:
the Date part of this DateTime instance
Throws:
java.lang.IllegalArgumentException - if the conversion is not possible

compareTo

public int compareTo(DateTime date)
Returns: > 0 if this date is after the given date; 0 if this date is the same as the given date; < 0 if this date is before the given date.

Parameters:
date - - the Date instance to compare with this one
Returns:
an integer representing the result of the comparison

isBefore

public boolean isBefore(DateTime date)
Returns true if the given date is before this one in time

Parameters:
date - - the Date instance to compare with this one
Returns:
true if the given date is before this one in time

isAfter

public boolean isAfter(DateTime date)
Returns true if the given date is after this one in time

Parameters:
date - - the Date instance to compare with this one
Returns:
true if the given date is after this one in time


StarTeam SDK 14.0, Build 21
Copyright © 2003-2012 Borland Software Corporation. All rights reserved.