List of usage examples for java.time LocalDateTime plusHours
public LocalDateTime plusHours(long hours)
From source file:Main.java
public static void main(String[] args) { LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00); LocalDateTime t = a.plusHours(100); System.out.println(t);//from www . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] argv) { LocalDate today = LocalDate.now(); LocalDate tomorrow = today.plusDays(1); LocalDateTime time = LocalDateTime.now(); LocalDateTime nextHour = time.plusHours(1); System.out.println("today = " + today); System.out.println("1) tomorrow = " + tomorrow + " \n2) tomorrow = " + today.plus(1, DAYS)); System.out.println("local time now = " + time); System.out.println("1) nextHour = " + nextHour + " \n2) nextHour = " + time.plus(1, HOURS)); LocalDate nextWeek = today.plus(1, WEEKS); System.out.println("Date after 1 week : " + nextWeek); LocalDate previousYear = today.minus(1, YEARS); System.out.println("Date before 1 year : " + previousYear); LocalDate nextYear = today.plus(1, YEARS); System.out.println("Date after 1 year : " + nextYear); LocalDate firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); System.out.println("firstDayOfMonth = " + firstDayOfMonth); }
From source file:com.omertron.slackbot.functions.Meetup.java
/** * Convert MeetupDetails into a SlackAttachment * * @param meetupDetails/*from ww w. jav a 2s . c o m*/ * @param detailed * @return */ private static SlackAttachment makeSlackAttachment(MeetupDetails meetupDetails, boolean detailed) { SlackAttachment sa = new SlackAttachment(); sa.addMarkdownIn("text"); sa.setColor("good"); sa.setTitle(meetupDetails.getName()); sa.setTitleLink(meetupDetails.getLink()); sa.setThumbUrl("https://secure.meetupstatic.com/photos/event/4/9/1/c/global_453258716.jpeg"); if (detailed) { sa.setText(reformatDescription(meetupDetails.getDescription())); sa.addField("Duration", String.format("%1$d hour(s)", meetupDetails.getDuration()), true); sa.addField("Status", meetupDetails.getStatus(), true); } if (meetupDetails.getVenue() != null) { sa.addField("Venue", meetupDetails.getVenue().getName(), true); } LocalDateTime meetTime = meetupDetails.getMeetupTime(); if (!IS_GMT) { // Correct for BST meetTime = meetTime.plusHours(1); } sa.addField("Date", meetTime.format(DT_FORMAT), true); if (meetupDetails.getHowToFindUs() != null && detailed) { sa.addField("How to find us", meetupDetails.getHowToFindUs(), false); } return sa; }
From source file:org.wallride.service.UserService.java
@CacheEvict(value = WallRideCacheConfiguration.USER_CACHE, allEntries = true) public UserInvitation inviteAgain(UserInvitationResendRequest form, BindingResult result, AuthorizedUser authorizedUser) throws MessagingException { LocalDateTime now = LocalDateTime.now(); UserInvitation invitation = userInvitationRepository.findOneForUpdateByToken(form.getToken()); invitation.setExpiredAt(now.plusHours(72)); invitation.setUpdatedAt(now);//from www. ja v a 2 s . com invitation.setUpdatedBy(authorizedUser.toString()); invitation = userInvitationRepository.saveAndFlush(invitation); Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); String websiteTitle = blog.getTitle(LocaleContextHolder.getLocale().getLanguage()); String signupLink = ServletUriComponentsBuilder.fromCurrentContextPath().path("/_admin/signup") .queryParam("token", invitation.getToken()).buildAndExpand().toString(); final Context ctx = new Context(LocaleContextHolder.getLocale()); ctx.setVariable("websiteTitle", websiteTitle); ctx.setVariable("authorizedUser", authorizedUser); ctx.setVariable("signupLink", signupLink); ctx.setVariable("invitation", invitation); final MimeMessage mimeMessage = mailSender.createMimeMessage(); final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // true = multipart message.setSubject(MessageFormat.format( messageSourceAccessor.getMessage("InvitationMessageTitle", LocaleContextHolder.getLocale()), authorizedUser.toString(), websiteTitle)); message.setFrom(authorizedUser.getEmail()); message.setTo(invitation.getEmail()); final String htmlContent = templateEngine.process("user-invite", ctx); message.setText(htmlContent, true); // true = isHtml mailSender.send(mimeMessage); return invitation; }
From source file:org.wallride.service.UserService.java
public PasswordResetToken createPasswordResetToken(PasswordResetTokenCreateRequest request) { User user = userRepository.findOneByEmail(request.getEmail()); if (user == null) { throw new EmailNotFoundException(); }/* w w w . j a v a 2 s . c o m*/ LocalDateTime now = LocalDateTime.now(); PasswordResetToken passwordResetToken = new PasswordResetToken(); passwordResetToken.setUser(user); passwordResetToken.setEmail(user.getEmail()); passwordResetToken.setExpiredAt(now.plusHours(24)); passwordResetToken.setCreatedAt(now); passwordResetToken.setCreatedBy(user.toString()); passwordResetToken.setUpdatedAt(now); passwordResetToken.setUpdatedBy(user.toString()); passwordResetToken = passwordResetTokenRepository.saveAndFlush(passwordResetToken); try { Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); String blogTitle = blog.getTitle(LocaleContextHolder.getLocale().getLanguage()); ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); if (blog.isMultiLanguage()) { builder.path("/{language}"); } builder.path("/password-reset"); builder.path("/{token}"); Map<String, Object> urlVariables = new LinkedHashMap<>(); urlVariables.put("language", request.getLanguage()); urlVariables.put("token", passwordResetToken.getToken()); String resetLink = builder.buildAndExpand(urlVariables).toString(); Context ctx = new Context(LocaleContextHolder.getLocale()); ctx.setVariable("passwordResetToken", passwordResetToken); ctx.setVariable("resetLink", resetLink); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // true = multipart message.setSubject(MessageFormat.format( messageSourceAccessor.getMessage("PasswordResetSubject", LocaleContextHolder.getLocale()), blogTitle)); message.setFrom(mailProperties.getProperties().get("mail.from")); message.setTo(passwordResetToken.getEmail()); String htmlContent = templateEngine.process("password-reset", ctx); message.setText(htmlContent, true); // true = isHtml mailSender.send(mimeMessage); } catch (MessagingException e) { throw new ServiceException(e); } return passwordResetToken; }
From source file:org.wallride.service.UserService.java
@CacheEvict(value = WallRideCacheConfiguration.USER_CACHE, allEntries = true) public List<UserInvitation> inviteUsers(UserInvitationCreateRequest form, BindingResult result, AuthorizedUser authorizedUser) throws MessagingException { String[] recipients = StringUtils.commaDelimitedListToStringArray(form.getInvitees()); LocalDateTime now = LocalDateTime.now(); List<UserInvitation> invitations = new ArrayList<>(); for (String recipient : recipients) { UserInvitation invitation = new UserInvitation(); invitation.setEmail(recipient);// w ww .j a v a2s . c o m invitation.setMessage(form.getMessage()); invitation.setExpiredAt(now.plusHours(72)); invitation.setCreatedAt(now); invitation.setCreatedBy(authorizedUser.toString()); invitation.setUpdatedAt(now); invitation.setUpdatedBy(authorizedUser.toString()); invitation = userInvitationRepository.saveAndFlush(invitation); invitations.add(invitation); } Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); for (UserInvitation invitation : invitations) { String websiteTitle = blog.getTitle(LocaleContextHolder.getLocale().getLanguage()); String signupLink = ServletUriComponentsBuilder.fromCurrentContextPath().path("/_admin/signup") .queryParam("token", invitation.getToken()).buildAndExpand().toString(); final Context ctx = new Context(LocaleContextHolder.getLocale()); ctx.setVariable("websiteTitle", websiteTitle); ctx.setVariable("authorizedUser", authorizedUser); ctx.setVariable("signupLink", signupLink); ctx.setVariable("invitation", invitation); final MimeMessage mimeMessage = mailSender.createMimeMessage(); final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // true = multipart message.setSubject(MessageFormat.format( messageSourceAccessor.getMessage("InvitationMessageTitle", LocaleContextHolder.getLocale()), authorizedUser.toString(), websiteTitle)); message.setFrom(authorizedUser.getEmail()); message.setTo(invitation.getEmail()); final String htmlContent = templateEngine.process("user-invite", ctx); message.setText(htmlContent, true); // true = isHtml mailSender.send(mimeMessage); } return invitations; }