Example usage for java.time LocalDateTime isAfter

List of usage examples for java.time LocalDateTime isAfter

Introduction

In this page you can find the example usage for java.time LocalDateTime isAfter.

Prototype

@Override 
public boolean isAfter(ChronoLocalDateTime<?> other) 

Source Link

Document

Checks if this date-time is after the specified date-time.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2012, 6, 30, 12, 00);
    LocalDateTime b = LocalDateTime.of(2012, 7, 1, 12, 00);
    System.out.println(a.isAfter(b));
    System.out.println(a.isAfter(a));
}

From source file:net.dv8tion.discord.util.GoogleSearch.java

public static List<SearchResult> performSearch(String engineId, String terms, int requiredResultsCount) {
    try {//from   w  w  w  .j a v  a 2 s.co m
        if (GOOGLE_API_KEY == null)
            throw new IllegalStateException(
                    "Google API Key is null, Cannot preform google search without a key! Set one in the settings!");
        if (engineId == null || engineId.isEmpty())
            throw new IllegalArgumentException("Google Custom Search Engine id cannot be null or empty!");

        LocalDateTime currentTime = LocalDateTime.now();
        if (currentTime.isAfter(dayStartTime.plusDays(1))) {
            dayStartTime = currentTime;
            currentGoogleUsage = 1;
        } else if (currentGoogleUsage >= 80) {
            throw new IllegalStateException("Google usage has reached the premature security cap of 80");
        }

        terms = terms.replace(" ", "%20");
        String searchUrl = String.format(GOOGLE_URL, engineId, GOOGLE_API_KEY, requiredResultsCount, terms);

        URL searchURL = new URL(searchUrl);
        URLConnection conn = searchURL.openConnection();
        currentGoogleUsage++;
        conn.setRequestProperty("User-Agent",
                "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 " + randomName(10));
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder json = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            json.append(line).append("\n");
        }
        in.close();

        JSONArray jsonResults = new JSONObject(json.toString()).getJSONArray("items");
        List<SearchResult> results = new LinkedList<>();
        for (int i = 0; i < jsonResults.length(); i++) {
            results.add(SearchResult.fromGoogle(jsonResults.getJSONObject(i)));
        }
        return results;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.wallride.service.SignupService.java

public boolean validateInvitation(UserInvitation invitation) {
    if (invitation == null) {
        return false;
    }/*from ww  w. j  a va 2 s  .  c om*/
    if (invitation.isAccepted()) {
        return false;
    }
    LocalDateTime now = LocalDateTime.now();
    if (now.isAfter(invitation.getExpiredAt())) {
        return false;
    }
    return true;
}

From source file:org.wallride.web.controller.guest.user.PasswordResetController.java

@RequestMapping(value = "/{token}", method = RequestMethod.GET)
public String edit(@PathVariable String token, RedirectAttributes redirectAttributes) {
    PasswordResetToken passwordResetToken = userService.getPasswordResetToken(token);
    if (passwordResetToken == null) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }/*www  .java 2  s .  c o m*/
    LocalDateTime now = LocalDateTime.now();
    if (now.isAfter(passwordResetToken.getExpiredAt())) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }

    return "user/password-reset3-reset";
}

From source file:org.wallride.web.controller.guest.user.PasswordResetController.java

@RequestMapping(value = "/{token}", method = RequestMethod.PUT)
public String reset(@PathVariable String token,
        @Validated @ModelAttribute(FORM_MODEL_KEY) PasswordResetForm form, BindingResult errors,
        BlogLanguage blogLanguage, RedirectAttributes redirectAttributes) {
    redirectAttributes.addFlashAttribute(FORM_MODEL_KEY, form);
    redirectAttributes.addFlashAttribute(ERRORS_MODEL_KEY, errors);

    PasswordResetToken passwordResetToken = userService.getPasswordResetToken(token);
    if (passwordResetToken == null) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }/*from  w  w  w. j a v a2  s.c o  m*/
    LocalDateTime now = LocalDateTime.now();
    if (now.isAfter(passwordResetToken.getExpiredAt())) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }

    if (!errors.hasFieldErrors("newPassword")) {
        if (!ObjectUtils.nullSafeEquals(form.getNewPassword(), form.getNewPasswordRetype())) {
            errors.rejectValue("newPasswordRetype", "MatchRetype");
        }
    }
    if (errors.hasFieldErrors("newPassword*")) {
        return "redirect:/password-reset/{token}";
    }

    PasswordUpdateRequest request = new PasswordUpdateRequest().withUserId(passwordResetToken.getUser().getId())
            .withPassword(form.getNewPassword()).withLanguage(blogLanguage.getLanguage());
    userService.updatePassword(request, passwordResetToken);

    redirectAttributes.getFlashAttributes().clear();
    return "redirect:/login";
}

From source file:nu.yona.server.analysis.service.ActivityUpdateService.java

public void updateTimeExistingActivity(ActivityPayload payload, Activity existingActivity) {
    LocalDateTime startTimeLocal = payload.startTime.toLocalDateTime();
    if (startTimeLocal.isBefore(existingActivity.getStartTime())) {
        existingActivity.setStartTime(startTimeLocal);
    }//from  w ww .ja v  a2  s .co m
    LocalDateTime endTimeLocal = payload.endTime.toLocalDateTime();
    if (endTimeLocal.isAfter(existingActivity.getEndTime())) {
        existingActivity.setEndTime(endTimeLocal);
    }
}

From source file:org.apache.geode.management.internal.cli.commands.ExportLogsInterceptor.java

@Override
public Result preExecution(GfshParseResult parseResult) {
    // the arguments are in the order of it's being declared
    Map<String, String> arguments = parseResult.getParamValueStrings();

    // validates groupId and memberIds not both set
    if (arguments.get("group") != null && arguments.get("member") != null) {
        return ResultBuilder.createUserErrorResult("Can't specify both group and member.");
    }// w w w .j  a v  a  2 s .c  o m

    // validate log level
    String logLevel = arguments.get("log-level");
    if (StringUtils.isBlank(logLevel) || LogLevel.getLevel(logLevel) == null) {
        return ResultBuilder.createUserErrorResult("Invalid log level: " + logLevel);
    }

    // validate start date and end date
    String start = arguments.get("start-time");
    String end = arguments.get("end-time");
    if (start != null && end != null) {
        // need to make sure end is later than start
        LocalDateTime startTime = ExportLogsFunction.parseTime(start);
        LocalDateTime endTime = ExportLogsFunction.parseTime(end);
        if (startTime.isAfter(endTime)) {
            return ResultBuilder.createUserErrorResult("start-time has to be earlier than end-time.");
        }
    }

    // validate onlyLogs and onlyStats
    boolean onlyLogs = Boolean.parseBoolean(arguments.get("logs-only"));
    boolean onlyStats = Boolean.parseBoolean(arguments.get("stats-only"));
    if (onlyLogs && onlyStats) {
        return ResultBuilder.createUserErrorResult("logs-only and stats-only can't both be true");
    }

    return ResultBuilder.createInfoResult("");
}

From source file:com.match_tracker.twitter.TwitterSearch.java

protected boolean isLongRunningSearch(LocalDateTime lastLogTime) {
    LocalDateTime oneMinuteAgo = LocalDateTime.now().minusSeconds(LONG_SEARCH_THRESHOLD_SECONDS);
    return oneMinuteAgo.isAfter(lastLogTime);
}

From source file:com.ccserver.digital.validator.CreditCardApplicationValidator.java

private void validateGeneralTab(CreditCardApplicationDTO creditCardApplicationDTO, Errors errors) {
    // Validate date of issue
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dob", ErrorCodes.FIELD_REQUIRED);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", ErrorCodes.FIELD_REQUIRED);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", ErrorCodes.FIELD_REQUIRED);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", ErrorCodes.FIELD_REQUIRED);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "typeOfID", ErrorCodes.FIELD_REQUIRED);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passportNumber", ErrorCodes.FIELD_REQUIRED);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dateOfIssue", ErrorCodes.FIELD_REQUIRED);
    if (creditCardApplicationDTO.getCitizenship() != null
            && "+84".equals(creditCardApplicationDTO.getCitizenship().getCode())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "placeOfIssue", ErrorCodes.FIELD_REQUIRED);
    }// www. j a  va2 s  .  c o m
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passportNumber", ErrorCodes.FIELD_REQUIRED);
    LocalDateTime dateOfIssue = creditCardApplicationDTO.getDateOfIssue();
    if (dateOfIssue != null) {
        if (dateOfIssue.isAfter(LocalDateTime.now())) {
            errors.rejectValue("dateOfIssue", ErrorCodes.FIELD_NOT_FUTURE);
        }
    }
    validateMobilephone(creditCardApplicationDTO, errors);
}

From source file:fi.vrk.xroad.catalog.lister.JaxbCatalogServiceTest.java

private Iterable<Member> mockGetAllMembers(LocalDateTime l) {
    Collection<Long> keys;
    if (l.isAfter(DATETIME_2015)) {
        keys = Arrays.asList(2L, 3L);
    } else {/*w ww  . jav  a  2  s .  c o m*/
        keys = Arrays.asList(1L, 2L, 3L);
    }
    List<Member> matchingMembers = new ArrayList<>();
    Map<Long, Member> allMembers = createTestMembers();
    for (Long key : keys) {
        matchingMembers.add(allMembers.get(key));
    }
    return matchingMembers;
}