Java Code Examples for org.joda.time.Duration#isShorterThan()
The following examples show how to use
org.joda.time.Duration#isShorterThan() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForwardStream.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Spliterator<TimeSeriesCollection> trySplit() { if (pending != null) return null; // We're already traversing. final Duration delta = new Duration(begin, end).dividedBy(2); if (delta.isShorterThan(MIN_INTERVAL)) return null; final DateTime forkedBegin = begin; begin = begin.plus(delta); return new ForwardStream(selector, forkedBegin, begin); }
Example 2
Source File: ClusterWait.java From docker-compose-rule with Apache License 2.0 | 5 votes |
private static Duration minDuration(Duration first, Duration second) { if (first.isShorterThan(second)) { return first; } return second; }
Example 3
Source File: FixedWindows.java From beam with Apache License 2.0 | 5 votes |
private FixedWindows(Duration size, Duration offset) { if (offset.isShorterThan(Duration.ZERO) || !offset.isShorterThan(size)) { throw new IllegalArgumentException( "FixedWindows WindowingStrategies must have 0 <= offset < size"); } this.size = size; this.offset = offset; }
Example 4
Source File: SlidingWindows.java From beam with Apache License 2.0 | 5 votes |
private SlidingWindows(Duration period, Duration size, Duration offset) { if (offset.isShorterThan(Duration.ZERO) || !offset.isShorterThan(period) || !size.isLongerThan(Duration.ZERO)) { throw new IllegalArgumentException( "SlidingWindows WindowingStrategies must have 0 <= offset < period and 0 < size"); } this.period = period; this.size = size; this.offset = offset; }
Example 5
Source File: DataflowPipelineJob.java From beam with Apache License 2.0 | 5 votes |
private static BackOff getMessagesBackoff(Duration duration) { FluentBackoff factory = MESSAGES_BACKOFF_FACTORY; if (!duration.isShorterThan(Duration.ZERO)) { factory = factory.withMaxCumulativeBackoff(duration); } return BackOffAdapter.toGcpBackOff(factory.backoff()); }
Example 6
Source File: ParserUtils.java From substitution-schedule-parser with Mozilla Public License 2.0 | 5 votes |
static LocalDateTime parseDateTime(String string) { if (string == null) return null; reinitIfNeeded(); string = string.replace("Stand:", "").replace("Import:", "").trim(); int i = 0; for (DateTimeFormatter f : dateTimeFormatters) { try { LocalDateTime dt = f.parseLocalDateTime(string); if (dateTimeFormats[i].contains("yyyy")) { return dt; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), dt.toDateTime())); Duration lastYearDifference = abs(new Duration(DateTime.now(), dt.minusYears(1).toDateTime())); Duration nextYearDifference = abs(new Duration(DateTime.now(), dt.plusYears(1).toDateTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]) .withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() - 1) .parseLocalDateTime(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]) .withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() + 1) .parseLocalDateTime(string); } else { return dt; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }
Example 7
Source File: ParserUtils.java From substitution-schedule-parser with Mozilla Public License 2.0 | 5 votes |
private static Duration abs(Duration duration) { Duration nothing = new Duration(0); if (duration.isShorterThan(nothing)) { return duration.negated(); } else { return duration; } }
Example 8
Source File: JobInstanceModel.java From gocd with Apache License 2.0 | 5 votes |
public int getPercentComplete() { Duration eta = eta(); if (eta.getMillis() == 0) { return 0; } if (eta.isShorterThan(getElapsedTime())) { return 100; } return (int) ((getElapsedTime().getMillis() * 100) / eta.getMillis()); }
Example 9
Source File: ExpressionLookBack.java From monsoon with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Interval(@NonNull Duration duration) { if (duration.isShorterThan(Duration.ZERO)) throw new IllegalArgumentException("negative duration not supported"); this.duration = duration; }
Example 10
Source File: ParserUtils.java From substitution-schedule-parser with Mozilla Public License 2.0 | 4 votes |
static LocalDate parseDate(String string) { if (string == null) return null; reinitIfNeeded(); string = string .replace("Stand:", "") .replace("Import:", "") .replaceAll(", Woche [A-Z]", "") .replaceAll(", .*unterricht Gruppe .*", "") .replaceAll(", Unterrichts.* Gruppe .*", "") .trim(); int i = 0; for (DateTimeFormatter f : dateFormatters) { try { LocalDate d = f.parseLocalDate(string); if (dateFormats[i].contains("yyyy")) { return d; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), d.toDateTimeAtCurrentTime())); Duration lastYearDifference = abs(new Duration(DateTime.now(), d.minusYears(1).toDateTimeAtCurrentTime())); Duration nextYearDifference = abs(new Duration(DateTime.now(), d.plusYears(1).toDateTimeAtCurrentTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateFormats[i]) .withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() - 1) .parseLocalDate(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateFormats[i]) .withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() + 1) .parseLocalDate(string); } else { return d; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }
Example 11
Source File: RdeUploadAction.java From nomulus with Apache License 2.0 | 4 votes |
@Override public void runWithLock(final DateTime watermark) throws Exception { logger.atInfo().log("Verifying readiness to upload the RDE deposit."); Cursor cursor = ofy().load().key(Cursor.createKey(CursorType.RDE_STAGING, Registry.get(tld))).now(); loadAndCompare(cursor, tld); DateTime stagingCursorTime = getCursorTimeOrStartOfTime(cursor); if (isBeforeOrAt(stagingCursorTime, watermark)) { throw new NoContentException( String.format( "Waiting on RdeStagingAction for TLD %s to send %s upload; " + "last RDE staging completion was at %s", tld, watermark, stagingCursorTime)); } Cursor sftpCursor = ofy().load().key(Cursor.createKey(RDE_UPLOAD_SFTP, Registry.get(tld))).now(); loadAndCompare(sftpCursor, tld); DateTime sftpCursorTime = getCursorTimeOrStartOfTime(sftpCursor); Duration timeSinceLastSftp = new Duration(sftpCursorTime, clock.nowUtc()); if (timeSinceLastSftp.isShorterThan(sftpCooldown)) { throw new NoContentException( String.format( "Waiting on %d minute SFTP cooldown for TLD %s to send %s upload; " + "last upload attempt was at %s (%d minutes ago)", sftpCooldown.getStandardMinutes(), tld, watermark, sftpCursorTime, timeSinceLastSftp.getStandardMinutes())); } int revision = RdeRevision.getNextRevision(tld, watermark, FULL) - 1; verify(revision >= 0, "RdeRevision was not set on generated deposit"); final String name = RdeNamingUtils.makeRydeFilename(tld, watermark, FULL, 1, revision); final GcsFilename xmlFilename = new GcsFilename(bucket, name + ".xml.ghostryde"); final GcsFilename xmlLengthFilename = new GcsFilename(bucket, name + ".xml.length"); GcsFilename reportFilename = new GcsFilename(bucket, name + "-report.xml.ghostryde"); verifyFileExists(xmlFilename); verifyFileExists(xmlLengthFilename); verifyFileExists(reportFilename); logger.atInfo().log("Commencing RDE upload for TLD '%s' to '%s'.", tld, uploadUrl); final long xmlLength = readXmlLength(xmlLengthFilename); retrier.callWithRetry( () -> upload(xmlFilename, xmlLength, watermark, name), JSchException.class); logger.atInfo().log( "Updating RDE cursor '%s' for TLD '%s' following successful upload.", RDE_UPLOAD_SFTP, tld); tm().transact( () -> { CursorDao.saveCursor( Cursor.create(RDE_UPLOAD_SFTP, tm().getTransactionTime(), Registry.get(tld)), tld); }); response.setContentType(PLAIN_TEXT_UTF_8); response.setPayload(String.format("OK %s %s\n", tld, watermark)); }
Example 12
Source File: DateUtils.java From joda-time-android with Apache License 2.0 | 4 votes |
/** * Return string describing the time until/elapsed time since 'time' formatted like * "[relative time/date], [time]". * * See {@link android.text.format.DateUtils#getRelativeDateTimeString} for full docs. * * @param context the context * @param time some time * @param transitionResolution the elapsed time (period) at which * to stop reporting relative measurements. Periods greater * than this resolution will default to normal date formatting. * For example, will transition from "6 days ago" to "Dec 12" * when using Weeks.ONE. If null, defaults to Days.ONE. * Clamps to min value of Days.ONE, max of Weeks.ONE. * @param flags flags for getRelativeTimeSpanString() (if duration is less than transitionResolution) */ public static CharSequence getRelativeDateTimeString(Context context, ReadableInstant time, ReadablePeriod transitionResolution, int flags) { Resources r = context.getResources(); // We set the millis to 0 so we aren't off by a fraction of a second when counting duration DateTime now = DateTime.now(time.getZone()).withMillisOfSecond(0); DateTime timeDt = new DateTime(time).withMillisOfSecond(0); boolean past = !now.isBefore(timeDt); Duration duration = past ? new Duration(timeDt, now) : new Duration(now, timeDt); // getRelativeTimeSpanString() doesn't correctly format relative dates // above a week or exact dates below a day, so clamp // transitionResolution as needed. Duration transitionDuration; Duration minDuration = Days.ONE.toPeriod().toDurationTo(timeDt); if (transitionResolution == null) { transitionDuration = minDuration; } else { transitionDuration = past ? transitionResolution.toPeriod().toDurationTo(now) : transitionResolution.toPeriod().toDurationFrom(now); Duration maxDuration = Weeks.ONE.toPeriod().toDurationTo(timeDt); if (transitionDuration.isLongerThan(maxDuration)) { transitionDuration = maxDuration; } else if (transitionDuration.isShorterThan(minDuration)) { transitionDuration = minDuration; } } CharSequence timeClause = formatDateRange(context, time, time, FORMAT_SHOW_TIME); String result; if (!duration.isLongerThan(transitionDuration)) { CharSequence relativeClause = getRelativeTimeSpanString(context, time, flags); result = r.getString(R.string.joda_time_android_relative_time, relativeClause, timeClause); } else { CharSequence dateClause = getRelativeTimeSpanString(context, time, false); result = r.getString(R.string.joda_time_android_date_time, dateClause, timeClause); } return result; }