List of utility methods to do LocalDateTime Calculate
LocalDateTime | add(final LocalDateTime original, final int years, final int months, final int days, final int hours, final int minutes) add return original.plusYears(years).plusMonths(months).plusDays(days).plusHours(hours).plusMinutes(minutes);
|
LocalDateTime | addHeureMinute(final LocalDateTime time, final int heures, final int minutes) add Heure Minute return time.plus(heures * 60 + minutes, ChronoUnit.MINUTES);
|
boolean | areDatesOneMonthApart(LocalDateTime start, LocalDateTime end) are Dates One Month Apart final int startDay = start.getDayOfMonth(); final int endDay = end.getDayOfMonth(); if (startDay == endDay && (start.getMonth() != start.getMonth())) { return true; } else { final boolean startAtMonthEnd = (startDay == start.getMonth().length(start.toLocalDate().isLeapYear())); final boolean endAtMonthEnd = (endDay == end.getMonth().length(end.toLocalDate().isLeapYear())); if (startAtMonthEnd) { ... |
LocalDateTime | atMidnight(LocalDateTime value) at Midnight return value != null ? value.truncatedTo(ChronoUnit.DAYS) : null;
|
LocalDateTime | balanceStartAndEndDateTime(LocalDateTime startDateTime, LocalDateTime endDateTime) Takes two LocalDateTime and balances by ensuring that the latter DateTime is gaurenteed to be later than the former DateTime LocalDateTime newEndDateTime = endDateTime; while (startDateTime.compareTo(newEndDateTime) >= 1) { newEndDateTime = newEndDateTime.plusDays(1); return newEndDateTime; |
boolean | before(LocalDateTime time1, LocalDateTime time2) before return time1.isBefore(time2);
|
LocalDate | calcNextDayOfWeekFromLDT(LocalDateTime ldt, DayOfWeek dow) Like it says LocalDate d = ldt.toLocalDate();
return calcNextDayOfWeek(d, dow);
|
LocalDateTime | ceilDate(LocalDateTime dateTime) Performs a "ceiling" operation on a LocalDateTime, and returns a new LocalDateTime with time set to 23:59. if (dateTime == null) { return null; return dateTime.toLocalDate().atTime(23, 59); |
boolean | checkIfTimeExist(LocalDateTime date) check If Time Exist LocalDateTime currentTime = LocalDateTime.now();
return currentTime.getHour() != date.getHour() || currentTime.getMinute() != date.getMinute();
|
LocalDateTime | clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour) Clamp the dateTime so that the latest hour can only be maxAllowedHour. if (dateTime.getHour() >= maxAllowedHour) { return dateTime.withHour(maxAllowedHour).withMinute(0); return dateTime; |