iglu.util
Class CalendarParser

java.lang.Object
  |
  +--iglu.util.CalendarParser

public class CalendarParser
extends java.lang.Object

Takes a date string, figures out what its format it, and tell you the month, date, and year numbers. Useful in database applications where users will be manually entering dates. This class lets your program support multiple date formats for entry. Also automatically adjusts for two digit year problems. If the year is entered in two digits (e.g. 99), the class will assume that the year is either 30 years in the future or seventy years in the past.

Author:
Travis BauerTravis Bauer

Nested Class Summary
 class CalendarParser.InvalidDateFormatException
           
 
Field Summary
(package private)  int date
          Parsed day number
(package private)  java.lang.String dateString
          The input string
(package private)  int month
          Parsed Value of the Month
(package private)  int year
          Parsed Year number
 
Constructor Summary
CalendarParser(java.lang.String nDateString)
          Creates new CalendarParser
 
Method Summary
 int date()
          Returns the day of the parsed date
protected  java.lang.String dropLeadZero(java.lang.String s)
          Protected utility to drop a zero from the front of the string.
static void main(java.lang.String[] argv)
          Takes a date as a parameter, and returns the month, day, and year number.
 int month()
          Returns the month of the parsed date
protected  void parseAmerDate()
          handles dates in the form MM/DD/YY and MM/DD/YYYY Yes, I know there is some ambiguity here.
protected  void parseNumberDate()
          Handles dates in the form MMDDYY and MMDDYYYY
protected  void parseSqlDate()
          Handles dates in the form YYYY-MM-DD.
protected  int realYear(int year)
          Given a two or four digit year, converts it into the appropriate four digit year.
 int year()
          Returns the year of the parsed date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

month

int month
Parsed Value of the Month


date

int date
Parsed day number


year

int year
Parsed Year number


dateString

java.lang.String dateString
The input string

Constructor Detail

CalendarParser

public CalendarParser(java.lang.String nDateString)
Creates new CalendarParser

Parameters:
nDateString - The string version of the date
Method Detail

month

public int month()
Returns the month of the parsed date


date

public int date()
Returns the day of the parsed date


year

public int year()
Returns the year of the parsed date


parseAmerDate

protected void parseAmerDate()
handles dates in the form MM/DD/YY and MM/DD/YYYY Yes, I know there is some ambiguity here. I'm assuming the American convention of Months before dates. Go ahead and fix this. Y2K adjustments are made for dates that are entered with two digit dates. It assumes that the dates are either 30 years into the future or 70 years into the past.


parseSqlDate

protected void parseSqlDate()
Handles dates in the form YYYY-MM-DD. Called Sql format because that's what JDBC specifies.


parseNumberDate

protected void parseNumberDate()
Handles dates in the form MMDDYY and MMDDYYYY


dropLeadZero

protected java.lang.String dropLeadZero(java.lang.String s)
Protected utility to drop a zero from the front of the string.

Parameters:
s -

realYear

protected int realYear(int year)
Given a two or four digit year, converts it into the appropriate four digit year.

Parameters:
year -

main

public static void main(java.lang.String[] argv)
Takes a date as a parameter, and returns the month, day, and year number.

Parameters:
argv -