src/org/ohmage/domain/campaign/prompt/TimestampPrompt.java
@Override
	public Object validateValue(final Object value) throws DomainException {
		// If it's already a NoResponse value, then return make sure that if it
		// was skipped that it as skippable.
		if(value instanceof NoResponse) {
			if(NoResponse.SKIPPED.equals(value) && (! skippable())) {
				throw new DomainException(
						"The prompt, '" +
							getId() +
							"', was skipped, but it is not skippable.");
			}
			
			return value;
		}
		// If it's already a DateTime, return it.
		else if(value instanceof DateTime) {
			return value;
		}
		// If it's a Date, convert it to a DateTime and return it.
		else if(value instanceof Date) {
			return new DateTime(((Date) value).getTime());
		}
		// If it's a Calendar, convert it to a DateTime and return it.
		else if(value instanceof Calendar) {
			Calendar calValue = (Calendar) value;
			return new DateTime(
					calValue.getTimeInMillis(), 
					DateTimeZone.forTimeZone(calValue.getTimeZone()));
		}
		// If it's a String, attempt to convert it to a DateTime and return it.
		else if(value instanceof String) {
			try {
				return NoResponse.valueOf((String) value);
			}
			catch(IllegalArgumentException notNoResponse) {
				try {
					return DateTimeUtils.getDateTimeFromString((String) value);
				}
				catch(IllegalArgumentException notOurDateTime) {
					try {
						return
							ISODateTimeFormat
								.dateTimeParser()
								.withOffsetParsed()
								.parseDateTime((String) value);
					}
					catch(IllegalArgumentException notIsoDateTime) {
						throw new DomainException(
							"The string value could not be converted to a date for prompt '" +
								getId() +
								"'.",
							notIsoDateTime);
					}
				}
			}
		}
		
		throw new DomainException(
				"The value could not be converted to a valid date for prompt '" +
					getId() +
					"'.");
	}
/**
	 * Validates that a given value is valid and, if so, converts it into an
	 * appropriate object.
	 * 
	 * @param value The value to be validated. This must be one of the  
	 * 				following:<br />
	 * 				<ul>
	 * 				<li>{@link NoResponse}</li>
	 * 				<li>{@link Date}</li>
	 * 				<li>{@link Calendar}</li>
	 * 				<li>{@link String} that represents:</li>
	 * 				  <ul>
	 * 				    <li>{@link NoResponse}</li>
	 * 				    <li>ISO 8601 formatted date with or without the time.
	 * 				      </li>
	 * 				  <ul>
	 * 				</ul>
	 * 
	 * @return A Date object or a {@link NoResponse} object.
	 * 
	 * @throws DomainException The value is invalid.
	 */
Validates that a given value is valid and, if so, converts it into an
appropriate object.

@param value The value to be validated. This must be one of the
following:

 NoResponse
 Date
 Calendar
 String that represents:

 NoResponse
ISO 8601 formatted date with or without the time.

@return A Date object or a  NoResponse object.

@throws DomainException The value is invalid.
Validates that a given value is valid and if so converts it into an appropriate object . @param value The value to be validated . This must be one of the following : NoResponse Date Calendar String that represents : NoResponse ISO 8601 formatted date with or without the time . @return A Date object or a NoResponse object . @throws DomainException The value is invalid .
@Override
	public Object validateValue(final Object value) throws DomainException {
		if(value instanceof NoResponse) {
			if(NoResponse.SKIPPED.equals(value) && (! skippable())) {
				throw new DomainException(
						"The prompt, '" +
							getId() +
							"', was skipped, but it is not skippable.");
			}
			return value;
		}
		else if(value instanceof DateTime) {
			return value;
		}
		else if(value instanceof Date) {
			return new DateTime(((Date) value).getTime());
		}
		else if(value instanceof Calendar) {
			Calendar calValue = (Calendar) value;
			return new DateTime(
					calValue.getTimeInMillis(), 
					DateTimeZone.forTimeZone(calValue.getTimeZone()));
		}
		else if(value instanceof String) {
			try {
				return NoResponse.valueOf((String) value);
			}
			catch(IllegalArgumentException notNoResponse) {
				try {
					return DateTimeUtils.getDateTimeFromString((String) value);
				}
				catch(IllegalArgumentException notOurDateTime) {
					try {
						return
							ISODateTimeFormat
								.dateTimeParser()
								.withOffsetParsed()
								.parseDateTime((String) value);
					}
					catch(IllegalArgumentException notIsoDateTime) {
						throw new DomainException(
							"The string value could not be converted to a date for prompt '" +
								getId() +
								"'.",
							notIsoDateTime);
					}
				}
			}
		}
		throw new DomainException(
				"The value could not be converted to a valid date for prompt '" +
					getId() +
					"'.");
	}
@ Override public Object validateValue ( final Object value ) throws DomainException { if ( value instanceof NoResponse ) { if ( NoResponse . SKIPPED . equals ( value ) && ( ! skippable ( ) ) ) { throw new DomainException ( "The prompt, '" + getId ( ) + "', was skipped, but it is not skippable." ) ; } return value ; } else if ( value instanceof DateTime ) { return value ; } else if ( value instanceof Date ) { return new DateTime ( ( ( Date ) value ) . getTime ( ) ) ; } else if ( value instanceof Calendar ) { Calendar calValue = ( Calendar ) value ; return new DateTime ( calValue . getTimeInMillis ( ) , DateTimeZone . forTimeZone ( calValue . getTimeZone ( ) ) ) ; } else if ( value instanceof String ) { try { return NoResponse . valueOf ( ( String ) value ) ; } catch ( IllegalArgumentException notNoResponse ) { try { return DateTimeUtils . getDateTimeFromString ( ( String ) value ) ; } catch ( IllegalArgumentException notOurDateTime ) { try { return ISODateTimeFormat . dateTimeParser ( ) . withOffsetParsed ( ) . parseDateTime ( ( String ) value ) ; } catch ( IllegalArgumentException notIsoDateTime ) { throw new DomainException ( "The string value could not be converted to a date for prompt '" + getId ( ) + "'." , notIsoDateTime ) ; } } } } throw new DomainException ( "The value could not be converted to a valid date for prompt '" + getId ( ) + "'." ) ; }
Validates that a given value is valid and, if so, converts it into an
 appropriate object.
Validates that a given value is valid and if so converts it into an appropriate object .
// If it's already a NoResponse value, then return make sure that if it // was skipped that it as skippable. // If it's already a DateTime, return it. // If it's a Date, convert it to a DateTime and return it. // If it's a Calendar, convert it to a DateTime and return it. // If it's a String, attempt to convert it to a DateTime and return it.