com.extjs.gxt.ui.client.util
Class DateWrapper

java.lang.Object
  extended by com.extjs.gxt.ui.client.util.DateWrapper

public class DateWrapper
extends java.lang.Object

Instances of this class are immutable and as such any mutation methods return new DateWrapper instances.


Nested Class Summary
static class DateWrapper.Unit
          Represents the different unit values that the add(Unit, int) method takes
 
Constructor Summary
DateWrapper()
          Creates a new instance with the current time.
DateWrapper(java.util.Date date)
          Creates a new instance with the given date.
DateWrapper(int year, int month, int day)
          Creates a new instance with the given values.
DateWrapper(long time)
          Creates a new instance with the given time in milliseconds.
 
Method Summary
 DateWrapper add(DateWrapper.Unit unit, int quantity)
          Provides a convenient method of performing basic date arithmetic.
 DateWrapper addDays(int days)
          Returns a new DateWrapper with days added
 DateWrapper addHours(int hours)
          Returns a new DateWrapper with hours added
 DateWrapper addMillis(int millis)
          Returns a new DateWrapper with millis added
 DateWrapper addMinutes(int minutes)
          Returns a new DateWrapper with minutes added
 DateWrapper addMonths(int months)
          Returns a new DateWrapper with months added
 DateWrapper addSeconds(int seconds)
          Returns a new DateWrapper with seconds added
 DateWrapper addYears(int years)
          Returns a new DateWrapper with years added
 java.util.Date asDate()
          Returns a new Date instance
 boolean before(DateWrapper dateWrapper)
           
 DateWrapper clearTime()
          Returns a new instance with the time portion (hours/minutes/seconds/milliseconds) cleared.
 DateWrapper clone()
           
protected static java.lang.String format(java.util.Date date, java.lang.String format)
           
protected static java.lang.String format(float date, java.lang.String format)
           
 int getDate()
          Returns the day of the month
 int getDay()
          Returns the day of the week
 int getDayInWeek()
          Returns the day of the week
 int getDayOfYear()
          Returns the day of the year
 int getDaysInMonth()
          Returns the number of days in the month.
 DateWrapper getFirstDayOfMonth()
          Returns the first date of the month.
 int getFullYear()
          Returns the full year
 int getHours()
          Returns the hour
 DateWrapper getLastDateOfMonth()
          Returns the last date of the month.
 long getMilliseconds()
          Returns the milliseconds
 int getMinutes()
          Returns the minutes
 int getMonth()
          Returns the month
 int getSeconds()
          Returns the seconds
 long getTime()
          Returns the time in milliseconds.
 DateWrapper resetTime()
          Returns a new instance with the time portion (hours/minutes/seconds/milliseconds) reseted to 12am.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateWrapper

public DateWrapper()
Creates a new instance with the current time.


DateWrapper

public DateWrapper(java.util.Date date)
Creates a new instance with the given date.

Parameters:
date - the date

DateWrapper

public DateWrapper(int year,
                   int month,
                   int day)
Creates a new instance with the given values.

Parameters:
year - the year
month - the month
day - the day

DateWrapper

public DateWrapper(long time)
Creates a new instance with the given time in milliseconds.

Parameters:
time - the time in milliseconds
Method Detail

format

protected static java.lang.String format(java.util.Date date,
                                         java.lang.String format)

format

protected static java.lang.String format(float date,
                                         java.lang.String format)

add

public DateWrapper add(DateWrapper.Unit unit,
                       int quantity)
Provides a convenient method of performing basic date arithmetic. This method does not modify the DateWrapper instance being called - it creates and returns a new DateWrapper instance containing the resulting date value.

Parameters:
unit - the DateWrapper.Unit
quantity - the quantity to add
Returns:
the new DateWrapper
See Also:
addMillis(int), addSeconds(int), addMinutes(int), addHours(int), addDays(int), addMonths(int), addYears(int)

addDays

public DateWrapper addDays(int days)
Returns a new DateWrapper with days added

Returns:
a new DateWrapper with days added
See Also:
add(DateWrapper.Unit, int)

addHours

public DateWrapper addHours(int hours)
Returns a new DateWrapper with hours added

Returns:
a new DateWrapper with hours added
See Also:
add(DateWrapper.Unit, int)

addMillis

public DateWrapper addMillis(int millis)
Returns a new DateWrapper with millis added

Returns:
a new DateWrapper with millis added
See Also:
add(DateWrapper.Unit, int)

addMinutes

public DateWrapper addMinutes(int minutes)
Returns a new DateWrapper with minutes added

Returns:
a new DateWrapper with minutes added
See Also:
add(DateWrapper.Unit, int)

addMonths

public DateWrapper addMonths(int months)
Returns a new DateWrapper with months added

Returns:
a new DateWrapper with months added
See Also:
add(DateWrapper.Unit, int)

addSeconds

public DateWrapper addSeconds(int seconds)
Returns a new DateWrapper with seconds added

Returns:
a new DateWrapper with seconds added
See Also:
add(DateWrapper.Unit, int)

addYears

public DateWrapper addYears(int years)
Returns a new DateWrapper with years added

Returns:
a new DateWrapper with years added
See Also:
add(DateWrapper.Unit, int)

asDate

public java.util.Date asDate()
Returns a new Date instance

Returns:
a new Date instance

before

public boolean before(DateWrapper dateWrapper)

clearTime

public DateWrapper clearTime()
Returns a new instance with the time portion (hours/minutes/seconds/milliseconds) cleared.

Returns:
a new instance with the time portion (hours/minutes/seconds/milliseconds) cleared.

clone

public DateWrapper clone()
Overrides:
clone in class java.lang.Object

getDate

public int getDate()
Returns the day of the month

Returns:
the day of the month

getDay

public int getDay()
Returns the day of the week

Returns:
the day of the week

getDayInWeek

public int getDayInWeek()
Returns the day of the week

Returns:
the day of the week

getDayOfYear

public int getDayOfYear()
Returns the day of the year

Returns:
the day of the year

getDaysInMonth

public int getDaysInMonth()
Returns the number of days in the month.

Returns:
the number of days in the month.

getFirstDayOfMonth

public DateWrapper getFirstDayOfMonth()
Returns the first date of the month.

Returns:
the first date of the month.

getFullYear

public int getFullYear()
Returns the full year

Returns:
the full year

getHours

public int getHours()
Returns the hour

Returns:
the hour

getLastDateOfMonth

public DateWrapper getLastDateOfMonth()
Returns the last date of the month.

Returns:
the last date of the month.

getMilliseconds

public long getMilliseconds()
Returns the milliseconds

Returns:
the milliseconds

getMinutes

public int getMinutes()
Returns the minutes

Returns:
the minutes

getMonth

public int getMonth()
Returns the month

Returns:
the month

getSeconds

public int getSeconds()
Returns the seconds

Returns:
the seconds

getTime

public long getTime()
Returns the time in milliseconds.

Returns:
the time in milliseconds

resetTime

public DateWrapper resetTime()
Returns a new instance with the time portion (hours/minutes/seconds/milliseconds) reseted to 12am. This keeps the date the same also during daylight saving times.

Returns:
a new instance with the time portion reseted to 12am

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object