List of usage examples for org.joda.time DateTime minusWeeks
public DateTime minusWeeks(int weeks)
From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java
License:Apache License
private void sendEmail(boolean test, AmazonSimpleEmailServiceClient emailService, String email, List<ApplicationGroup> appGroups) throws IOException, MessagingException { StringBuilder body = new StringBuilder(); body.append(/* ww w. j a v a2 s . c om*/ "<html><head><style type=\"text/css\">a:link, a:visited{color:#006DBA;}a:link, a:visited, a:hover {\n" + "text-decoration: none;\n" + "}\n" + "body {\n" + "color: #333;\n" + "}" + "</style></head>"); List<MimeBodyPart> mimeBodyParts = Lists.newArrayList(); int index = 0; String subject = ""; for (ApplicationGroup appGroup : appGroups) { boolean hasData = false; for (String prodName : appGroup.data.keySet()) { if (config.productService.getProductByName(prodName) == null) continue; hasData = appGroup.data.get(prodName) != null && appGroup.data.get(prodName).size() > 0; if (hasData) break; } if (!hasData) continue; try { MimeBodyPart mimeBodyPart = constructEmail(index, appGroup, body); index++; if (mimeBodyPart != null) { mimeBodyParts.add(mimeBodyPart); subject = subject + (subject.length() > 0 ? ", " : "") + appGroup.getDisplayName(); } } catch (Exception e) { logger.error("Error contructing email", e); } } body.append("</html>"); if (mimeBodyParts.size() == 0) return; DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0); subject = String.format("%s Weekly AWS Costs (%s - %s)", subject, formatter.print(end.minusWeeks(1)), formatter.print(end)); String toEmail = test ? testEmail : email; Session session = Session.getInstance(new Properties()); MimeMessage mimeMessage = new MimeMessage(session); mimeMessage.setSubject(subject); mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO, toEmail); if (!test && !StringUtils.isEmpty(bccEmail)) { mimeMessage.addRecipients(Message.RecipientType.BCC, bccEmail); } MimeMultipart mimeMultipart = new MimeMultipart(); BodyPart p = new MimeBodyPart(); p.setContent(body.toString(), "text/html"); mimeMultipart.addBodyPart(p); for (MimeBodyPart mimeBodyPart : mimeBodyParts) mimeMultipart.addBodyPart(mimeBodyPart); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); mimeMessage.setContent(mimeMultipart); mimeMessage.writeTo(outputStream); RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray())); SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage); rawEmailRequest.setDestinations(Lists.<String>newArrayList(toEmail)); rawEmailRequest.setSource(fromEmail); logger.info("sending email to " + toEmail + " " + body.toString()); emailService.sendRawEmail(rawEmailRequest); }
From source file:com.pureblue.quant.util.frequency.Weekly.java
@Override public DateTime periodBegin(DateTime time) { int timeDifference = time.getDayOfWeek() - day.toJodaTimeValue(); if (timeDifference < 0) { timeDifference += 7;/*from www .j a v a 2 s. c o m*/ } DateTime startDay = time.minusDays(timeDifference); DateTime weekStart = new DateTime(startDay.getYear(), startDay.getMonthOfYear(), startDay.getDayOfMonth(), dayStartTime.getHourOfDay(), dayStartTime.getMinuteOfHour(), dayStartTime.getSecondOfMinute(), dayStartTime.getMillisOfSecond(), startDay.getZone()); if (weekStart.isAfter(time)) { return weekStart.minusWeeks(1); } else { return weekStart; } }
From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java
License:Open Source License
private List<SBEmail> generateIndividualSalesmanSummaryEmailsForDealershipIdReportType(Integer dealershipId, Integer reportType) {/*from w w w . j a v a 2 s .c om*/ DateTime to = new DateTime(DateTimeZone.UTC); DateTime from = null; switch (reportType) { case DAILY_SALESMAN_SUMMARY_EMAIL_TYPE: from = to.minusDays(1).minusMinutes(10); break; case WEEKLY_SALESMAN_SUMMARY_EMAIL_TYPE: from = to.minusWeeks(1).minusMinutes(10); break; case MONTHLY_SALESMAN_SUMMARY_EMAIL_TYPE: from = to.minusMonths(1).minusMinutes(10); break; default: throw new RuntimeException( "report type invalid for generateIndividualSalesmanSummaryEmailsForDealershipIdReportType"); } List<UserTree> userTrees = this.getUserTreeForDealershipIdType(dealershipId, reportType); List<SBEmail> emails = new ArrayList<>(); for (UserTree ut : userTrees) { try { String subject = "Report about " + this.getUsersName(ut.getUserId()).getName() + " from Salesman Buddy"; String body = this.individualSalesmanSummaryReport(this.getUserByGoogleId(ut.getUserId()).getId(), from, to); SBEmail email = SBEmail.newPlainTextEmail(REPORTS_EMAIL, null, subject, body, true); email.replaceTo(this.getEmailForGoogleId(ut.getSupervisorId())); emails.add(email); } catch (UserNameException e) { e.printStackTrace(); JDBCSalesmanBuddyDAO.sendErrorToMe(new StringBuilder().append( "Error in generateIndividualSalesmanSummaryEmailsForDealershipIdReportType for getting user's name for userTree: ") .append(ut.toString()).append(", error: ").append(e.getLocalizedMessage()).toString()); } } return emails; }
From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java
License:Open Source License
private String generateEmailContentForDealershipIdReportType(Integer dealershipId, Integer type) { DateTime now = new DateTime(DateTimeZone.forID("America/Denver")); final Integer BACK_MINUTES = 10; DateTime dayPrevious = now.minusDays(1).minusMinutes(BACK_MINUTES); DateTime weekPrevious = now.minusWeeks(1).minusMinutes(BACK_MINUTES); DateTime monthPrevious = now.minusMonths(1).minusMinutes(BACK_MINUTES); switch (type) { case DAILY_TEST_DRIVE_SUMMARY_EMAIL_TYPE: return this.testDriveSummaryReport(dealershipId, dayPrevious, now); case DAILY_ALL_SALESMAN_SUMMARY_EMAIL_TYPE: return this.allSalesmanSummaryReport(dealershipId, dayPrevious, now); case DAILY_DEALERSHIP_SUMMARY_EMAIL_TYPE: return this.dealershipSummaryReport(dealershipId, dayPrevious, now); case DAILY_STOCK_NUMBERS_EMAIL_TYPE: return this.stockNumberSummaryReport(dealershipId, dayPrevious, now); case WEEKLY_TEST_DRIVE_SUMMARY_EMAIL_TYPE: return this.testDriveSummaryReport(dealershipId, weekPrevious, now); case WEEKLY_ALL_SALESMAN_SUMMARY_EMAIL_TYPE: return this.allSalesmanSummaryReport(dealershipId, weekPrevious, now); case WEEKLY_DEALERSHIP_SUMMARY_EMAIL_TYPE: return this.dealershipSummaryReport(dealershipId, weekPrevious, now); case WEEKLY_STOCK_NUMBERS_EMAIL_TYPE: return this.stockNumberSummaryReport(dealershipId, weekPrevious, now); case MONTHLY_TEST_DRIVE_SUMMARY_EMAIL_TYPE: return this.testDriveSummaryReport(dealershipId, monthPrevious, now); case MONTHLY_ALL_SALESMAN_SUMMARY_EMAIL_TYPE: return this.allSalesmanSummaryReport(dealershipId, monthPrevious, now); case MONTHLY_DEALERSHIP_SUMMARY_EMAIL_TYPE: return this.dealershipSummaryReport(dealershipId, monthPrevious, now); case MONTHLY_STOCK_NUMBERS_EMAIL_TYPE: return this.stockNumberSummaryReport(dealershipId, monthPrevious, now); // case DAILY_SALESMAN_SUMMARY_EMAIL_TYPE: // /*from w w w . j ava 2 s. c o m*/ // break; // // case WEEKLY_SALESMAN_SUMMARY_EMAIL_TYPE: // // break; // // case MONTHLY_SALESMAN_SUMMARY_EMAIL_TYPE: // // break; default: return "Error, couldn't find correct report type"; } }
From source file:com.salesmanBuddy.dao.JDBCSalesmanBuddyDAO.java
License:Open Source License
private String getStatsAboutUserId(Integer userId) { DateTime to = this.getNowTime(); DateTime from = to.minusWeeks(1); List<Licenses> licenses = this.getLicensesForUserIdDateRange(userId, to, from); StringBuilder sb = new StringBuilder(); sb.append("This salesman has had ").append(licenses.size()).append(" test drives in the last week.\n"); return sb.toString(); }
From source file:com.sos.scheduler.model.objects.JodaTools.java
License:Apache License
/** * \brief calculate a date for a specific weekday based on a given date * \detail/*from w w w.ja v a2s. c o m*/ * * @param date * @param weekday * @return */ public static DateTime getPreviousWeekday(DateTime date, int weekday) { if (date.getDayOfWeek() < weekday) date = date.minusWeeks(1); return date.withDayOfWeek(weekday); }
From source file:com.sos.scheduler.model.objects.JodaTools.java
License:Apache License
/** * \brief calculate a date for a specific weekday based on a given date * \detail// w ww.j a va 2 s. c o m * @param date - the base date * @param weekday - the weekday * @return */ public static DateTime getWeekdayInMonth(DateTime date, int weekday, int which) { if (which < 0) { DateTime baseDate = getEndOfMonth(date); DateTime d = getPreviousWeekday(baseDate, weekday); int weeks = (which * -1) - 1; return d.minusWeeks(weeks); } DateTime baseDate = getStartOfMonth(date); DateTime d = getNextWeekday(baseDate, weekday); return d.plusWeeks(which - 1); }
From source file:com.tango.BucketSyncer.MirrorOptions.java
License:Apache License
private long initMaxAge() { DateTime dateTime = new DateTime(nowTime); // all digits -- assume "days" if (ctime.matches("^[0-9]+$")) return dateTime.minusDays(Integer.parseInt(ctime)).getMillis(); // ensure there is at least one digit, and exactly one character suffix, and the suffix is a legal option if (!ctime.matches("^[0-9]+[yMwdhms]$")) throw new IllegalArgumentException("Invalid option for ctime: " + ctime); if (ctime.endsWith("y")) return dateTime.minusYears(getCtimeNumber(ctime)).getMillis(); if (ctime.endsWith("M")) return dateTime.minusMonths(getCtimeNumber(ctime)).getMillis(); if (ctime.endsWith("w")) return dateTime.minusWeeks(getCtimeNumber(ctime)).getMillis(); if (ctime.endsWith("d")) return dateTime.minusDays(getCtimeNumber(ctime)).getMillis(); if (ctime.endsWith("h")) return dateTime.minusHours(getCtimeNumber(ctime)).getMillis(); if (ctime.endsWith("m")) return dateTime.minusMinutes(getCtimeNumber(ctime)).getMillis(); if (ctime.endsWith("s")) return dateTime.minusSeconds(getCtimeNumber(ctime)).getMillis(); throw new IllegalArgumentException("Invalid option for ctime: " + ctime); }
From source file:com.weebly.opus1269.copyeverywhere.model.ClipContentProvider.java
License:Apache License
/** * Delete rows older than the storage duration * * @return Number of rows deleted/* w w w. j a v a 2 s . c o m*/ */ @SuppressWarnings("CallToStringEquals") public static int deleteOldItems() { final String value = Prefs.getDuration(); if (value.equals(Prefs.DEFAULT_DURATION)) { return 0; } final Context context = App.getContext(); DateTime today = DateTime.now(); today = today.withTimeAtStartOfDay(); DateTime deleteDate = today; switch (value) { case "day": deleteDate = deleteDate.minusDays(1); break; case "week": deleteDate = deleteDate.minusWeeks(1); break; case "month": deleteDate = deleteDate.minusMonths(1); break; case "year": deleteDate = deleteDate.minusYears(1); break; default: return 0; } final long deleteTime = deleteDate.getMillis(); // Select all non-favorites older than the calculated time final String selection = "(" + ClipContract.Clip.COL_FAV + " == 0 " + ")" + " AND (" + ClipContract.Clip.COL_DATE + " < " + deleteTime + ")"; return context.getContentResolver().delete(ClipContract.Clip.CONTENT_URI, selection, null); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches all the instants between N weeks before the instantiation and the * instantiation.//w ww . j a v a2 s . com * * @param numberOfWeeks number of weeks to substract from current date * @return The corresponding period object */ public static Period createSinceWeeksPeriod(int numberOfWeeks) { DateTime dt = new DateTime(); return createPeriod(dt.minusWeeks(numberOfWeeks).getMillis(), dt.getMillis()); }