private void testGetDayDifferenceOfReadableIntsPlusMinusNDays(int sign) { Calendar calendar = Calendar.getInstance(); DateUtils.setTime(calendar, 12, 0, 0, 0); int today = DateUtils.getDayAsReadableInt(calendar); for (int i = 1; i <= 5000; i++) { DateUtils.addDays(calendar, sign * 1); int day = DateUtils.getDayAsReadableInt(calendar); int diff = DateUtils.getDayDifferenceOfReadableInts(today, day); Assert.assertEquals(sign * i, diff); } }
public static long getTimeForDay(int year, int month, int day) { return getTimeForDay(calendarThreadLocal.get(), year, month, day); }
public static int getDayDifferenceOfReadableInts(int dayOfBroadcast1, int dayOfBroadcast2) { long time1 = getTimeFromDayReadableInt(dayOfBroadcast1); long time2 = getTimeFromDayReadableInt(dayOfBroadcast2); // Don't use getDayDifference(time1, time2) here, it's wrong for some days. // Do float calculation and rounding at the end to cover daylight saving stuff etc. float daysFloat = (time2 - time1) / 1000 / 60 / 60 / 24f; return Math.round(daysFloat); }
/** Readable yyyyMMdd int representation of a day, which is also sortable. */ public static int getDayAsReadableInt(long time) { Calendar cal = calendarThreadLocal.get(); cal.setTimeInMillis(time); return getDayAsReadableInt(cal); }
private void checkDayDifference(int day1, int day2, int expectedDifference) { int actualDifference = DateUtils.getDayDifferenceOfReadableInts(day1, day2); Assert.assertEquals(expectedDifference, actualDifference); } }
/** Readable yyyyMMdd int representation of a day, which is also sortable. */ public static int getDayAsReadableInt(long time) { Calendar cal = calendarThreadLocal.get(); cal.setTimeInMillis(time); return getDayAsReadableInt(cal); }
public static int getDayDifferenceOfReadableInts(int dayOfBroadcast1, int dayOfBroadcast2) { long time1 = getTimeFromDayReadableInt(dayOfBroadcast1); long time2 = getTimeFromDayReadableInt(dayOfBroadcast2); // Don't use getDayDifference(time1, time2) here, it's wrong for some days. // Do float calculation and rounding at the end to cover daylight saving stuff etc. float daysFloat = (time2 - time1) / 1000 / 60 / 60 / 24f; return Math.round(daysFloat); }
/** Readable yyyyMMdd int representation of a day, which is also sortable. */ public static int getDayAsReadableInt(long time) { Calendar cal = calendarThreadLocal.get(); cal.setTimeInMillis(time); return getDayAsReadableInt(cal); }
public static long getTimeForDay(int year, int month, int day) { return getTimeForDay(calendarThreadLocal.get(), year, month, day); }
/** Returns midnight of the given day. */ public static long getTimeFromDayReadableInt(int day) { return getTimeFromDayReadableInt(calendarThreadLocal.get(), day, 0); }
/** Readable yyyyMMdd int representation of a day, which is also sortable. */ public static int getDayAsReadableInt(long time) { Calendar cal = calendarThreadLocal.get(); cal.setTimeInMillis(time); return getDayAsReadableInt(cal); }
public static long getTimeForDay(int year, int month, int day) { return getTimeForDay(calendarThreadLocal.get(), year, month, day); }
/** Returns midnight of the given day. */ public static long getTimeFromDayReadableInt(int day) { return getTimeFromDayReadableInt(calendarThreadLocal.get(), day, 0); }
public static long getTimeForDay(int year, int month, int day) { return getTimeForDay(calendarThreadLocal.get(), year, month, day); }
public static int getDayDifferenceOfReadableInts(int dayOfBroadcast1, int dayOfBroadcast2) { long time1 = getTimeFromDayReadableInt(dayOfBroadcast1); long time2 = getTimeFromDayReadableInt(dayOfBroadcast2); // Don't use getDayDifference(time1, time2) here, it's wrong for some days. // Do float calculation and rounding at the end to cover daylight saving stuff etc. float daysFloat = (time2 - time1) / 1000 / 60 / 60 / 24f; return Math.round(daysFloat); }
public static int getDayDifferenceOfReadableInts(int dayOfBroadcast1, int dayOfBroadcast2) { long time1 = getTimeFromDayReadableInt(dayOfBroadcast1); long time2 = getTimeFromDayReadableInt(dayOfBroadcast2); // Don't use getDayDifference(time1, time2) here, it's wrong for some days. // Do float calculation and rounding at the end to cover daylight saving stuff etc. float daysFloat = (time2 - time1) / 1000 / 60 / 60 / 24f; return Math.round(daysFloat); }
/** Returns midnight of the given day. */ public static long getTimeFromDayReadableInt(int day) { return getTimeFromDayReadableInt(calendarThreadLocal.get(), day, 0); }
/** Returns midnight of the given day. */ public static long getTimeFromDayReadableInt(int day) { return getTimeFromDayReadableInt(calendarThreadLocal.get(), day, 0); }