test/org/ohmage/test/ParameterSets.java
private static void initDateValues() {
    Calendar epochCalendar = Calendar.getInstance();
    TimeZone tz = epochCalendar.getTimeZone();
    int offset = tz.getOffset(0) * -1;

    // This is the epoch because we are 8 hours behind and that's how our
    // current system bases its calculations. In the future, we may want to
    // get rid of the date values and go only with the epoch millis.

    epochCalendar.setTimeInMillis(offset);

    Calendar currCalendar = Calendar.getInstance();

    // Test at the epoch.
    currCalendar.setTimeInMillis(epochCalendar.getTimeInMillis());

    dateToString.put(new DateTime(offset), "1970-01-01");
    dateTimeToString.put(new DateTime(offset), "1970-01-01 00:00:00");

    invalidDates.add("1970-13-01");
    invalidDateTimes.add("1970-13-01 00:00:00");

    invalidDates.add("1970-01-32");
    invalidDateTimes.add("1970-01-32 00:00:00");

    invalidDates.add("1970-13-32");
    invalidDateTimes.add("1970-13-32 00:00:00");

    // FIXME:
    // The problem with testing the times is that the validators will first
    // attempt to validate the date as a date-time. If that fails, it will
    // fall back to a date only value which will ignore the rest of the 
    // string, i.e. the time component, and will let it succeed.
    //
    // One fix is to add the ones with valid dates but invalid times to the
    // dateTimeToString map and always set the date to be 1970-01-01
    // 00:00:00. Then, add the ones with invalid dates to the  
    // invalidDateTimes collection. 
    // 
    // Another solution is to be even more restrictive and leave these as
    // they are but add a pattern matcher to the StringUtils to prevent
    // dates that contain more than they are supposed to from passing 
    // validation. First, the string is matched against a date-time 
    // pattern. If it matches, a date-time is attempted to be decoded or
    // null is returned. If it doesn't match, it is matched against a date
    // pattern. If it matches, a date is attempted to be decoded or null is
    // returned.
    //
    // I originally created the SimpleDateFormatters as lenient because I
    // thought we were going for a "be lenient in what you expect and 
    // strict in what you return" philosophy. We would do our best to try 
    // and decode whatever you gave us into something meaningful if we 
    // could. I understand that this may cause some confusion on the 
    // client's end if they are sending us some really weird data, but the
    // old addage, "garbage in, garbage out" comes to mind. Either way, let
    // me know what you decide, and I will make it work.
		/*
     * invalidDateTimes.add("1970-01-01 24:00:00");
     *
     * invalidDateTimes.add("1970-13-32 24:00:00");
     *
     * invalidDateTimes.add("1970-01-01 00:60:00");
     *
     * invalidDateTimes.add("1970-13-32 24:60:00");
     *
     * invalidDateTimes.add("1970-01-01 00:00:60");
     *
     * invalidDateTimes.add("1970-13-32 24:60:60");
     */

    System.out.println("Valid dates generated:");
    for (String dates : dateToString.values()) {
      System.out.println("\t" + dates);
    }
    System.out.println();

    System.out.println("Valid date-times generated:");
    for (String dateTime : dateTimeToString.values()) {
      System.out.println("\t" + dateTime);
    }
    System.out.println();
  }
/**
   * Populates the date map with Date objects and their corresponding String
   * representations for testing.
   */
Populates the date map with Date objects and their corresponding String
representations for testing.
Populates the date map with Date objects and their corresponding String representations for testing .
private static void initDateValues() {
    Calendar epochCalendar = Calendar.getInstance();
    TimeZone tz = epochCalendar.getTimeZone();
    int offset = tz.getOffset(0) * -1;
    epochCalendar.setTimeInMillis(offset);
    Calendar currCalendar = Calendar.getInstance();
    currCalendar.setTimeInMillis(epochCalendar.getTimeInMillis());
    dateToString.put(new DateTime(offset), "1970-01-01");
    dateTimeToString.put(new DateTime(offset), "1970-01-01 00:00:00");
    invalidDates.add("1970-13-01");
    invalidDateTimes.add("1970-13-01 00:00:00");
    invalidDates.add("1970-01-32");
    invalidDateTimes.add("1970-01-32 00:00:00");
    invalidDates.add("1970-13-32");
    invalidDateTimes.add("1970-13-32 00:00:00");
     One fix is to add the ones with valid dates but invalid times to the
     dateTimeToString map and always set the date to be 1970-01-01
     00:00:00. Then, add the ones with invalid dates to the  
     invalidDateTimes collection. 
     Another solution is to be even more restrictive and leave these as
     they are but add a pattern matcher to the StringUtils to prevent
     dates that contain more than they are supposed to from passing 
     validation. First, the string is matched against a date-time 
     pattern. If it matches, a date-time is attempted to be decoded or
     null is returned. If it doesn't match, it is matched against a date
     pattern. If it matches, a date is attempted to be decoded or null is
     returned.
     I originally created the SimpleDateFormatters as lenient because I
     thought we were going for a "be lenient in what you expect and 
     strict in what you return" philosophy. We would do our best to try 
     and decode whatever you gave us into something meaningful if we 
     could. I understand that this may cause some confusion on the 
     client's end if they are sending us some really weird data, but the
     old addage, "garbage in, garbage out" comes to mind. Either way, let
     me know what you decide, and I will make it work.
		/*
     * invalidDateTimes.add("1970-01-01 24:00:00");
     *
     * invalidDateTimes.add("1970-13-32 24:00:00");
     *
     * invalidDateTimes.add("1970-01-01 00:60:00");
     *
     * invalidDateTimes.add("1970-13-32 24:60:00");
     *
     * invalidDateTimes.add("1970-01-01 00:00:60");
     *
     * invalidDateTimes.add("1970-13-32 24:60:60");
     */
    System.out.println("Valid dates generated:");
    for (String dates : dateToString.values()) {
      System.out.println("\t" + dates);
    }
    System.out.println();
    System.out.println("Valid date-times generated:");
    for (String dateTime : dateTimeToString.values()) {
      System.out.println("\t" + dateTime);
    }
    System.out.println();
  }
private static void initDateValues ( ) { Calendar epochCalendar = Calendar . getInstance ( ) ; TimeZone tz = epochCalendar . getTimeZone ( ) ; int offset = tz . getOffset ( 0 ) * - 1 ; epochCalendar . setTimeInMillis ( offset ) ; Calendar currCalendar = Calendar . getInstance ( ) ; currCalendar . setTimeInMillis ( epochCalendar . getTimeInMillis ( ) ) ; dateToString . put ( new DateTime ( offset ) , "1970-01-01" ) ; dateTimeToString . put ( new DateTime ( offset ) , "1970-01-01 00:00:00" ) ; invalidDates . add ( "1970-13-01" ) ; invalidDateTimes . add ( "1970-13-01 00:00:00" ) ; invalidDates . add ( "1970-01-32" ) ; invalidDateTimes . add ( "1970-01-32 00:00:00" ) ; invalidDates . add ( "1970-13-32" ) ; invalidDateTimes . add ( "1970-13-32 00:00:00" ) ; /*
     * invalidDateTimes.add("1970-01-01 24:00:00");
     *
     * invalidDateTimes.add("1970-13-32 24:00:00");
     *
     * invalidDateTimes.add("1970-01-01 00:60:00");
     *
     * invalidDateTimes.add("1970-13-32 24:60:00");
     *
     * invalidDateTimes.add("1970-01-01 00:00:60");
     *
     * invalidDateTimes.add("1970-13-32 24:60:60");
     */ System . out . println ( "Valid dates generated:" ) ; for ( String dates : dateToString . values ( ) ) { System . out . println ( "\t" + dates ) ; } System . out . println ( ) ; System . out . println ( "Valid date-times generated:" ) ; for ( String dateTime : dateTimeToString . values ( ) ) { System . out . println ( "\t" + dateTime ) ; } System . out . println ( ) ; }
Populates the date map with Date objects and their corresponding String
 representations for testing.
Populates the date map with Date objects and their corresponding String representations for testing .
// This is the epoch because we are 8 hours behind and that's how our // current system bases its calculations. In the future, we may want to // get rid of the date values and go only with the epoch millis. // Test at the epoch. // FIXME: // The problem with testing the times is that the validators will first // attempt to validate the date as a date-time. If that fails, it will // fall back to a date only value which will ignore the rest of the  // string, i.e. the time component, and will let it succeed. // // One fix is to add the ones with valid dates but invalid times to the // dateTimeToString map and always set the date to be 1970-01-01 // 00:00:00. Then, add the ones with invalid dates to the   // invalidDateTimes collection.  //  // Another solution is to be even more restrictive and leave these as // they are but add a pattern matcher to the StringUtils to prevent // dates that contain more than they are supposed to from passing  // validation. First, the string is matched against a date-time  // pattern. If it matches, a date-time is attempted to be decoded or // null is returned. If it doesn't match, it is matched against a date // pattern. If it matches, a date is attempted to be decoded or null is // returned. // // I originally created the SimpleDateFormatters as lenient because I // thought we were going for a "be lenient in what you expect and  // strict in what you return" philosophy. We would do our best to try  // and decode whatever you gave us into something meaningful if we  // could. I understand that this may cause some confusion on the  // client's end if they are sending us some really weird data, but the // old addage, "garbage in, garbage out" comes to mind. Either way, let // me know what you decide, and I will make it work.