@Test public void shouldReturnFirstDayOfMonth(){ final Date testDate = new GregorianCalendar(2019, Calendar.JULY, 17).getTime(); final Date result = DateUtils.getFirstDayOfMonth(testDate); final Date expectedDate = new GregorianCalendar(2019, Calendar.JULY, 1).getTime(); assertThat(result, is(expectedDate)); }
public static Date getFirstDayOfMonth(Date date) { Calendar firstDayOfMonth = Calendar.getInstance(); firstDayOfMonth.setTime(DateUtils.minHourInDate(date)); firstDayOfMonth.set(Calendar.DAY_OF_MONTH, firstDayOfMonth.getMinimum(Calendar.DAY_OF_MONTH)); return firstDayOfMonth.getTime(); }
DateUtils { public static Date getFirstDayOfMonth(Date date) { Calendar firstDayOfMonth = Calendar.getInstance(); firstDayOfMonth.setTime(DateUtils.minHourInDate(date)); firstDayOfMonth.set(Calendar.DAY_OF_MONTH, firstDayOfMonth.getMinimum(Calendar.DAY_OF_MONTH)); return firstDayOfMonth.getTime(); } }
DateUtils { public static Date getFirstDayOfMonth(Date date) { Calendar firstDayOfMonth = Calendar.getInstance(); firstDayOfMonth.setTime(DateUtils.minHourInDate(date)); firstDayOfMonth.set(Calendar.DAY_OF_MONTH, firstDayOfMonth.getMinimum(Calendar.DAY_OF_MONTH)); return firstDayOfMonth.getTime(); }  }
DateUtils { public static Date getFirstDayOfMonth(Date date) { Calendar firstDayOfMonth = Calendar.getInstance(); firstDayOfMonth.setTime(DateUtils.minHourInDate(date)); firstDayOfMonth.set(Calendar.DAY_OF_MONTH, firstDayOfMonth.getMinimum(Calendar.DAY_OF_MONTH)); return firstDayOfMonth.getTime(); }  static Date timeToDate(int hour, int minutes); static Date minHourInDate(Date d); static Date addDays2Date(Date d, int days); static Date maxHourInDate(Date d); static Date getFirstDayOfMonth(Date date); static Date getLastDayOfMonth(Date date); static Date getFirstDayOfYear(Date date); static Date getLastDayOfYear(Date date); }
DateUtils { public static Date getFirstDayOfMonth(Date date) { Calendar firstDayOfMonth = Calendar.getInstance(); firstDayOfMonth.setTime(DateUtils.minHourInDate(date)); firstDayOfMonth.set(Calendar.DAY_OF_MONTH, firstDayOfMonth.getMinimum(Calendar.DAY_OF_MONTH)); return firstDayOfMonth.getTime(); }  static Date timeToDate(int hour, int minutes); static Date minHourInDate(Date d); static Date addDays2Date(Date d, int days); static Date maxHourInDate(Date d); static Date getFirstDayOfMonth(Date date); static Date getLastDayOfMonth(Date date); static Date getFirstDayOfYear(Date date); static Date getLastDayOfYear(Date date);  }