List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:com.ning.billing.catalog.DefaultDuration.java
License:Apache License
@Override public DateTime addToDateTime(final DateTime dateTime) { if ((number == null) && (unit != TimeUnit.UNLIMITED)) { return dateTime; }/* w ww. j av a 2s . c o m*/ switch (unit) { case DAYS: return dateTime.plusDays(number); case MONTHS: return dateTime.plusMonths(number); case YEARS: return dateTime.plusYears(number); case UNLIMITED: return dateTime.plusYears(100); default: return dateTime; } }
From source file:com.ning.billing.util.clock.DefaultClock.java
License:Apache License
public static DateTime addOrRemoveDuration(final DateTime input, final List<Duration> durations, final boolean add) { DateTime result = input; for (final Duration cur : durations) { switch (cur.getUnit()) { case DAYS: result = add ? result.plusDays(cur.getNumber()) : result.minusDays(cur.getNumber()); break; case MONTHS: result = add ? result.plusMonths(cur.getNumber()) : result.minusMonths(cur.getNumber()); break; case YEARS: result = add ? result.plusYears(cur.getNumber()) : result.minusYears(cur.getNumber()); break; case UNLIMITED: default:// www . j a v a 2 s.co m throw new RuntimeException("Trying to move to unlimited time period"); } } return result; }
From source file:com.ning.billing.util.clock.OldClockMock.java
License:Apache License
private DateTime adjustFromDuration(final DateTime input) { DateTime result = input; for (final Duration cur : deltaFromRealityDuration) { switch (cur.getUnit()) { case DAYS: result = result.plusDays(cur.getNumber()); break; case MONTHS: result = result.plusMonths(cur.getNumber()); break; case YEARS: result = result.plusYears(cur.getNumber()); break; case UNLIMITED: default://w w w . j av a2 s . co m throw new RuntimeException("ClockMock is adjusting an unlimited time period"); } } if (deltaFromRealityDurationEpsilon != 0) { result = result.plus(deltaFromRealityDurationEpsilon); } return result; }
From source file:com.njlabs.amrita.aid.gpms.client.Gpms.java
License:Open Source License
private DateTime roundOffDate(DateTime target) { int minutes = target.getMinuteOfHour(); if (minutes > 0 && minutes < 15) { return target.withMinuteOfHour(15); } else if (minutes > 15 && minutes < 30) { return target.withMinuteOfHour(30); } else if (minutes > 30 && minutes < 45) { return target.withMinuteOfHour(45); } else if (minutes > 45 && minutes <= 59) { if (target.getHourOfDay() == 23) { return target.plusDays(1).withHourOfDay(0).withMinuteOfHour(0); } else {/* ww w . jav a 2s .c om*/ return target.plusHours(1).withMinuteOfHour(0); } } else { return target; } }
From source file:com.norconex.collector.http.recrawl.impl.GenericRecrawlableResolver.java
License:Apache License
private boolean isRecrawlableFromFrequency(SitemapChangeFrequency cf, PreviousCrawlData prevData, String context) {/*from w w w . jav a 2 s . co m*/ if (cf == null) { return true; } if (LOG.isDebugEnabled()) { LOG.debug("The " + context + " change frequency is " + cf + " for: " + prevData.getReference()); } if (cf == SitemapChangeFrequency.ALWAYS) { return true; } if (cf == SitemapChangeFrequency.NEVER) { return false; } DateTime minCrawlDate = new DateTime(prevData.getCrawlDate()); switch (cf) { case HOURLY: minCrawlDate = minCrawlDate.plusHours(1); break; case DAILY: minCrawlDate = minCrawlDate.plusDays(1); break; case WEEKLY: minCrawlDate = minCrawlDate.plusWeeks(1); break; case MONTHLY: minCrawlDate = minCrawlDate.plusMonths(1); break; case YEARLY: minCrawlDate = minCrawlDate.plusYears(1); break; default: break; } if (minCrawlDate.isBeforeNow()) { if (LOG.isDebugEnabled()) { LOG.debug("Recrawl suggested according to " + context + " directive (change frequency < elapsed time since " + prevData.getCrawlDate() + ") for: " + prevData.getReference()); } return true; } if (LOG.isDebugEnabled()) { LOG.debug("No recrawl suggested according to " + context + " directive (change frequency >= elapsed time since " + prevData.getCrawlDate() + ") for: " + prevData.getReference()); } return false; }
From source file:com.ofalvai.bpinfo.util.UiUtils.java
License:Apache License
/** * Transforms the start and end timestamps into a human-friendly readable string, * with special replacements for special dates, times, and the API's strange notations. * @param context Context/*ww w . j ava2s .co m*/ * @param startTimestamp Start of the alert in seconds since the UNIX epoch * @param endTimestamp End of the alert in seconds since the UNIX epoch * @return A string in the format of [startdate] [starttime] [separator] [enddate] [endtime] */ @NonNull public static String alertDateFormatter(Context context, long startTimestamp, long endTimestamp) { DateTime startDateTime = new DateTime(startTimestamp * 1000L); DateTime endDateTime = new DateTime(endTimestamp * 1000L); LocalDate startDate = startDateTime.toLocalDate(); LocalDate endDate = endDateTime.toLocalDate(); DateTime today = new DateTime(); LocalDate todayDate = new DateTime().toLocalDate(); DateTime yesterday = today.minusDays(1); LocalDate yesterdayDate = yesterday.toLocalDate(); DateTime tomorrow = today.plusDays(1); LocalDate tomorrowDate = tomorrow.toLocalDate(); // Alert start, date part String startDateString; if (startDate.equals(todayDate)) { // Start day is today, replacing month and day with today string startDateString = context.getString(R.string.date_today) + " "; } else if (startDate.year().get() < today.year().get()) { // The start year is less than the current year, displaying the year too startDateString = Config.FORMATTER_DATE_YEAR.print(startDateTime); } else if (startDate.equals(yesterdayDate)) { startDateString = context.getString(R.string.date_yesterday) + " "; } else if (startDate.equals(tomorrowDate)) { startDateString = context.getString(R.string.date_tomorrow) + " "; } else { startDateString = Config.FORMATTER_DATE.print(startDateTime); } // Alert start, time part String startTimeString; if (startDateTime.hourOfDay().get() == 0 && startDateTime.minuteOfHour().get() == 0) { // The API marks "first departure" as 00:00 startTimeString = context.getString(R.string.date_first_departure); } else { startTimeString = Config.FORMATTER_TIME.print(startDateTime); } // Alert end, date part String endDateString; if (endTimestamp == 0) { // The API marks "until further notice" as 0 (in UNIX epoch), no need to display date // (the replacement string is displayed as the time part, not the date) endDateString = " "; } else if (endDate.year().get() > today.year().get()) { // The end year is greater than the current year, displaying the year too endDateString = Config.FORMATTER_DATE_YEAR.print(endDateTime); } else if (endDate.equals(todayDate)) { // End day is today, replacing month and day with today string endDateString = context.getString(R.string.date_today) + " "; } else if (endDate.equals(yesterdayDate)) { endDateString = context.getString(R.string.date_yesterday) + " "; } else if (endDate.equals(tomorrowDate)) { endDateString = context.getString(R.string.date_tomorrow) + " "; } else { endDateString = Config.FORMATTER_DATE.print(endDateTime); } // Alert end, time part String endTimeString; if (endTimestamp == 0) { // The API marks "until further notice" as 0 (in UNIX epoch) endTimeString = context.getString(R.string.date_until_revoke); } else if (endDateTime.hourOfDay().get() == 23 && endDateTime.minuteOfHour().get() == 59) { // The API marks "last departure" as 23:59 endTimeString = context.getString(R.string.date_last_departure); } else { endTimeString = Config.FORMATTER_TIME.print(endDateTime); } return startDateString + startTimeString + Config.DATE_SEPARATOR + endDateString + endTimeString; }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
@Override public List<Activity> getByProjectByDate(int projectId, Date date) { Activity sample = new Activity(); sample.setProjectId(projectId);// www . ja va 2 s .co m ActivityExample example = new ActivityExample(sample); DateTime dt = new DateTime(date); Date start = dt.withTimeAtStartOfDay().toDate(); Date end = dt.plusDays(1).toDate(); example.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(start).andCreatedLessThan(end); return activityMapper.selectByExample(example); }
From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java
License:Apache License
@Override public List<Map<String, ?>> getActivityCountForUsersGroupByDate(Integer companyId, Date since, Date until) { List<User> companyUsers = userService.getUserByCompanyId(companyId); List<Map<String, ?>> result = Lists.newArrayList(); Map<Integer, Integer> activityCountMap; DateTime dt = new DateTime(since); dt = dt.withTimeAtStartOfDay();/*ww w. ja va 2s .co m*/ DateTime end = new DateTime(until); end = end.withTimeAtStartOfDay().plusDays(1).minusMinutes(1); while (dt.toDate().before(end.toDate())) { activityCountMap = Maps.newHashMap(); for (User user : companyUsers) { activityCountMap.put(user.getId(), getCountByCompanyUserBetweenDates(companyId, user.getId(), dt.toDate(), dt.toDate())); } result.add(ImmutableMap.of("time", dt.toDate().getTime(), "counts", activityCountMap)); dt = dt.plusDays(1); } return result; }
From source file:com.onboard.service.collaboration.scheduler.DueTodosScheduler.java
License:Apache License
private List<Todo> getDueTodosOfToday() { Todo sample = new Todo(false); sample.setStatus(IterationItemStatus.TODO.getValue()); TodoExample example = new TodoExample(sample); DateTime today = new DateTime().withTimeAtStartOfDay(); example.getOredCriteria().get(0).andDueDateGreaterThanOrEqualTo(today.toDate()) .andDueDateLessThan(today.plusDays(1).toDate()); return todoMapper.selectByExample(example); }
From source file:com.pacoapp.paco.shared.scheduling.NonESMSignalGenerator.java
License:Open Source License
private DateTime scheduleWeekly(DateTime now) { DateTime nowMidnight = now.toDateMidnight().toDateTime(); int nowDow = nowMidnight.getDayOfWeek(); // joda starts Monday, I start Sunday Integer nowDowIndex = Schedule.DAYS_OF_WEEK[nowDow == 7 ? 0 : nowDow]; // joda is 1 based, and starts on Monday. we are 0-based, Sunday-start if ((schedule.getWeekDaysScheduled() & nowDowIndex) == nowDowIndex) { DateTime nextTimeToday = getNextTimeToday(now, nowMidnight); if (nextTimeToday != null) { return nextTimeToday; }// w w w . java2 s . com } DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1)); return getFirstScheduledTimeOnDay(nextDay); }