public static int getDaysBetween(final String date1, final String date2, String format) {
   try {
     final DateTimeFormatter fmt =
         DateTimeFormat.forPattern(format)
             .withChronology(LenientChronology.getInstance(GregorianChronology.getInstance()));
     return Days.daysBetween(fmt.parseDateTime(date1), fmt.parseDateTime(date2)).getDays();
   } catch (Exception ex) {
     ex.printStackTrace();
     return 0;
   }
 }
  /**
   * Given a year, month, and day, find the number of occurrences of that day in the month
   *
   * @param year the year
   * @param month the month
   * @param day the day
   * @return the number of occurrences of the day in the month
   */
  public int numOccurrences(int year, int month, int day) {
    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime date = parser.parseDateTime(year + "-" + month + "-" + "01");
    Calendar cal = Calendar.getInstance();
    cal.setTime(date.toDate());
    GregorianChronology calendar = GregorianChronology.getInstance();
    DateTimeField field = calendar.dayOfMonth();

    int days = 0;
    int count = 0;
    int num = field.getMaximumValue(new LocalDate(year, month, day, calendar));
    while (days < num) {
      if (cal.get(Calendar.DAY_OF_WEEK) == day) {
        count++;
      }
      date = date.plusDays(1);
      cal.setTime(date.toDate());

      days++;
    }
    return count;
  }
  /**
   * Parses the year of the given String, if parsing fails, the current year is returned.
   *
   * @param input
   * @return parsed Integer of the given String, if parsing failed the current year is returned
   */
  private Integer parseYearParameter(String input) {

    // default value for year is the current year
    Integer year = DateMidnight.now(GregorianChronology.getInstance()).getYear();

    if (StringUtils.hasText(input)) {
      try {
        year = Integer.parseInt(input);
      } catch (NumberFormatException ex) {
        LOG.warn("Tried to show overview for an invalid year entry: " + input, ex);
      }
    }

    return year;
  }
  // -----------------------------------------------------------------------
  @SuppressWarnings("deprecation")
  public void testCompareTo() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40);
    LocalTime test1a = new LocalTime(10, 20, 30, 40);
    assertEquals(0, test1.compareTo(test1a));
    assertEquals(0, test1a.compareTo(test1));
    assertEquals(0, test1.compareTo(test1));
    assertEquals(0, test1a.compareTo(test1a));

    LocalTime test2 = new LocalTime(10, 20, 35, 40);
    assertEquals(-1, test1.compareTo(test2));
    assertEquals(+1, test2.compareTo(test1));

    LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(-1, test1.compareTo(test3));
    assertEquals(+1, test3.compareTo(test1));
    assertEquals(0, test3.compareTo(test2));

    DateTimeFieldType[] types =
        new DateTimeFieldType[] {
          DateTimeFieldType.hourOfDay(),
          DateTimeFieldType.minuteOfHour(),
          DateTimeFieldType.secondOfMinute(),
          DateTimeFieldType.millisOfSecond(),
        };
    int[] values = new int[] {10, 20, 30, 40};
    Partial p = new Partial(types, values);
    assertEquals(0, test1.compareTo(p));
    assertEquals(0, test1.compareTo(new TimeOfDay(10, 20, 30, 40)));
    try {
      test1.compareTo(null);
      fail();
    } catch (NullPointerException ex) {
    }
    //        try {
    //            test1.compareTo(new Date());
    //            fail();
    //        } catch (ClassCastException ex) {}
  }
  // -----------------------------------------------------------------------
  public void testIsAfter_LocalTime() {
    LocalTime test1 = new LocalTime(10, 20, 30, 40);
    LocalTime test1a = new LocalTime(10, 20, 30, 40);
    assertEquals(false, test1.isAfter(test1a));
    assertEquals(false, test1a.isAfter(test1));
    assertEquals(false, test1.isAfter(test1));
    assertEquals(false, test1a.isAfter(test1a));

    LocalTime test2 = new LocalTime(10, 20, 35, 40);
    assertEquals(false, test1.isAfter(test2));
    assertEquals(true, test2.isAfter(test1));

    LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC());
    assertEquals(false, test1.isAfter(test3));
    assertEquals(true, test3.isAfter(test1));
    assertEquals(false, test3.isAfter(test2));

    try {
      new LocalTime(10, 20, 35, 40).isAfter(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }
/**
 * This class is a Junit unit test for LocalDate.
 *
 * @author Stephen Colebourne
 */
public class TestLocalDate_Constructors extends TestCase {

  private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
  private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
  private static final Chronology ISO_UTC = ISOChronology.getInstanceUTC();
  private static final Chronology BUDDHIST_UTC = BuddhistChronology.getInstanceUTC();
  private static final Chronology GREGORIAN_UTC = GregorianChronology.getInstanceUTC();
  private static final Chronology GREGORIAN_PARIS = GregorianChronology.getInstance(PARIS);

  private long TEST_TIME_NOW =
      (31L + 28L + 31L + 30L + 31L + 9L - 1L) * DateTimeConstants.MILLIS_PER_DAY;

  private long TEST_TIME1 =
      (31L + 28L + 31L + 6L - 1L) * DateTimeConstants.MILLIS_PER_DAY
          + 12L * DateTimeConstants.MILLIS_PER_HOUR
          + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
  private long TEST_TIME1_ROUNDED = (31L + 28L + 31L + 6L - 1L) * DateTimeConstants.MILLIS_PER_DAY;
  private long TEST_TIME2 =
      (365L + 31L + 28L + 31L + 30L + 7L - 1L) * DateTimeConstants.MILLIS_PER_DAY
          + 14L * DateTimeConstants.MILLIS_PER_HOUR
          + 28L * DateTimeConstants.MILLIS_PER_MINUTE;

  private DateTimeZone zone = null;

  public static void main(String[] args) {
    junit.textui.TestRunner.run(suite());
  }

  public static TestSuite suite() {
    return new TestSuite(TestLocalDate_Constructors.class);
  }

  public TestLocalDate_Constructors(String name) {
    super(name);
  }

  protected void setUp() throws Exception {
    DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
    zone = DateTimeZone.getDefault();
    DateTimeZone.setDefault(LONDON);
  }

  protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(zone);
    zone = null;
  }

  // -----------------------------------------------------------------------
  public void testParse_noFormatter() throws Throwable {
    assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010-06-30"));
    assertEquals(new LocalDate(2010, 1, 2), LocalDate.parse("2010-002"));
  }

  public void testParse_formatter() throws Throwable {
    DateTimeFormatter f =
        DateTimeFormat.forPattern("yyyy--dd MM").withChronology(ISOChronology.getInstance(PARIS));
    assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010--30 06", f));
  }

  // -----------------------------------------------------------------------
  public void testFactory_FromCalendarFields() throws Exception {
    GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6);
    cal.set(Calendar.MILLISECOND, 7);
    LocalDate expected = new LocalDate(1970, 2, 3);
    assertEquals(expected, LocalDate.fromCalendarFields(cal));
    try {
      LocalDate.fromCalendarFields((Calendar) null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testFactory_FromDateFields() throws Exception {
    GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6);
    cal.set(Calendar.MILLISECOND, 7);
    LocalDate expected = new LocalDate(1970, 2, 3);
    assertEquals(expected, LocalDate.fromDateFields(cal.getTime()));
    try {
      LocalDate.fromDateFields((Date) null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  // -----------------------------------------------------------------------
  public void testConstructor() throws Throwable {
    LocalDate test = new LocalDate();
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(test, LocalDate.now());
  }

  public void testConstructor_DateTimeZone() throws Throwable {
    DateTime dt = new DateTime(2005, 6, 8, 23, 59, 0, 0, LONDON);
    DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
    // 23:59 in London is 00:59 the following day in Paris

    LocalDate test = new LocalDate(LONDON);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(2005, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(8, test.getDayOfMonth());
    assertEquals(test, LocalDate.now(LONDON));

    test = new LocalDate(PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(2005, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(test, LocalDate.now(PARIS));
  }

  public void testConstructor_nullDateTimeZone() throws Throwable {
    DateTime dt = new DateTime(2005, 6, 8, 23, 59, 0, 0, LONDON);
    DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
    // 23:59 in London is 00:59 the following day in Paris

    LocalDate test = new LocalDate((DateTimeZone) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(2005, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(8, test.getDayOfMonth());
  }

  public void testConstructor_Chronology() throws Throwable {
    LocalDate test = new LocalDate(GREGORIAN_PARIS);
    assertEquals(GREGORIAN_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(test, LocalDate.now(GREGORIAN_PARIS));
  }

  public void testConstructor_nullChronology() throws Throwable {
    LocalDate test = new LocalDate((Chronology) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }

  // -----------------------------------------------------------------------
  public void testConstructor_long1() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME1);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_long2() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME2);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1971, test.getYear());
    assertEquals(5, test.getMonthOfYear());
    assertEquals(7, test.getDayOfMonth());
  }

  public void testConstructor_long1_DateTimeZone() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME1, PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
    assertEquals(TEST_TIME1_ROUNDED, test.getLocalMillis());
  }

  public void testConstructor_long2_DateTimeZone() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME2, PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1971, test.getYear());
    assertEquals(5, test.getMonthOfYear());
    assertEquals(7, test.getDayOfMonth());
  }

  public void testConstructor_long3_DateTimeZone() throws Throwable {
    DateTime dt = new DateTime(2006, 6, 9, 0, 0, 0, 0, PARIS);
    DateTime dtUTC = new DateTime(2006, 6, 9, 0, 0, 0, 0, DateTimeZone.UTC);

    LocalDate test = new LocalDate(dt.getMillis(), PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(2006, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(dtUTC.getMillis(), test.getLocalMillis());
  }

  public void testConstructor_long4_DateTimeZone() throws Throwable {
    DateTime dt = new DateTime(2006, 6, 9, 23, 59, 59, 999, PARIS);
    DateTime dtUTC = new DateTime(2006, 6, 9, 0, 0, 0, 0, DateTimeZone.UTC);

    LocalDate test = new LocalDate(dt.getMillis(), PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(2006, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(dtUTC.getMillis(), test.getLocalMillis());
  }

  public void testConstructor_long_nullDateTimeZone() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME1, (DateTimeZone) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_long1_Chronology() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME1, GREGORIAN_PARIS);
    assertEquals(GREGORIAN_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_long2_Chronology() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME2, GREGORIAN_PARIS);
    assertEquals(GREGORIAN_UTC, test.getChronology());
    assertEquals(1971, test.getYear());
    assertEquals(5, test.getMonthOfYear());
    assertEquals(7, test.getDayOfMonth());
  }

  public void testConstructor_long_nullChronology() throws Throwable {
    LocalDate test = new LocalDate(TEST_TIME1, (Chronology) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  // -----------------------------------------------------------------------
  public void testConstructor_Object1() throws Throwable {
    Date date = new Date(TEST_TIME1);
    LocalDate test = new LocalDate(date);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_nullObject() throws Throwable {
    LocalDate test = new LocalDate((Object) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }

  public void testConstructor_ObjectString1() throws Throwable {
    LocalDate test = new LocalDate("1972-04-06");
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1972, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_ObjectString2() throws Throwable {
    LocalDate test = new LocalDate("1972-037");
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1972, test.getYear());
    assertEquals(2, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_ObjectString3() throws Throwable {
    LocalDate test = new LocalDate("1972-02");
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1972, test.getYear());
    assertEquals(2, test.getMonthOfYear());
    assertEquals(1, test.getDayOfMonth());
  }

  public void testConstructor_ObjectStringEx1() throws Throwable {
    try {
      new LocalDate("1970-04-06T+14:00");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectStringEx2() throws Throwable {
    try {
      new LocalDate("1970-04-06T10:20:30.040");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectStringEx3() throws Throwable {
    try {
      new LocalDate("1970-04-06T10:20:30.040+14:00");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectStringEx4() throws Throwable {
    try {
      new LocalDate("T10:20:30.040");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectStringEx5() throws Throwable {
    try {
      new LocalDate("T10:20:30.040+14:00");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectStringEx6() throws Throwable {
    try {
      new LocalDate("10:20:30.040");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectStringEx7() throws Throwable {
    try {
      new LocalDate("10:20:30.040+14:00");
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectLocalDate() throws Throwable {
    LocalDate date = new LocalDate(1970, 4, 6, BUDDHIST_UTC);
    LocalDate test = new LocalDate(date);
    assertEquals(BUDDHIST_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_ObjectLocalTime() throws Throwable {
    LocalTime time = new LocalTime(10, 20, 30, 40, BUDDHIST_UTC);
    try {
      new LocalDate(time);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_ObjectLocalDateTime() throws Throwable {
    LocalDateTime dt = new LocalDateTime(1970, 5, 6, 10, 20, 30, 40, BUDDHIST_UTC);
    LocalDate test = new LocalDate(dt);
    assertEquals(BUDDHIST_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(5, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_ObjectYearMonthDay() throws Throwable {
    YearMonthDay date = new YearMonthDay(1970, 4, 6, BUDDHIST_UTC);
    LocalDate test = new LocalDate(date);
    assertEquals(BUDDHIST_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  // -----------------------------------------------------------------------
  public void testConstructor_Object_DateTimeZone() throws Throwable {
    Date date = new Date(TEST_TIME1);
    LocalDate test = new LocalDate(date, PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_nullObject_DateTimeZone() throws Throwable {
    LocalDate test = new LocalDate((Object) null, PARIS);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }

  public void testConstructor_Object_nullDateTimeZone() throws Throwable {
    Date date = new Date(TEST_TIME1);
    LocalDate test = new LocalDate(date, (DateTimeZone) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_nullObject_nullDateTimeZone() throws Throwable {
    LocalDate test = new LocalDate((Object) null, (DateTimeZone) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }

  public void testConstructor_Object_Chronology() throws Throwable {
    Date date = new Date(TEST_TIME1);
    LocalDate test = new LocalDate(date, GREGORIAN_PARIS);
    assertEquals(GREGORIAN_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_nullObject_Chronology() throws Throwable {
    LocalDate test = new LocalDate((Object) null, GREGORIAN_PARIS);
    assertEquals(GREGORIAN_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }

  public void testConstructor_Object_nullChronology() throws Throwable {
    Date date = new Date(TEST_TIME1);
    LocalDate test = new LocalDate(date, (Chronology) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(4, test.getMonthOfYear());
    assertEquals(6, test.getDayOfMonth());
  }

  public void testConstructor_nullObject_nullChronology() throws Throwable {
    LocalDate test = new LocalDate((Object) null, (Chronology) null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }

  // -----------------------------------------------------------------------
  public void testConstructor_int_int_int() throws Throwable {
    LocalDate test = new LocalDate(1970, 6, 9);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    try {
      new LocalDate(Integer.MIN_VALUE, 6, 9);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(Integer.MAX_VALUE, 6, 9);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 0, 9);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 13, 9);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 6, 0);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 6, 31);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    new LocalDate(1970, 7, 31);
    try {
      new LocalDate(1970, 7, 32);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_int_int_int_Chronology() throws Throwable {
    LocalDate test = new LocalDate(1970, 6, 9, GREGORIAN_PARIS);
    assertEquals(GREGORIAN_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    try {
      new LocalDate(Integer.MIN_VALUE, 6, 9, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(Integer.MAX_VALUE, 6, 9, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 0, 9, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 13, 9, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 6, 0, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      new LocalDate(1970, 6, 31, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
    new LocalDate(1970, 7, 31, GREGORIAN_PARIS);
    try {
      new LocalDate(1970, 7, 32, GREGORIAN_PARIS);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }

  public void testConstructor_int_int_int_nullChronology() throws Throwable {
    LocalDate test = new LocalDate(1970, 6, 9, null);
    assertEquals(ISO_UTC, test.getChronology());
    assertEquals(1970, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
  }
}
  /** Graph of duration of tests over time. */
  public Graph getSummaryGraph() {
    // The standard equals doesn't work because two LocalDate objects can
    // be differente even if the date is the same (different internal
    // timestamp)
    Comparator<LocalDate> localDateComparator =
        new Comparator<LocalDate>() {

          @Override
          public int compare(LocalDate d1, LocalDate d2) {
            if (d1.isEqual(d2)) {
              return 0;
            }
            if (d1.isAfter(d2)) {
              return 1;
            }
            return -1;
          }
        };

    // We need a custom comparator for LocalDate objects
    final Map<LocalDate, TestResultSummary> summaries = // new
        // HashMap<LocalDate,
        // TestResultSummary>();
        new TreeMap<LocalDate, TestResultSummary>(localDateComparator);
    LocalDate today =
        new LocalDate(
            System.currentTimeMillis() - dateShift * 6000, GregorianChronology.getInstanceUTC());

    // for each job, for each day, add last build of the day to summary
    for (Job job : getDashboard().getJobs()) {
      Run run = job.getFirstBuild();

      if (run != null) { // execute only if job has builds
        LocalDate runDay =
            new LocalDate(
                run.getTimeInMillis() - dateShift * 60000, GregorianChronology.getInstanceUTC());
        LocalDate firstDay =
            (dateRange != 0)
                ? new LocalDate(
                        System.currentTimeMillis() - dateShift * 6000,
                        GregorianChronology.getInstanceUTC())
                    .minusDays(dateRange)
                : runDay;

        while (run != null) {
          runDay =
              new LocalDate(
                  run.getTimeInMillis() - dateShift * 60000, GregorianChronology.getInstanceUTC());
          Run nextRun = run.getNextBuild();

          if (nextRun != null) {
            LocalDate nextRunDay =
                new LocalDate(
                    nextRun.getTimeInMillis() - dateShift * 60000,
                    GregorianChronology.getInstanceUTC());
            // skip run before firstDay, but keep if next build is
            // after start date
            if (!runDay.isBefore(firstDay)
                || runDay.isBefore(firstDay) && !nextRunDay.isBefore(firstDay)) {
              // if next run is not the same day, use this test to
              // summarize
              if (nextRunDay.isAfter(runDay)) {
                summarize(
                    summaries,
                    run,
                    (runDay.isBefore(firstDay) ? firstDay : runDay),
                    nextRunDay.minusDays(1));
              }
            }
          } else {
            // use this run's test result from last run to today
            summarize(summaries, run, (runDay.isBefore(firstDay) ? firstDay : runDay), today);
          }

          run = nextRun;
        }
      }
    }

    return new Graph(-1, getGraphWidth(), getGraphHeight()) {

      @Override
      protected JFreeChart createGraph() {
        final JFreeChart chart =
            ChartFactory.createStackedAreaChart(
                null, // chart title
                Messages.Dashboard_Date(), // unused
                Messages.Dashboard_Count(), // range axis label
                buildDataSet(summaries), // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                false, // tooltips
                false // urls
                );

        chart.setBackgroundPaint(Color.white);

        final CategoryPlot plot = chart.getCategoryPlot();

        plot.setBackgroundPaint(Color.WHITE);
        plot.setOutlinePaint(null);
        plot.setForegroundAlpha(0.8f);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.black);

        CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
        plot.setDomainAxis(domainAxis);
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        domainAxis.setCategoryMargin(0.0);

        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        StackedAreaRenderer ar = new StackedAreaRenderer2();
        plot.setRenderer(ar);

        switch (getDisplayStatusEnum()) {
          case SUCCESS:
            ar.setSeriesPaint(0, ColorPalette.BLUE);
            break;
          case SKIPPED:
            ar.setSeriesPaint(0, ColorPalette.YELLOW);
            break;
          case FAILED:
            ar.setSeriesPaint(0, ColorPalette.RED);
            break;
          default:
            ar.setSeriesPaint(0, ColorPalette.RED); // Failures.
            ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips.
            ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.
        }

        // crop extra space around the graph
        plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

        return chart;
      }
    };
  }