Java Utililty Methods LocalDate Calculate

List of utility methods to do LocalDate Calculate

Description

The list of methods to do LocalDate Calculate are organized into topic(s).

Method

TemporalAdjusternext(Predicate p)
Returns a TemporalAdjuster which returns the next date fulfilling the predicate.
Objects.requireNonNull(p, "p is null");
return w -> {
    LocalDate result = (LocalDate) w;
    do {
        result = result.plusDays(1);
    } while (!p.test(result));
    return result;
};
...
StringnormalizedYear(LocalDate d)
normalized Year
if (d == null)
    return null;
int yr = d.getYear();
int mo = d.getMonthValue();
int day = d.getDayOfMonth();
if (mo == 12 && day == 31) {
    yr++; 
return String.valueOf(yr);
LocalDateobtenirLocalDateAPartirDUneDate(Date date)
obtenir Local Date A Partir D Une Date
return (date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
booleanoneDayAfterNotificationRequired(LocalDate requestDate, LocalDate vehicleDetailsMotExpiryDate)
one Day After Notification Required
return requestDate.minusDays(1).equals(vehicleDetailsMotExpiryDate);
java.util.DateparseDate(LocalDate date)
parse Date
if (date != null) {
    return java.util.Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
} else {
    return null;
Periodperiod(LocalDate startDate, LocalDate endDate)
period
return Period.between(startDate, endDate);
LocalDateplusDays(LocalDate date, int daysToAdd)
Adds a number of days to the date.
if (daysToAdd == 0) {
    return date;
long dom = date.getDayOfMonth() + daysToAdd;
if (dom > 0 && dom <= 59) {
    int monthLen = date.lengthOfMonth();
    int month = date.getMonthValue();
    int year = date.getYear();
...
voidrebucketingArray(List targetDates, double[] rebucketedSensitivityAmounts, double sensitivityAmount, LocalDate sensitivityDate)
Re-bucket one sensitivity at a specific date and add it to an existing array.
int nbBuckets = targetDates.size();
if (!sensitivityDate.isAfter(targetDates.get(0))) {
    rebucketedSensitivityAmounts[0] += sensitivityAmount;
} else if (!sensitivityDate.isBefore(targetDates.get(nbBuckets - 1))) {
    rebucketedSensitivityAmounts[nbBuckets - 1] += sensitivityAmount;
} else {
    int indexSensitivityDate = 0;
    while (sensitivityDate.isAfter(targetDates.get(indexSensitivityDate))) {
...
LocalDateroundDown(final LocalDate dateTime, final TemporalUnit temporalUnit, final int size)
round Down
LocalDate epoch = LocalDate.ofEpochDay(0);
long count = temporalUnit.between(epoch, dateTime);
long round = count / size * size;
long diff = round - count;
return dateTime.plus(diff, temporalUnit);
Streamstream(LocalDate startInclusive, LocalDate endExclusive)
Streams the set of dates included in the range.
Iterator<LocalDate> it = new Iterator<LocalDate>() {
    private LocalDate current = startInclusive;
    @Override
    public LocalDate next() {
        LocalDate result = current;
        current = plusDays(current, 1);
        return result;
    @Override
    public boolean hasNext() {
        return current.isBefore(endExclusive);
};
long count = endExclusive.toEpochDay() - startInclusive.toEpochDay() + 1;
Spliterator<LocalDate> spliterator = Spliterators.spliterator(it, count,
        Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.DISTINCT | Spliterator.ORDERED
                | Spliterator.SORTED | Spliterator.SIZED | Spliterator.SUBSIZED);
return StreamSupport.stream(spliterator, false);