Java LocalDateTime Calculate getShiftResult(ImmutableMap timexUnitMap, LocalDateTime reference, boolean future)

Here you can find the source of getShiftResult(ImmutableMap timexUnitMap, LocalDateTime reference, boolean future)

Description

get Shift Result

License

Open Source License

Declaration

public static LocalDateTime getShiftResult(ImmutableMap<String, Double> timexUnitMap, LocalDateTime reference,
            boolean future) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDateTime;
import java.util.Map;
import com.google.common.collect.ImmutableMap;

public class Main {
    public static LocalDateTime getShiftResult(ImmutableMap<String, Double> timexUnitMap, LocalDateTime reference,
            boolean future) {

        LocalDateTime result = reference;
        int futureOrPast = future ? 1 : -1;

        for (Map.Entry<String, Double> pair : timexUnitMap.entrySet()) {

            String unit = pair.getKey();
            Double number = pair.getValue();

            switch (unit) {
            case "H":
                result = result.plusHours(Math.round(number * futureOrPast));
                break;
            case "M":
                result = result.plusMinutes(Math.round(number * futureOrPast));
                break;
            case "S":
                result = result.plusSeconds(Math.round(number * futureOrPast));
                break;
            case "D":
                result = result.plusDays(Math.round(number * futureOrPast));
                break;
            case "W":
                result = result.plusWeeks(Math.round(number * futureOrPast));
                break;
            case "MON":
                result = result.plusMonths(Math.round(number * futureOrPast));
                break;
            case "Y":
                result = result.plusYears(Math.round(number * futureOrPast));
                break;

            default:
                return result;
            }//from w ww.jav  a  2  s. c o m
        }

        return result;
    }
}

Related

  1. currentTimeMillis(LocalDateTime ldt)
  2. DateTime2LocalDateTime(Date datetime)
  3. dateTimeToOleMinutes(LocalDateTime datetime)
  4. dayDuration(LocalDateTime startDateTime, LocalDateTime endDateTime)
  5. fastDateTimeWriteHours(LocalDateTime localDateTime)
  6. getStartWeekOfMonth(@Nonnull final LocalDateTime aDT, @Nonnull final Locale aLocale)
  7. getTimePart(final LocalDateTime dateTime)
  8. getZonedDateTime(LocalDateTime dateTime, TimeZone timeZone)
  9. isAfter(LocalDateTime endDateTime, LocalDateTime startDateTime)