| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DateDataType |
|
| 1.5;1.5 |
| 1 | package us.daveread.utility.formatcheck.format; | |
| 2 | ||
| 3 | import java.text.SimpleDateFormat; | |
| 4 | ||
| 5 | /** | |
| 6 | * <p>Title: DateDataType | |
| 7 | * <p>Description: Represents a date value data type | |
| 8 | * <p>Copyright: Copyright (c) 2005 | |
| 9 | * <p>This program is free software; you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation; either version 2 of the License, or | |
| 12 | * (at your option) any later version. | |
| 13 | * <p>This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * <p>You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | * </p> | |
| 21 | * | |
| 22 | * @author David Read | |
| 23 | * @version $Id: DateDataType.java,v 1.2 2006/06/14 23:32:42 daveread Exp $ | |
| 24 | */ | |
| 25 | public class DateDataType | |
| 26 | extends DataType { | |
| 27 | ||
| 28 | /** The format to create with the supplied format string */ | |
| 29 | private SimpleDateFormat format; | |
| 30 | ||
| 31 | /** | |
| 32 | * Requires a format using the standard java.text.SimpleDateFormat | |
| 33 | * values. | |
| 34 | * | |
| 35 | * @param aDateFormat String The format string defining the acceptable date format | |
| 36 | * @param aDescription String The display description for this date type | |
| 37 | */ | |
| 38 | public DateDataType(String aDateFormat, String aDescription) { | |
| 39 | 12 | super(aDateFormat, aDescription); |
| 40 | 12 | format = new SimpleDateFormat(aDateFormat); |
| 41 | 12 | format.setLenient(false); |
| 42 | 12 | setTypeName("Date"); |
| 43 | 12 | } |
| 44 | ||
| 45 | /** | |
| 46 | * Tests whether the field value is a proper date as defined by the date | |
| 47 | * format. | |
| 48 | * | |
| 49 | * @param fieldValue String The value being checked | |
| 50 | * | |
| 51 | * @return boolean True if the date is valid, false otherwise | |
| 52 | */ | |
| 53 | public boolean isValid(String fieldValue) { | |
| 54 | boolean valid; | |
| 55 | ||
| 56 | try { | |
| 57 | 16 | format.parse(fieldValue); |
| 58 | 9 | valid = true; |
| 59 | } | |
| 60 | 7 | catch (Throwable any) { |
| 61 | 7 | valid = false; |
| 62 | 9 | } |
| 63 | ||
| 64 | 16 | return valid; |
| 65 | } | |
| 66 | } |