| java.lang.Object org.cougaar.util.ShortDateFormat
ShortDateFormat | public class ShortDateFormat (Code) | | Short form date formatter, using "month/day/year" (e.g. 10/20/1999).
Easier to use and does better error checking than
java.text.SimpleDateFormat .
See method main() at end for sample usage.
|
Method Summary | |
public static Date | adjustDate(Date date, int months, int days) Helper for adjusting a given date. | public static Date | fixTime(Date date) | protected static boolean | isValid(String sDate) DateFormat seems to do a lousy job at parsing the
date -- it allows all sorts of mistakes (e.g. | protected static int | readDigits(String s, int iStart, int minDigits, int maxDigits) read digits from given string and starting position. | public Date | toDate(String sDate) Parameters: sDate - Short date string (e.g. | public Date | toDate(String sDate, boolean doFixTime) Parameters: sDate - Short date string (e.g. | public String | toString(Date date) |
ShortDateFormat | public ShortDateFormat()(Code) | | |
adjustDate | public static Date adjustDate(Date date, int months, int days)(Code) | | Helper for adjusting a given date.
Parameters: date - date to adjust (current date if null) Parameters: months - adjust by number of months Parameters: days - adjust by number of days adjusted date |
fixTime | public static Date fixTime(Date date)(Code) | | Helper for filling hour:minute:second of a given date to
current hour:minute:second, since default is 0:00:00
Parameters: date - date needing hour:minute:second filled date |
isValid | protected static boolean isValid(String sDate)(Code) | | DateFormat seems to do a lousy job at parsing the
date -- it allows all sorts of mistakes (e.g. "12/12/1x944", etc).
What we want in BNF is:
digit := ('0'..'9')
slash := '/'
days := (digit | (digit digit))
months := (digit | (digit digit))
years := (digit digit digit digit)
date := months slash days slash years
We'll let the myDateFormatter check the digit values.
Note: Doesn't check values! "99/99/9999" is "valid"!
Parameters: sDate - Short date string (e.g. "10/20/1999") true if sDate format is valid |
readDigits | protected static int readDigits(String s, int iStart, int minDigits, int maxDigits)(Code) | | read digits from given string and starting position. check that
the given range of digits were read.
|
toDate | public Date toDate(String sDate)(Code) | | Parameters: sDate - Short date string (e.g. "10/20/1999") Corresponding Date |
toDate | public Date toDate(String sDate, boolean doFixTime)(Code) | | Parameters: sDate - Short date string (e.g. "10/20/1999") Parameters: doFixTime - if true then adjust hour:minute to current hour:minute Corresponding Date |
toString | public String toString(Date date)(Code) | | Parameters: date - date to convert to string date string |
|
|