@Test public void calculatesQuarterCorrectly() { DateTime dateTime = DateTime.now(); DateTime startOfQuarter = DateTimeUtils.withStartOfQuarter(dateTime.withMonthOfYear(2)); Assert.assertEquals(1, startOfQuarter.monthOfYear().get()); startOfQuarter = DateTimeUtils.withStartOfQuarter(dateTime.withMonthOfYear(5)); Assert.assertEquals(4, startOfQuarter.monthOfYear().get()); startOfQuarter = DateTimeUtils.withStartOfQuarter(dateTime.withMonthOfYear(8)); Assert.assertEquals(7, startOfQuarter.monthOfYear().get()); startOfQuarter = DateTimeUtils.withStartOfQuarter(dateTime.withMonthOfYear(11)); Assert.assertEquals(10, startOfQuarter.monthOfYear().get()); }
public static DateTime withStartOfQuarter(DateTime dateTime) { int monthOfYear = dateTime.getMonthOfYear(); DateTime firstMonthOfQuarter; if (monthOfYear >= DateTimeConstants.OCTOBER) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.OCTOBER); } else if (monthOfYear >= DateTimeConstants.JULY) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JULY); } else if (monthOfYear >= DateTimeConstants.APRIL) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.APRIL); } else { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JANUARY); } return firstMonthOfQuarter.withDayOfMonth(1); }
DateTimeUtils { public static DateTime withStartOfQuarter(DateTime dateTime) { int monthOfYear = dateTime.getMonthOfYear(); DateTime firstMonthOfQuarter; if (monthOfYear >= DateTimeConstants.OCTOBER) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.OCTOBER); } else if (monthOfYear >= DateTimeConstants.JULY) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JULY); } else if (monthOfYear >= DateTimeConstants.APRIL) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.APRIL); } else { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JANUARY); } return firstMonthOfQuarter.withDayOfMonth(1); } }
DateTimeUtils { public static DateTime withStartOfQuarter(DateTime dateTime) { int monthOfYear = dateTime.getMonthOfYear(); DateTime firstMonthOfQuarter; if (monthOfYear >= DateTimeConstants.OCTOBER) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.OCTOBER); } else if (monthOfYear >= DateTimeConstants.JULY) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JULY); } else if (monthOfYear >= DateTimeConstants.APRIL) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.APRIL); } else { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JANUARY); } return firstMonthOfQuarter.withDayOfMonth(1); }  }
DateTimeUtils { public static DateTime withStartOfQuarter(DateTime dateTime) { int monthOfYear = dateTime.getMonthOfYear(); DateTime firstMonthOfQuarter; if (monthOfYear >= DateTimeConstants.OCTOBER) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.OCTOBER); } else if (monthOfYear >= DateTimeConstants.JULY) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JULY); } else if (monthOfYear >= DateTimeConstants.APRIL) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.APRIL); } else { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JANUARY); } return firstMonthOfQuarter.withDayOfMonth(1); }  @SuppressLint("DefaultLocale") static String parseInterval(Context context, long intervalInMillis); static DateTime parseFromString(String text, String format); static String toWeekDayAndDate(DateTime dateTime); static DateTime withStartOfQuarter(DateTime dateTime); static String toDateString(DateTime dateTime); }
DateTimeUtils { public static DateTime withStartOfQuarter(DateTime dateTime) { int monthOfYear = dateTime.getMonthOfYear(); DateTime firstMonthOfQuarter; if (monthOfYear >= DateTimeConstants.OCTOBER) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.OCTOBER); } else if (monthOfYear >= DateTimeConstants.JULY) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JULY); } else if (monthOfYear >= DateTimeConstants.APRIL) { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.APRIL); } else { firstMonthOfQuarter = dateTime.withMonthOfYear(DateTimeConstants.JANUARY); } return firstMonthOfQuarter.withDayOfMonth(1); }  @SuppressLint("DefaultLocale") static String parseInterval(Context context, long intervalInMillis); static DateTime parseFromString(String text, String format); static String toWeekDayAndDate(DateTime dateTime); static DateTime withStartOfQuarter(DateTime dateTime); static String toDateString(DateTime dateTime);  }