com.teraspaces.qwframework
Class TimeSpan

java.lang.Object
  extended by com.teraspaces.qwframework.TimeSpan
All Implemented Interfaces:
Comparable<TimeSpan>

public class TimeSpan
extends Object
implements Comparable<TimeSpan>

Represents a Java implementation of .Net TimeSpan class.


Field Summary
static TimeSpan MAX_VALUE
          Represents the maximum TimeSpan value.
static TimeSpan MIN_VALUE
          Represents the minimum TimeSpan value.
static long TICKS_PER_DAY
          Represents the number of ticks in 1 day.
static long TICKS_PER_HOUR
          Represents the number of ticks in 1 hour.
static long TICKS_PER_MILLISECOND
          Represents the number of ticks in 1 millisecond.
static long TICKS_PER_MINUTE
          Represents the number of ticks in 1 minute.
static long TICKS_PER_SECOND
          Represents the number of ticks in 1 second.
static TimeSpan ZERO
          Represents the zero TimeSpan value.
 
Constructor Summary
TimeSpan(int hours, int minutes, int seconds)
          Instantiates a new time span.
TimeSpan(int days, int hours, int minutes, int seconds)
          Instantiates a new time span.
TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
          Instantiates a new time span.
TimeSpan(long ticks)
          Instantiates a new time span.
 
Method Summary
 TimeSpan add(TimeSpan ts)
          Adds the specified TimeSpan to this instance.
static int compare(TimeSpan t1, TimeSpan t2)
          Compares two TimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.
 int compareTo(TimeSpan value)
           
static long createTicks(int days, int hours, int minutes, int seconds, int milliseconds)
          Creates the ticks of a TimeSpan.
 TimeSpan duration()
          Duration.
 boolean equals(Object value)
           
 boolean equals(TimeSpan obj)
          Equals.
static boolean equals(TimeSpan t1, TimeSpan t2)
          Equals.
static TimeSpan fromDays(double value)
          From days.
static TimeSpan fromHours(double value)
          From hours.
static TimeSpan fromMilliseconds(double value)
          From milliseconds.
static TimeSpan fromMinutes(double value)
          From minutes.
static TimeSpan fromSeconds(double value)
          From seconds.
static TimeSpan fromTicks(long value)
          From ticks.
 int getDays()
          Gets the days.
static int getDays(long ticks)
          Gets the day component of a TimeSpan from ticks.
 int getHours()
          Gets the hours.
static int getHours(long ticks)
          Gets the hour component of a TimeSpan from ticks.
 int getMilliseconds()
          Gets the milliseconds.
static int getMilliseconds(long ticks)
          Gets the millisecond component of a TimeSpan from ticks.
 int getMinutes()
          Gets the minutes.
static int getMinutes(long ticks)
          Gets the minute component of a TimeSpan from ticks.
 int getSeconds()
          Gets the seconds.
static int getSeconds(long ticks)
          Gets the second component of a TimeSpan from ticks.
 long getTicks()
          Gets the ticks.
 double getTotalDays()
          Gets the total days.
static double getTotalDays(long ticks)
          Gets the total days of a TimeSpan from ticks.
 double getTotalHours()
          Gets the total hours.
static double getTotalHours(long ticks)
          Gets the total hours of a TimeSpan from ticks.
 double getTotalMilliseconds()
          Gets the total milliseconds of a TimeSpan from ticks.
static double getTotalMilliseconds(long ticks)
          Gets the total milliseconds.
 double getTotalMinutes()
          Gets the total minutes.
static double getTotalMinutes(long ticks)
          Gets the total minutes of a TimeSpan from ticks.
 double getTotalSeconds()
          Gets the total seconds.
static double getTotalSeconds(long ticks)
          Gets the total seconds of a TimeSpan from ticks.
 int hashCode()
           
 TimeSpan negate()
          Negate.
static TimeSpan parse(String s)
          Parses the.
 TimeSpan subtract(TimeSpan ts)
          Subtract.
 String toString()
           
static TimeSpan valueOf(String s)
          Value of.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TICKS_PER_MILLISECOND

public static final long TICKS_PER_MILLISECOND
Represents the number of ticks in 1 millisecond. This field is constant.

See Also:
Constant Field Values

TICKS_PER_SECOND

public static final long TICKS_PER_SECOND
Represents the number of ticks in 1 second.

See Also:
Constant Field Values

TICKS_PER_MINUTE

public static final long TICKS_PER_MINUTE
Represents the number of ticks in 1 minute. This field is constant.

See Also:
Constant Field Values

TICKS_PER_HOUR

public static final long TICKS_PER_HOUR
Represents the number of ticks in 1 hour. This field is constant.

See Also:
Constant Field Values

TICKS_PER_DAY

public static final long TICKS_PER_DAY
Represents the number of ticks in 1 day. This field is constant.

See Also:
Constant Field Values

ZERO

public static final TimeSpan ZERO
Represents the zero TimeSpan value. This field is read-only.


MAX_VALUE

public static final TimeSpan MAX_VALUE
Represents the maximum TimeSpan value. This field is read-only.


MIN_VALUE

public static final TimeSpan MIN_VALUE
Represents the minimum TimeSpan value. This field is read-only.

Constructor Detail

TimeSpan

public TimeSpan(long ticks)
Instantiates a new time span.

Parameters:
ticks - the ticks

TimeSpan

public TimeSpan(int hours,
                int minutes,
                int seconds)
Instantiates a new time span.

Parameters:
hours - the hours
minutes - the minutes
seconds - the seconds

TimeSpan

public TimeSpan(int days,
                int hours,
                int minutes,
                int seconds)
Instantiates a new time span.

Parameters:
days - the days
hours - the hours
minutes - the minutes
seconds - the seconds

TimeSpan

public TimeSpan(int days,
                int hours,
                int minutes,
                int seconds,
                int milliseconds)
Instantiates a new time span.

Parameters:
days - the days
hours - the hours
minutes - the minutes
seconds - the seconds
milliseconds - the milliseconds
Method Detail

createTicks

public static long createTicks(int days,
                               int hours,
                               int minutes,
                               int seconds,
                               int milliseconds)
Creates the ticks of a TimeSpan.

Parameters:
days - the days
hours - the hours
minutes - the minutes
seconds - the seconds
milliseconds - the milliseconds
Returns:
the ticks

getTicks

public long getTicks()
Gets the ticks.

Returns:
the ticks

getDays

public int getDays()
Gets the days.

Returns:
the days

getDays

public static int getDays(long ticks)
Gets the day component of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the days

getHours

public int getHours()
Gets the hours.

Returns:
the hours

getHours

public static int getHours(long ticks)
Gets the hour component of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the hours

getMilliseconds

public int getMilliseconds()
Gets the milliseconds.

Returns:
the milliseconds

getMilliseconds

public static int getMilliseconds(long ticks)
Gets the millisecond component of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the milliseconds

getMinutes

public int getMinutes()
Gets the minutes.

Returns:
the minutes

getMinutes

public static int getMinutes(long ticks)
Gets the minute component of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the minutes

getSeconds

public int getSeconds()
Gets the seconds.

Returns:
the seconds

getSeconds

public static int getSeconds(long ticks)
Gets the second component of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the seconds

getTotalDays

public double getTotalDays()
Gets the total days.

Returns:
the total days

getTotalDays

public static double getTotalDays(long ticks)
Gets the total days of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the total days

getTotalHours

public double getTotalHours()
Gets the total hours.

Returns:
the total hours

getTotalHours

public static double getTotalHours(long ticks)
Gets the total hours of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the total hours

getTotalMilliseconds

public double getTotalMilliseconds()
Gets the total milliseconds of a TimeSpan from ticks.

Returns:
the total milliseconds

getTotalMilliseconds

public static double getTotalMilliseconds(long ticks)
Gets the total milliseconds.

Parameters:
ticks - the ticks
Returns:
the total milliseconds

getTotalMinutes

public double getTotalMinutes()
Gets the total minutes.

Returns:
the total minutes

getTotalMinutes

public static double getTotalMinutes(long ticks)
Gets the total minutes of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the total minutes

getTotalSeconds

public double getTotalSeconds()
Gets the total seconds.

Returns:
the total seconds

getTotalSeconds

public static double getTotalSeconds(long ticks)
Gets the total seconds of a TimeSpan from ticks.

Parameters:
ticks - the ticks
Returns:
the total seconds

add

public TimeSpan add(TimeSpan ts)
Adds the specified TimeSpan to this instance.

Parameters:
ts - a TimeSpan
Returns:
a TimeSpan that represents the value of this instance plus the value of ts

compare

public static int compare(TimeSpan t1,
                          TimeSpan t2)
Compares two TimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.

Parameters:
t1 - the first TimeSpan
t2 - the second TimeSpan
Returns:
-1, if t1 is shorter than t2; 0, if t1 is equal to t2; 1, if t1 is longer than t2

compareTo

public int compareTo(TimeSpan value)
Specified by:
compareTo in interface Comparable<TimeSpan>

fromDays

public static TimeSpan fromDays(double value)
From days.

Parameters:
value - the value
Returns:
the time span

duration

public TimeSpan duration()
Duration.

Returns:
the time span

equals

public boolean equals(Object value)
Overrides:
equals in class Object

equals

public boolean equals(TimeSpan obj)
Equals.

Parameters:
obj - the obj
Returns:
true, if successful

equals

public static boolean equals(TimeSpan t1,
                             TimeSpan t2)
Equals.

Parameters:
t1 - the t1
t2 - the t2
Returns:
true, if successful

hashCode

public int hashCode()
Overrides:
hashCode in class Object

fromHours

public static TimeSpan fromHours(double value)
From hours.

Parameters:
value - the value
Returns:
the time span

fromMilliseconds

public static TimeSpan fromMilliseconds(double value)
From milliseconds.

Parameters:
value - the value
Returns:
the time span

fromMinutes

public static TimeSpan fromMinutes(double value)
From minutes.

Parameters:
value - the value
Returns:
the time span

negate

public TimeSpan negate()
Negate.

Returns:
the time span

fromSeconds

public static TimeSpan fromSeconds(double value)
From seconds.

Parameters:
value - the value
Returns:
the time span

subtract

public TimeSpan subtract(TimeSpan ts)
Subtract.

Parameters:
ts - the ts
Returns:
the time span

fromTicks

public static TimeSpan fromTicks(long value)
From ticks.

Parameters:
value - the value
Returns:
the time span

parse

public static TimeSpan parse(String s)
Parses the.

Parameters:
s - the s
Returns:
the time span

toString

public String toString()
Overrides:
toString in class Object

valueOf

public static TimeSpan valueOf(String s)
Value of.

Parameters:
s - the s
Returns:
the time span