QuarterlyPeriod implements Period { @Override public String getAsIsoString() { DateTime dt = new DateTime(getStartDate()); return dt.getYear() + "Q" + ((dt.getMonthOfYear() / 3) + 1); } QuarterlyPeriod(Date date); @Override void setStartDate(Date startDate); @Override void setEndDate(Date endDate); @Override Date getStartDate(); @Override Date getEndDate(); @Override String getAsIsoString(); static final String ISO_FORMAT; }
@Test public void testGetAsIsoString() throws ParseException { QuarterlyPeriod qp1 = new QuarterlyPeriod(new SimpleDateFormat( "yyyy-MM-dd").parse("2012-02-25")); QuarterlyPeriod qp2 = new QuarterlyPeriod(new SimpleDateFormat( "yyyy-MM-dd").parse("2012-05-14")); QuarterlyPeriod qp3 = new QuarterlyPeriod(new SimpleDateFormat( "yyyy-MM-dd").parse("2012-07-08")); QuarterlyPeriod qp4 = new QuarterlyPeriod(new SimpleDateFormat( "yyyy-MM-dd").parse("2012-10-29")); String q1 = "2012Q1"; String q2 = "2012Q2"; String q3 = "2012Q3"; String q4 = "2012Q4"; assertEquals(q1, qp1.getAsIsoString()); assertEquals(q2, qp2.getAsIsoString()); assertEquals(q3, qp3.getAsIsoString()); assertEquals(q4, qp4.getAsIsoString()); }