Example usage for java.time LocalDate from

List of usage examples for java.time LocalDate from

Introduction

In this page you can find the example usage for java.time LocalDate from.

Prototype

public static LocalDate from(TemporalAccessor temporal) 

Source Link

Document

Obtains an instance of LocalDate from a temporal object.

Usage

From source file:org.symphonyoss.simplebot.LunchBoxBot.java

private void processMessage(Message message) {
    username = message.getFromUserId().toString();
    String messageString = message.getMessage();
    if (StringUtils.isNotEmpty(messageString) && StringUtils.isNotBlank(messageString)) {
        MlMessageParser messageParser = new MlMessageParser();
        try {//from   w w  w.  ja  v  a2s .c om
            messageParser.parseMessage(messageString);
            String text = messageParser.getText();
            if (isFeedback == true) {
                processFeedback(text);
                isFeedback = false;
            }

            if (StringUtils.startsWithIgnoreCase(text, "/lunchbox")) {
                LunchBotCommand cmd = getLunchBotCommand(text);

                switch (cmd) {
                case MENU:
                    HashMap lunch = parseLunchMenu(todayDateString);
                    sendMessage("#######" + lunch.get("title") + "#######" + "\n\n" + lunch.get("body"));
                    break;
                case FEEDBACK:
                    isFeedback = true;
                    break;
                case TOMORROW:
                    LocalDate tomorrowDate = LocalDate.from(todayDate.toInstant().atZone(ZoneId.of("UTC")))
                            .plusDays(1);
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy,MM,dd");
                    String tomorrowString = tomorrowDate.format(formatter);
                    lunch = parseLunchMenu(tomorrowString);
                    sendMessage("#######" + lunch.get("title") + "#######" + "\n\n" + lunch.get("body"));
                    break;
                case FORMAT:
                    sendMessage(
                            "- For feedback on individual items on the menu, <item number> -> <number of stars (out of 5)>\n- For feedback on lunch as a whole, <overall> -> <number of stars (out of 5)>, comments (optional)\n\n\nP.S: Please provide complete feedback in a single message with each section separated by a comma");
                    break;
                case OPTIONS:
                    sendMessage(
                            "For today's menu:  '/lunchbox menu' OR '/lunchbox today's menu'\nFor tomorrow's menu: '/lunchbox tomorrow' OR '/lunchbox tomorrow's menu'\nFor tips on format for feedback: '/lunchbox format'\nFor feedback: '/lunchbox feedback' <hit enter and then provide feedback all in one message>\nFor options: '/lunchbox help'\n\n\nP.S: All commands should be typed without quotes");
                    break;
                case UNKNOWN:
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:serposcope.controllers.admin.DebugController.java

@FilterWith(XSRFFilter.class)
public Result dryRun(Context context, @Param("startDate") String start, @Param("endDate") String end) {
    long _start = System.currentTimeMillis();
    FlashScope flash = context.getFlashScope();

    LocalDate startDate = null;//from www  .  j a  v a2  s.  c om
    LocalDate endDate = null;

    try {
        startDate = LocalDate.parse(start);
        endDate = LocalDate.parse(end);
    } catch (Exception ex) {
    }

    if (startDate == null || endDate == null || startDate.isAfter(endDate)) {
        flash.error("error.invalidDate");
        return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    Run lastRun = baseDB.run.findLast(Module.GOOGLE, null, null);
    if (lastRun != null && lastRun.getDay().isAfter(startDate)) {
        flash.error("error.invalidDate");
        return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    LocalDate date = LocalDate.from(startDate);

    GoogleSettings ggOptions = googleDB.options.get();

    int minPauseBetweenPageSec = ggOptions.getMinPauseBetweenPageSec();
    int maxPauseBetweenPageSec = ggOptions.getMaxPauseBetweenPageSec();
    ggOptions.setMinPauseBetweenPageSec(0);
    ggOptions.setMaxPauseBetweenPageSec(0);
    googleDB.options.update(ggOptions);

    try {
        while (date.isBefore(endDate)) {
            LOG.debug("dry run {}", date);
            if (!taskManager
                    .startGoogleTask(new Run(Run.Mode.MANUAL, Module.GOOGLE, date.atTime(13, 37, 00)))) {
                LOG.error("can't startGoogleTask");
                flash.error("can't startGoogleTask");
                return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
            }
            taskManager.joinGoogleTask();
            date = date.plusDays(1);
        }
    } catch (Exception ex) {
        LOG.error("an error occured", ex);
        flash.error("an error occured");
        return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    } finally {
        ggOptions.setMinPauseBetweenPageSec(minPauseBetweenPageSec);
        ggOptions.setMaxPauseBetweenPageSec(maxPauseBetweenPageSec);
        googleDB.options.update(ggOptions);
    }

    LOG.debug("dry run timing : {}",
            DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - _start));
    flash.success("ok");
    return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
}