net.sourceforge.annovalidator.util
Class DateUtil
java.lang.Object
net.sourceforge.annovalidator.util.DateUtil
public class DateUtil
- extends java.lang.Object
Utility for parsing and converting Date
s.
Nested Class Summary |
static interface |
DateUtil.CompositeDatePart
Identifies a part of a date, along with the field used
to specify its value. |
static class |
DateUtil.DatePartType
Identifies part of a date, and identifies the format pattern
required to parse that portion of the date. |
static interface |
DateUtil.DateSource
Specifies a date to be passed as an argument to a validator. |
Method Summary |
static java.util.Date |
constructFromComposite(DateUtil.CompositeDatePart[] dateParts,
java.lang.Object target,
java.lang.String invalidDatePartErrorCode)
|
static java.util.Date |
convertToDate(DateUtil.DateSource dateSource,
java.lang.Object fieldValue,
java.lang.Object object,
java.lang.String invalidDatePartErrorCode)
|
static java.util.Date |
convertToDate(java.lang.Object object,
java.lang.String[] dateFormats)
Attempts to convert object to a Date using
one of the following conversion strategies:
If object is a Date , then is it returned
verbatim.
If object is a Long then it is parsed as
a time in milliseconds.
If object is a String then the following
strategies are attempted:
If dateFormat contains a conversion pattern
then object is parsed using that pattern.
If no dateFormat is provided, then the system
will attempt to determine the appropriate conversion
pattern by itself.
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_DATE_FORMATS
public static final java.lang.String[][] DEFAULT_DATE_FORMATS
DateUtil
public DateUtil()
convertToDate
public static java.util.Date convertToDate(DateUtil.DateSource dateSource,
java.lang.Object fieldValue,
java.lang.Object object,
java.lang.String invalidDatePartErrorCode)
throws ReportedValidationException,
java.text.ParseException
- Throws:
ReportedValidationException
java.text.ParseException
constructFromComposite
public static java.util.Date constructFromComposite(DateUtil.CompositeDatePart[] dateParts,
java.lang.Object target,
java.lang.String invalidDatePartErrorCode)
throws ReportedValidationException,
java.text.ParseException
- Throws:
ReportedValidationException
java.text.ParseException
convertToDate
public static java.util.Date convertToDate(java.lang.Object object,
java.lang.String[] dateFormats)
throws java.text.ParseException
- Attempts to convert
object
to a Date
using
one of the following conversion strategies:
- If
object
is a Date
, then is it returned
verbatim.
- If
object
is a Long
then it is parsed as
a time in milliseconds.
- If
object
is a String
then the following
strategies are attempted:
- If
dateFormat
contains a conversion pattern
then object
is parsed using that pattern.
- If no
dateFormat
is provided, then the system
will attempt to determine the appropriate conversion
pattern by itself.
- Parameters:
object
- An Object
containing a date that can be parsed.dateFormats
- The conversion pattern used to parse a text date.
- Returns:
- A
Date
obtained by parsing object
.
- Throws:
java.text.ParseException
- If object
cannot be converted to a
Date
.
Copyright © 2008. All Rights Reserved.