List of usage examples for org.joda.time DateTime plusHours
public DateTime plusHours(int hours)
From source file:org.mythtv.service.guide.v27.ProgramGuideHelperV27.java
License:Open Source License
private static void downloadProgramGuide(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadProgramGuide : enter"); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ProgramHelperV27.getInstance().deletePrograms(context, locationProfile, ops, ProgramConstants.CONTENT_URI_GUIDE, ProgramConstants.TABLE_NAME_GUIDE); RecordingHelperV27.getInstance().deleteRecordings(context, locationProfile, ops, ContentDetails.GUIDE); DateTime startDownloading = new DateTime(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); int downloadDays = Integer.parseInt(sp.getString("preference_program_guide_days", "14")); Log.v(TAG, "downloadProgramGuide : downloadDays=" + downloadDays); DateTime start = new DateTime(DateTimeZone.getDefault()).withTimeAtStartOfDay(); DateTime end = start.plusHours(3); for (int i = 0; i < ((downloadDays * 24) / 3); i++) { Log.i(TAG,//from w ww .j a v a 2 s . c o m "downloadProgramGuide : starting download for [" + (i + 1) + " of " + ((downloadDays * 24) / 3) + "] " + DateUtils.getDateTimeUsingLocaleFormattingPretty(start, mMainApplication.getDateFormat(), mMainApplication.getClockType()) + ", end time=" + DateUtils.getDateTimeUsingLocaleFormattingPretty(end, mMainApplication.getDateFormat(), mMainApplication.getClockType())); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetProgramGuide", String.valueOf(i)); Log.d(TAG, "downloadProgramGuide : etag=" + etag.getValue()); if (null == etag.getDate() || start.isAfter(etag.getDate())) { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has passed"); ResponseEntity<ProgramGuide> responseEntity = mMythServicesTemplate.guideOperations() .getProgramGuide(start, end, 1, null, false, etag); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 200 OK"); ProgramGuide programGuide = responseEntity.getBody(); if (null != programGuide) { if (null != programGuide) { load(context, locationProfile, programGuide); } } if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setEndpoint("GetProgramGuide"); etag.setDataId(i); etag.setDate(locationProfile.getNextMythFillDatabase()); etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } start = end; end = end.plusHours(3); } else { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has NOT passed!"); } } Log.i(TAG, "downloadProgramGuide : interval=" + new Interval(startDownloading, new DateTime()).toString()); Log.v(TAG, "downloadProgramGuide : exit"); }
From source file:org.n52.iceland.util.DateTimeHelper.java
License:Open Source License
/** * Set the time object to the end values (seconds, minutes, hours, days,..) * if the time Object has not all values * * @param dateTime/*from w ww . ja v a 2 s.c o m*/ * Time object * @param isoTimeLength * Length of the time object * @return Modified time object. */ public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(final DateTime dateTime, final int isoTimeLength) { switch (isoTimeLength) { // year case YEAR: return dateTime.plusYears(ONE_VALUE).minusMillis(ONE_VALUE); // year, month case YEAR_MONTH: return dateTime.plusMonths(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day case YEAR_MONTH_DAY: return dateTime.plusDays(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour case YEAR_MONTH_DAY_HOUR: return dateTime.plusHours(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour, minute case YEAR_MONTH_DAY_HOUR_MINUTE: return dateTime.plusMinutes(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour, minute, second case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND: return dateTime.plusSeconds(ONE_VALUE).minusMillis(ONE_VALUE); default: return dateTime; } }
From source file:org.n52.shetland.util.DateTimeHelper.java
License:Apache License
/** * Set the time object to the end values (seconds, minutes, hours, days,..) * if the time Object has not all values * * @param dateTime/* w ww . j a va 2 s .c o m*/ * Time object * @param isoTimeLength * Length of the time object * @return Modified time object. */ public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(DateTime dateTime, int isoTimeLength) { switch (isoTimeLength) { case YEAR: return dateTime.plusYears(1).minusMillis(1); case YEAR_MONTH: return dateTime.plusMonths(1).minusMillis(1); case YEAR_MONTH_DAY: return dateTime.plusDays(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR: return dateTime.plusHours(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR_MINUTE: return dateTime.plusMinutes(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND: return dateTime.plusSeconds(1).minusMillis(1); default: return dateTime; } }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsExpression(DateTime origin, String duration) { int k = getFactor(duration); switch (duration.substring(duration.length() - 1, duration.length())) { case "s": return origin.plusSeconds(k); case "m": return origin.plusMinutes(k); case "h": return origin.plusHours(k); case "d": return origin.plusDays(k); case "w": return origin.plusWeeks(k); case "M": return origin.plusMonths(k); case "y": return origin.plusYears(k); }/* w w w .j a va2 s. c o m*/ return invalid(duration); }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsNoun(DateTime origin, String duration) { switch (duration.toLowerCase()) { case "second": return origin.plusSeconds(1); case "minute": return origin.plusMinutes(1); case "hour": return origin.plusHours(1); case "day": return origin.plusDays(1); case "week": return origin.plusWeeks(1); case "month": return origin.plusMonths(1); case "quarter": return origin.plusMonths(3); case "year": return origin.plusYears(1); }//w w w. jav a 2s .com return invalid(duration); }
From source file:org.obiba.agate.service.AuthorizationService.java
License:Open Source License
private DateTime getExpirationDate(DateTime created) { return created.plusHours(configurationService.getConfiguration().getLongTimeout()); }
From source file:org.openvpms.archetype.i18n.time.DateDurationFormatter.java
License:Open Source License
/** * Formats the duration between two timestamps. * <p/>//from w w w .ja va 2s . c om * NOTE: this currently doesn't do anything sensible for from > to. Possible solution would be to simply * reverse the times, and then prepend a - between each field using the * * @param from the starting time * @param to the ending time * @return the formatted duration */ protected String format(DateTime from, DateTime to) { int years = 0; int months = 0; int weeks = 0; int days = 0; int hours = 0; int minutes = 0; DateTime start = from; if (showYears) { years = Years.yearsBetween(start, to).getYears(); start = start.plusYears(years); } if (showMonths) { months = Months.monthsBetween(start, to).getMonths(); start = start.plusMonths(months); } if (showWeeks) { weeks = Weeks.weeksBetween(start, to).getWeeks(); start = start.plusWeeks(weeks); } if (showDays) { days = Days.daysBetween(start, to).getDays(); start = start.plusDays(days); } if (showHours) { hours = Hours.hoursBetween(start, to).getHours(); start = start.plusHours(hours); } if (showMinutes) { minutes = Minutes.minutesBetween(start, to).getMinutes(); } Period period = new Period(years, months, weeks, days, hours, minutes, 0, 0); return formatter.print(period); }
From source file:org.openvpms.web.workspace.workflow.appointment.FreeAppointmentSlotQuery.java
License:Open Source License
/** * Returns the next slot nearest to the specified time. * * @param time the slot time/*from w ww . ja v a 2 s. c o m*/ * @return the next nearest slot */ private Date getNextSlot(Date time) { Date from; int slotSize = 15; DateTime dt = new DateTime(time); int min = (dt.getMinuteOfHour() / slotSize) * slotSize; if (dt.getMinuteOfHour() % slotSize != 0) { min += slotSize; if (min >= 60) { dt = dt.plusHours(1); min = 0; } } from = dt.withMinuteOfHour(min).minuteOfDay().roundFloorCopy().toDate(); return from; }
From source file:org.qipki.crypto.x509.X509GeneratorImpl.java
License:Open Source License
@Override public X509CRL updateX509CRL(X509Certificate caCertificate, PrivateKey caPrivateKey, X509Certificate revokedCertificate, RevocationReason reason, X509CRL previousCRL, BigInteger lastCRLNumber) { try {//from w w w. j a va 2 s . c o m X509V2CRLGenerator crlGen = new X509V2CRLGenerator(); crlGen.setIssuerDN(caCertificate.getSubjectX500Principal()); DateTime skewedNow = new DateTime().minus(Time.CLOCK_SKEW); crlGen.setThisUpdate(skewedNow.toDate()); crlGen.setNextUpdate(skewedNow.plusHours(12).toDate()); crlGen.setSignatureAlgorithm(SignatureAlgorithm.SHA256withRSA.jcaString()); crlGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(caCertificate)); crlGen.addExtension(X509Extensions.CRLNumber, false, new CRLNumber(lastCRLNumber)); crlGen.addCRL(previousCRL); crlGen.addCRLEntry(revokedCertificate.getSerialNumber(), skewedNow.toDate(), reason.reason()); return crlGen.generate(caPrivateKey, BouncyCastleProvider.PROVIDER_NAME); } catch (GeneralSecurityException ex) { throw new CryptoFailure("Unable to update CRL", ex); } }
From source file:org.richfaces.fragment.calendar.TimeEditor.java
License:Open Source License
public DateTime getTime() { int seconds = (getSecondsSpinner() != null ? getSecondsSpinner().getValue() : defaultSeconds); int minutes = (getMinutesSpinner() != null ? getMinutesSpinner().getValue() : defaultMinutes); int hours = (getHoursSpinner() != null ? getHoursSpinner().getValue() : defaultHours); DateTime result = new DateTime().withHourOfDay(hours).withMinuteOfHour(minutes).withSecondOfMinute(seconds); TimeSignSpinner tss = getTimeSignSpinner(); if (tss != null) { switch (tss.getValue()) { case AM:/* www. j av a 2 s . c o m*/ if (result.getHourOfDay() == 12) {//12:xx am -> 00:xx result = result.minusHours(12); } break; case PM: if (result.getHourOfDay() != 12) { result = result.plusHours(12); } break; default: throw new IllegalArgumentException("Unknown switch"); } } return result; }