public class VerifyDateFormat extends SimpleDateFormat
Note: This class is designed to adhere strictly to the description of the date format string in the JDK docs for java.text.SimpleDateFormat. This means that I throw an Exception on the string "'hi there", even though SimpleDateFormat is lenient and interprets it as "'hi there'".
There exist some minor bugs in the 1.1.8 implementation of java.text.SimpleDateFormat. As an example, the format string "'''hi'" results in dates looking like "''hi" when they should look like "'hi". These bugs have been fixed by JDK 1.2.2_06. So far as I know, my verifier parses strings correctly and strictly, which means that some strings that worked with the 1.1.8 SimpleDateFormat might not work with VerifyDateFormat. This is fine though, since we don't want to allow Strings that don't work with 1.2.2
DateFormat.Field
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
Constructor and Description |
---|
VerifyDateFormat(String format)
Constructor that mirrors SimpleDateFormat(String)
|
VerifyDateFormat(String format,
DateFormatSymbols dfs)
Constructor that mirrors SimpleDateFormat(String, DateFormatSymbols)
|
VerifyDateFormat(String format,
Locale loc)
Constructor that mirrors SimpleDateFormat(String, Locale)
|
Modifier and Type | Method and Description |
---|---|
protected static int |
eatLiteralString(String str,
int i)
Advances to the end of the current literal string.
|
protected static boolean |
isCharValid(char ch)
Checks whether the given character is valid (according to the
javadoc for SimpleDateFormat)
|
static boolean |
isFormatStringValid(String str)
Checks whether the given date format string is valid (according to the
javadoc for SimpleDateFormat)
|
applyLocalizedPattern, applyPattern, clone, equals, format, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, parse, set2DigitYearStart, setDateFormatSymbols, toLocalizedPattern, toPattern
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
format, parseObject
public VerifyDateFormat(String format)
IllegalArgumentException
- if the format is invalidpublic VerifyDateFormat(String format, DateFormatSymbols dfs)
IllegalArgumentException
- if the format is invalidpublic VerifyDateFormat(String format, Locale loc)
IllegalArgumentException
- if the format is invalidpublic static boolean isFormatStringValid(String str)
str
- the string to test for validityprotected static int eatLiteralString(String str, int i)
Date format strings can have literal strings enclosed in ' characters. Everything within the ' characters is to be treated literally, except for ' characters themselves. If two ' in a row occur, they are treated as one ', and the literal string continues.
This function takes in a string to parse, and an index indicating the location of the opening '. It returns an index indicating the location of the ending '.
If the literal string doesn't end, or on other errors, this returns -1.
str
- the stringi
- the index into the stringprotected static boolean isCharValid(char ch)
ch
- the character to test for validityCopyright © 2023. All rights reserved.