class DateUtil extends AbstractCaller {

    @Description("Returns provided datetime in the UTC time zone modified according to a pattern<br/>"
            + "If modified date time is on weekend and <code>skipWeekends</code> is <code>true</code> then the next working day in direction of modification will be returned"
            + MODIFY_HELP
            + "Example: #{modifyDateTime(dateTime, modifyPattern, skipWeekends)}"
    )
    @UtilityMethod
    public final LocalDateTime modifyDateTime(LocalDateTime dateTime, String modifyPattern, boolean skipWeekends){
        LocalDateTime modifiedDate = modifyTemporal(dateTime, modifyPattern);

        if (skipWeekends) {
            DayOfWeek dayOfWeek = modifiedDate.getDayOfWeek();
            long currentMillis = DateTimeUtility.getMillisecond(dateTime);
            long modifiedMillis = DateTimeUtility.getMillisecond(modifiedDate);
            if(dayOfWeek == DayOfWeek.SATURDAY) {
                int shift = modifiedMillis - currentMillis >= 0 ? 2 : -1;
                return modifiedDate.plusDays(shift);
            } else if(dayOfWeek == DayOfWeek.SUNDAY) {
                int shift = modifiedMillis - currentMillis >= 0 ? 1 : -2;
                return modifiedDate.plusDays(shift);
            }
        }
        return modifiedDate;
    }

}