List of usage examples for org.joda.time DateTime minusDays
public DateTime minusDays(int days)
From source file:org.n52.io.PreRenderingTask.java
License:Open Source License
public Interval createTimespanFromInterval(String timeseriesId, String interval) { DateTime now = new DateTime(); if (interval.equals("lastDay")) { return new Interval(now.minusDays(1), now); } else if (interval.equals("lastWeek")) { return new Interval(now.minusWeeks(1), now); } else if (interval.equals("lastMonth")) { return new Interval(now.minusMonths(1), now); } else {//from ww w.j a v a 2s. c om throw new ResourceNotFoundException( "Unknown interval definition '" + interval + "' for timeseriesId " + timeseriesId); } }
From source file:org.n52.sos.request.operator.AqdGetObservationOperatorV10.java
License:Open Source License
private void checkRequestForFlowAndTemporalFilter(GetObservationRequest request, ReportObligationType flow) throws CodedException { try {//w w w. j av a 2 s.c o m if (!request.isSetTemporalFilter()) { DateTime start = null; DateTime end = null; DateTime dateTime = new DateTime(); if (ReportObligationType.E2A.equals(flow)) { String timeString; timeString = DateTimeHelper.formatDateTime2YearMonthDayDateStringYMD(dateTime.minusDays(1)); start = DateTimeHelper.parseIsoString2DateTime(timeString); int timeLength = DateTimeHelper.getTimeLengthBeforeTimeZone(timeString); DateTime origEnd = DateTimeHelper.parseIsoString2DateTime(timeString); end = DateTimeHelper.setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(origEnd, timeLength); } else if (ReportObligationType.E1A.equals(flow) || ReportObligationType.E1B.equals(flow)) { String year = Integer.toString(dateTime.minusYears(1).getYear()); start = DateTimeHelper.parseIsoString2DateTime(year); int timeLength = DateTimeHelper.getTimeLengthBeforeTimeZone(year); end = DateTimeHelper.setDateTime2EndOfMostPreciseUnit4RequestedEndPosition( DateTimeHelper.parseIsoString2DateTime(year), timeLength); } if (start != null && end != null) { request.setTemporalFilters( getTemporalFilter(new TimePeriod(start.minusMillis(1), end.plusMillis(2)))); } } } catch (DateTimeFormatException | DateTimeParseException e) { throw new NoApplicableCodeException().causedBy(e).withMessage( "The request does not contain a temporal filter and the temporal filter creation for the flow fails!"); } }
From source file:org.obm.push.bean.FilterType.java
License:Open Source License
public Date getFilteredDate(Date fromDate) { DateTime fromUTCDate = new DateTime(fromDate).withZone(DateTimeZone.UTC); switch (this) { case ALL_ITEMS: return DateUtils.getEpochPlusOneSecondCalendar().getTime(); case ONE_DAY_BACK: return fromUTCDate.minusDays(1).toDate(); case THREE_DAYS_BACK: return fromUTCDate.minusDays(3).toDate(); case ONE_WEEK_BACK: return fromUTCDate.minusWeeks(1).toDate(); case TWO_WEEKS_BACK: return fromUTCDate.minusWeeks(2).toDate(); case ONE_MONTHS_BACK: return fromUTCDate.minusMonths(1).toDate(); case THREE_MONTHS_BACK: return fromUTCDate.minusMonths(3).toDate(); case SIX_MONTHS_BACK: return fromUTCDate.minusMonths(6).toDate(); case FILTER_BY_NO_INCOMPLETE_TASKS: return fromDate; }/*ww w . ja v a2 s. com*/ throw new IllegalStateException("No filtered date available"); }
From source file:org.ojbc.adapters.rapbackdatastore.dao.RapbackDAOImpl.java
License:RPL License
@Override public int archiveCivilIdentifications() { log.info("Archiving records that have been available " + "for subscription for over " + civilIdlePeriod + " days."); final String sql = "UPDATE identification_transaction t " + "SET t.archived = 'true' " + "WHERE (select count(*)>0 FROM civil_initial_results c where c.transaction_number = t.transaction_number) " + " AND t.archived = 'false' AND t.available_for_subscription_start_date < ?"; DateTime currentDate = new DateTime(); DateTime comparableDate = currentDate.minusDays(civilIdlePeriod); log.info("Comparable Date:" + comparableDate); int updatedRows = jdbcTemplate.update(sql, comparableDate.toDate()); log.info("Archived " + updatedRows + " rows that have been idle for over " + civilIdlePeriod + " days "); return updatedRows; }
From source file:org.ojbc.adapters.rapbackdatastore.dao.RapbackDAOImpl.java
License:RPL License
@Override public int archiveCriminalIdentifications() { log.info("Archiving records that have been available " + "for subscription for over " + criminalIdlePeriod + " days."); final String sql = "UPDATE identification_transaction t " + "SET t.archived = 'true' " + "WHERE (select count(*)>0 FROM criminal_initial_results c where c.transaction_number = t.transaction_number) " + "AND t.archived = 'false' AND t.available_for_subscription_start_date < ?"; DateTime currentDate = new DateTime(); DateTime comparableDate = currentDate.minusDays(criminalIdlePeriod); log.info("Comparable Date:" + comparableDate); int updatedRows = jdbcTemplate.update(sql, comparableDate.toDate()); log.info("Archived " + updatedRows + " rows that have been idle for over " + criminalIdlePeriod + " days "); return updatedRows; }
From source file:org.ojbc.bundles.adapters.staticmock.samplegen.AbstractSampleGenerator.java
License:RPL License
/** * Generate a date that occurs before the specified date, with a random spread * /*from w w w.j a v a2 s. co m*/ * @param baseDate * the date before which the generated date will occur * @param meanDaysInThePast * average number of days prior to the specified date that the generated date occurs * @return the generated date */ protected final DateTime generateNormalRandomDateBefore(DateTime baseDate, int meanDaysInThePast) { // we don't care so much about precision... int subtract = Math.abs((int) randomGenerator.nextGaussian(meanDaysInThePast, meanDaysInThePast * 2)); DateTime newDate = baseDate.minusDays(subtract); return newDate; }
From source file:org.opencastproject.dataloader.EventsLoader.java
License:Educational Community License
private List<EventEntry> parseCSV(CSVParser csv) { List<EventEntry> arrayList = new ArrayList<EventEntry>(); for (CSVRecord record : csv) { String title = record.get(0); String description = StringUtils.trimToNull(record.get(1)); String series = StringUtils.trimToNull(record.get(2)); String seriesName = StringUtils.trimToNull(record.get(3)); Integer days = Integer.parseInt(record.get(4)); float signum = Math.signum(days); DateTime now = DateTime.now(); if (signum > 0) { now = now.plusDays(days);/*from w w w .j a va 2 s. co m*/ } else if (signum < 0) { now = now.minusDays(days * -1); } Integer duration = Integer.parseInt(record.get(5)); boolean archive = BooleanUtils.toBoolean(record.get(6)); String agent = StringUtils.trimToNull(record.get(7)); String source = StringUtils.trimToNull(record.get(8)); String contributor = StringUtils.trimToNull(record.get(9)); List<String> presenters = Arrays .asList(StringUtils.split(StringUtils.trimToEmpty(record.get(10)), ",")); EventEntry eventEntry = new EventEntry(title, now.toDate(), duration, archive, series, agent, source, contributor, description, seriesName, presenters); arrayList.add(eventEntry); } return arrayList; }
From source file:org.opendatakit.common.android.utilities.DataUtil.java
License:Apache License
public Interval tryParseInterval(String input) { for (int i = 0; i < userPartialParsers.length; i++) { try {/*from ww w .j av a 2 s. co m*/ DateTime start = userPartialParsers[i].parseDateTime(input); DateTime end = start.plusSeconds(USER_INTERVAL_DURATIONS[i]); return new Interval(start, end); } catch (IllegalArgumentException e) { } } if (!locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) { return null; } DateTime start = new DateMidnight().toDateTime(); boolean match = false; if (input.equalsIgnoreCase("today")) { match = true; } else if (input.equalsIgnoreCase("yesterday")) { start = start.minusDays(1); match = true; } else if (input.equalsIgnoreCase("tomorrow") || input.equalsIgnoreCase("tmw")) { start = start.plusDays(1); match = true; } if (match) { DateTime end = start.plusDays(1); return new Interval(start, end); } return null; }
From source file:org.opendatakit.utilities.DateUtils.java
License:Apache License
private Interval tryParseInterval(String input) { for (int i = 0; i < userPartialParsers.length; i++) { try {//from w w w.jav a2s . c o m DateTime start = userPartialParsers[i].parseDateTime(input); DateTime end = start.plusSeconds(USER_INTERVAL_DURATIONS[i]); return new Interval(start, end); } catch (IllegalArgumentException ignored) { // TODO } } if (!locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) { return null; } DateTime start = new DateTime().withTimeAtStartOfDay(); boolean match = false; if ("today".equalsIgnoreCase(input)) { match = true; } else if ("yesterday".equalsIgnoreCase(input)) { start = start.minusDays(1); match = true; } else if ("tomorrow".equalsIgnoreCase(input) || "tmw".equalsIgnoreCase(input)) { start = start.plusDays(1); match = true; } if (match) { DateTime end = start.plusDays(1); return new Interval(start, end); } return null; }
From source file:org.openlmis.core.manager.SharedPreferenceMgr.java
License:Open Source License
public boolean hasSyncedUpLatestMovementLastDay() { DateTime lastSyncTriggerDate = new DateTime(sharedPreferences.getLong(LAST_MOVEMENT_HANDSHAKE_DATE, 0)); DateTime currentDate = new DateTime(LMISApp.getInstance().getCurrentTimeMillis()); return currentDate.minusDays(1).isBefore(lastSyncTriggerDate); }