private Duration nextDurationRaw() { return Duration.ofSeconds( nextLong( DAYS.getDuration().getSeconds() ), nextLong( NANOS_PER_SECOND ) ); }
/** * Converts a number of time units to a duration in microseconds. * * @param years a number of years * @param months a number of months * @param days a number of days * @param hours a number of hours * @param minutes a number of minutes * @param seconds a number of seconds * @param micros a number of microseconds * @param daysPerMonthAvg an optional value representing a days per month average; if null, the default duration * from {@link ChronoUnit#MONTHS} is used. * @return a {@link BigDecimal} value which contains the number of microseconds, never {@code null} */ public static double durationMicros(int years, int months, int days, int hours, int minutes, double seconds, int micros, Double daysPerMonthAvg) { if (daysPerMonthAvg == null) { daysPerMonthAvg = (double) ChronoUnit.MONTHS.getDuration().toDays(); } double numberOfDays = ((years * 12) + months) * daysPerMonthAvg + days; double numberOfSeconds = (((numberOfDays * 24 + hours) * 60) + minutes) * 60 + seconds; return numberOfSeconds * 1e6 + micros; }
@Test public void neverGoAfterInfinite() { Duration afterInfinite = ChronoUnit.FOREVER.getDuration(); Timeouts t = TimeoutsBuilder.timeouts() .read(afterInfinite) .write(afterInfinite) .connection(afterInfinite) .build(); assertThat(t.getReadOperationTimeout()).isEqualTo(Timeouts.INFINITE_TIMEOUT); assertThat(t.getWriteOperationTimeout()).isEqualTo(Timeouts.INFINITE_TIMEOUT); assertThat(t.getConnectionTimeout()).isEqualTo(Timeouts.INFINITE_TIMEOUT); } }
dateUnit.getTemporalUnit().getDuration().toMillis(), dateUnit.getTemporalUnit().getDuration().toMillis(),
@BeforeSuite public void setup() throws Exception { EventBuilder builder = new EventBuilder(PROJECT_NAME, getMetastore()); getMetastore().createProject(PROJECT_NAME); for (int cIdx = 0; cIdx < 2; cIdx++) { final int finalCIdx = cIdx; List<Event> events = IntStream.range(0, SCALE_FACTOR).mapToObj(i -> builder.createEvent("test" + finalCIdx, ImmutableMap.<String, Object>builder() .put("teststr", "test" + (i % 2)) .put("_user", "test" + (i % 2)) .put("_time", Instant.ofEpochSecond(i * DAYS.getDuration().getSeconds())).build())) .collect(Collectors.toList()); getEventStore().storeBatch(events); } }
public static Duration infinity() { return ChronoUnit.FOREVER.getDuration(); }
@Override public Long from() { return end - (time * chronoUnit.getDuration().toMillis()); }
public static Interval interval(ChronoUnit unit, int interval) { return () -> unit.getDuration().toMillis() * interval; }
public Duration getDuration() { if (myChronoUnit != null) { return myChronoUnit.getDuration(); } else { // QUARTER return ChronoUnit.MONTHS.getDuration().multipliedBy(3L); } }
public Duration getDuration() { if (myChronoUnit != null) { return myChronoUnit.getDuration(); } else { // QUARTER return ChronoUnit.MONTHS.getDuration().multipliedBy(3L); } }
/** * @param args the first value is the time span e.g. 5, 10, the second one is the unit of the time span */ @Override public void setArguments(String[] args) { this.timeSpan = Long.parseLong(args[0]); this.unit = ChronoUnit.valueOf(args[1].toUpperCase()); this.windowTime = unit.getDuration().toMillis() * timeSpan; }
/** * @param args the first value is the amount, e.g 10, the second one is the unit, e.g HOURS */ @Override public void setArguments(String[] args) { this.amount = Long.parseLong(args[0]); this.unit = ChronoUnit.valueOf(args[1].toUpperCase()); this.shift = unit.getDuration().toMillis() * amount; }
/** * Returns the duration in milliseconds * * @param duration - amount of time in the units indicated by the provided {@link OWLTime} URI * @param uri - OWLTime URI indicating the time unit of duration (not null) * @return - the amount of time in milliseconds * @throws IllegalArgumentException if provided {@link URI} is not a valid, supported OWL-Time time unit. */ public static long getMillis(int duration, URI uri) throws IllegalArgumentException { Optional<ChronoUnit> unit = getChronoUnitFromURI(uri); checkArgument(unit.isPresent(), String.format("URI %s does not indicate a valid OWLTime time unit. URI must of be of type %s, %s, %s, %s, or %s .", uri, SECONDS_URI, MINUTES_URI, HOURS_URI, DAYS_URI, WEEKS_URI)); return duration * unit.get().getDuration().toMillis(); }
/** * Returns the duration in milliseconds * * @param duration - amount of time in the units indicated by the provided {@link OWLTime} IRI * @param iri - OWLTime IRI indicating the time unit of duration (not null) * @return - the amount of time in milliseconds * @throws IllegalArgumentException if provided {@link IRI} is not a valid, supported OWL-Time time unit. */ public static long getMillis(int duration, IRI iri) throws IllegalArgumentException { Optional<ChronoUnit> unit = getChronoUnitFromURI(iri); checkArgument(unit.isPresent(), String.format("IRI %s does not indicate a valid OWLTime time unit. IRI must of be of type %s, %s, %s, %s, or %s .", iri, SECONDS_URI, MINUTES_URI, HOURS_URI, DAYS_URI, WEEKS_URI)); return duration * unit.get().getDuration().toMillis(); }
private Duration nextDurationRaw() { return Duration.ofSeconds( nextLong( DAYS.getDuration().getSeconds() ), nextLong( NANOS_PER_SECOND ) ); }
/** * Converts a number of time units to a duration in microseconds. * * @param years a number of years * @param months a number of months * @param days a number of days * @param hours a number of hours * @param minutes a number of minutes * @param seconds a number of seconds * @param micros a number of microseconds * @param daysPerMonthAvg an optional value representing a days per month average; if null, the default duration * from {@link ChronoUnit#MONTHS} is used. * @return a {@link BigDecimal} value which contains the number of microseconds, never {@code null} */ public static double durationMicros(int years, int months, int days, int hours, int minutes, double seconds, int micros, Double daysPerMonthAvg) { if (daysPerMonthAvg == null) { daysPerMonthAvg = (double) ChronoUnit.MONTHS.getDuration().toDays(); } double numberOfDays = ((years * 12) + months) * daysPerMonthAvg + days; double numberOfSeconds = (((numberOfDays * 24 + hours) * 60) + minutes) * 60 + seconds; return numberOfSeconds * 1e6 + micros; }
private static Optional<String> inUnits(Duration duration, ChronoUnit unit, String name) { Duration cutoff = unit.getDuration().multipliedBy(2); if (duration.compareTo(cutoff) >= 0) { return Optional.of(convert(duration, unit, name)); } else { return Optional.empty(); } }
private static String convert(Duration duration, ChronoUnit unit, String name) { double value = seconds(duration) / seconds(unit.getDuration()); return toThreeSigFig(value, 2000) + " " + name; }
} else { eventsPerYear = -1; double estimatedSecs = months * MONTHS.getDuration().getSeconds() + days * DAYS.getDuration().getSeconds(); eventsPerYearEstimate = YEARS.getDuration().getSeconds() / estimatedSecs;
if (duration.getNano() % ChronoUnit.MILLIS.getDuration().getNano() >= 1) result += (duration.getNano() % ChronoUnit.MILLIS.getDuration().getNano()) + "nanos";