Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.RuntimeCollective.webapps.bean
Class DateBean  view DateBean download DateBean.java

java.lang.Object
  extended byjava.util.Date
      extended bycom.RuntimeCollective.webapps.bean.DateBean
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class DateBean
extends java.util.Date

A date (and optional time) entered by a user (system-generated dates can stick with java.util.Date.). This class wraps a java.util.Date turning it into a bean including convenience methods for setting its day/month/year/hour/second values, validating and displaying.

Note - a DateBean set using an InputDateTag must be validated (using DateBean.isValid) before the content is transferred to a bean. This method not only validates the date, but also sets the internal java.util.Date.

Version:
$Id: DateBean.java,v 1.19 2003/09/30 15:13:09 joe Exp $

Field Summary
static java.text.SimpleDateFormat dateTimeFormatter
          The date-time formatter.
protected  java.lang.String day
          The day of the month.
protected  java.lang.String hour
          The hour.
private  int iDay
          The integer values for the date represented by this bean.
private  int iHour
          The integer values for the date represented by this bean.
private  int iMinute
          The integer values for the date represented by this bean.
private  int iMonth
          The integer values for the date represented by this bean.
private  int iYear
          The integer values for the date represented by this bean.
protected  java.lang.String minute
          The minute.
protected  java.lang.String month
          The month number (1-12).
private static java.lang.String[] months
          The months of the year {"Jan","Feb", etc}.
protected  java.lang.String year
          The year.
 
Fields inherited from class java.util.Date
 
Constructor Summary
DateBean()
          Default constructor sets the date, day, month, and year to today, and the time to the current time.
DateBean(java.util.Date d)
          Constructor sets the date, day, month, and year from a Date.
 
Method Summary
 int age()
          If this bean represented the date of birth of someone how old would they be in years.
 boolean equals(java.lang.Object obj)
          Compares this DateBean with another object for equality.
 boolean equalsDay(java.lang.Object obj)
          Compares the day of this DateBean with another object for equality.
static DateBean fromSql(java.lang.Object result)
          Generate a DateBean from an object returned from a JDBC SQL query.
 java.lang.String getDateTimeDisplay()
          Show this date in the format 'DD-MON-YYYY HH:MM'.
 java.lang.String getDayString()
          Get the day of the month.
 java.lang.String getDisplay()
          Show this date in the format 'DD-MON-YYYY'.
 java.lang.String getHourString()
          Get the hour.
 java.lang.String getMinuteString()
          Get the minute.
 java.lang.String getMonthString()
          Get the month number (1-12).
 java.lang.String getYearString()
          Get the year.
 boolean isValid()
          Check whether the date and time fields are valid and update the date accordingly.
 boolean isValid(boolean past)
          Check whether the date and time fields are valid and represent a valid date in the future/past, and update the date accordingly.
 void setDayString(java.lang.String day)
          Set the day of the month.
 void setFields()
          Set the day, month, and year fields from the internal Date object.
 void setHourString(java.lang.String hour)
          Set the hour.
 void setMinuteString(java.lang.String minute)
          Set the minute.
 void setMonthString(java.lang.String month)
          Set the month number (1-12).
 void setYearString(java.lang.String year)
          Set the year.
static java.lang.String toSql(DateBean date)
          Deprecated. This method seems buggy under Oracle. Instead, just pass the java.util.Date object straight to RuntimeDataSource.save(...); it will format it correctly.
 java.lang.String toString()
          Show this date in the format 'DD-MON-YYYY HH:MM'
 
Methods inherited from class java.util.Date
after, before, clone, compareTo, compareTo, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

months

private static final java.lang.String[] months
The months of the year {"Jan","Feb", etc}.


iYear

private int iYear
The integer values for the date represented by this bean.


iMonth

private int iMonth
The integer values for the date represented by this bean.


iDay

private int iDay
The integer values for the date represented by this bean.


iHour

private int iHour
The integer values for the date represented by this bean.


iMinute

private int iMinute
The integer values for the date represented by this bean.


dateTimeFormatter

public static final java.text.SimpleDateFormat dateTimeFormatter
The date-time formatter.


day

protected java.lang.String day
The day of the month.


month

protected java.lang.String month
The month number (1-12).


year

protected java.lang.String year
The year.


hour

protected java.lang.String hour
The hour.


minute

protected java.lang.String minute
The minute.

Constructor Detail

DateBean

public DateBean()
Default constructor sets the date, day, month, and year to today, and the time to the current time.


DateBean

public DateBean(java.util.Date d)
Constructor sets the date, day, month, and year from a Date. If date is null then sets values to today.

Method Detail

setDayString

public void setDayString(java.lang.String day)
Set the day of the month.


getDayString

public java.lang.String getDayString()
Get the day of the month.


setMonthString

public void setMonthString(java.lang.String month)
Set the month number (1-12).


getMonthString

public java.lang.String getMonthString()
Get the month number (1-12).


setYearString

public void setYearString(java.lang.String year)
Set the year.


getYearString

public java.lang.String getYearString()
Get the year.


setHourString

public void setHourString(java.lang.String hour)
Set the hour.


getHourString

public java.lang.String getHourString()
Get the hour.


setMinuteString

public void setMinuteString(java.lang.String minute)
Set the minute.


getMinuteString

public java.lang.String getMinuteString()
Get the minute.


setFields

public void setFields()
Set the day, month, and year fields from the internal Date object.


isValid

public boolean isValid(boolean past)
Check whether the date and time fields are valid and represent a valid date in the future/past, and update the date accordingly.


isValid

public boolean isValid()
Check whether the date and time fields are valid and update the date accordingly.


toString

public java.lang.String toString()
Show this date in the format 'DD-MON-YYYY HH:MM'


getDisplay

public java.lang.String getDisplay()
Show this date in the format 'DD-MON-YYYY'. NB this method is equivalen to `toString', but uses the getter bean property method convention.


getDateTimeDisplay

public java.lang.String getDateTimeDisplay()
Show this date in the format 'DD-MON-YYYY HH:MM'. NB this method is equivalen to `toString', but uses the getter bean property method convention.


toSql

public static java.lang.String toSql(DateBean date)
Deprecated. This method seems buggy under Oracle. Instead, just pass the java.util.Date object straight to RuntimeDataSource.save(...); it will format it correctly.

Convert this date bean to a format suitable for insertion into a SQL Date column.


fromSql

public static DateBean fromSql(java.lang.Object result)
Generate a DateBean from an object returned from a JDBC SQL query.


age

public int age()
If this bean represented the date of birth of someone how old would they be in years. If the date is in the future, then the result will be < 1.

NB this DateBean should be validated using isValid() before calling this method. The results of calling this on an un-validated date are unpredictable.


equals

public boolean equals(java.lang.Object obj)
Compares this DateBean with another object for equality. The result is true if and only if the argument is not null and is a Date or DateBean object that represents the same point in time, to the minute, as this object. Seconds and millis are ignored. Throws a ClassCastException if the object is not a DateBean nor a Date, says false if the object is null.


equalsDay

public boolean equalsDay(java.lang.Object obj)
Compares the day of this DateBean with another object for equality. The result is true if and only if the argument is not null and is a Date or DateBean object that represents the same point in time, to the day (eg Year, Month, Day), as this object. Hours, Minutes, Seconds and millis are ignored.