Constructs a Period representing a duration of
count units extending into the past.
@param count the number of units, must be non-negative
@param unit the unit
@return the new Period
423459
public static Period at(float count, TimeUnit unit) {
    checkCount(count);
    return new Period(ETimeLimit.NOLIMIT, false, count, unit);
  }
988378
public void start(long period, TimeUnit unit) {
		synchronized (this) {
			if (started) {
				throw new IllegalStateException("This reporter has already been started");
			}
			final long periodInMS = unit.toMillis(period);
			executor.scheduleAtFixedRate(new Runnable() {
				@Override
				public void run() {
					try {
						report();
					} catch (RuntimeException ex) {
						logger.error("RuntimeException thrown from {}#report. Exception was suppressed.", ScheduledMetrics2Reporter.this.getClass().getSimpleName(), ex);
					}
				}
			}, getOffsetUntilTimestampIsDivisableByPeriod(clock.getTime(), periodInMS), periodInMS, TimeUnit.MILLISECONDS);
			this.clock = new QuantizedClock(clock, periodInMS);
			this.started = true;
		}
	}
1212654
def p_duration_number_duration_unit(self, p):
        ''
        logger.debug('duration = number %s, duration unit %s', p[1], p[2])
        p[0] = Duration.from_quantity_unit(p[1], p[2])
278962
public Duration add( long duration,
                         TimeUnit unit ) {
        long durationInNanos = TimeUnit.NANOSECONDS.convert(duration, unit);
        return new Duration(this.durationInNanos + durationInNanos);
    }
300721
@Override
    public long get(TemporalUnit unit) {
        if (unit == ChronoUnit.YEARS) {
            return years;
        } else if (unit == ChronoUnit.MONTHS) {
            return months;
        } else if (unit == ChronoUnit.DAYS) {
            return days;
        } else {
            throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
        }
    }
751075
public double totalTime(TimeUnit unit) {
        T obj2 = ref.get();
        if (obj2 != null) {
            double prevLast = lastTime;
            lastTime = Math.max(TimeUtils.convert(totalTimeFunction.applyAsDouble(obj2), totalTimeFunctionUnit, baseTimeUnit()), 0);
            total.getCurrent().add(lastTime - prevLast);
        }
        return TimeUtils.convert(total.poll(), baseTimeUnit(), unit);
    }
360333
synchronized public void start(long initialDelay, long period, TimeUnit unit) {
        start(initialDelay, period, unit, () -> {
            try {
                report();
            } catch (Throwable ex) {
                LOG.error("Exception thrown from {}#report. Exception was suppressed.", ScheduledReporter.this.getClass().getSimpleName(), ex);
            }
        });
    }
441170
public final Timeout deadline(long duration, TimeUnit unit) {
    if (duration <= 0) throw new IllegalArgumentException("duration <= 0: " + duration);
    if (unit == null) throw new IllegalArgumentException("unit == null");
    return deadlineNanoTime(System.nanoTime() + unit.toNanos(duration));
  }
362140
public static PeriodDuration of(Duration duration) {
        Objects.requireNonNull(duration, "The duration must not be null");
        return new PeriodDuration(Period.ZERO, duration);
    }
910
private Duration getDuration(TimeUnit units, Double duration)
   {
      Duration result = null;
      if (duration != null)
      {
         double durationValue = duration.doubleValue() * 100.0;

         switch (units)
         {
            case MINUTES:
            {
               durationValue *= MINUTES_PER_DAY;
               break;
            }

            case HOURS:
            {
               durationValue *= HOURS_PER_DAY;
               break;
            }

            case DAYS:
            {
               durationValue *= 3.0;
               break;
            }

            case WEEKS:
            {
               durationValue *= 0.6;
               break;
            }

            case MONTHS:
            {
               durationValue *= 0.15;
               break;
            }

            default:
            {
               throw new IllegalArgumentException("Unsupported time units " + units);
            }
         }

         durationValue = Math.round(durationValue) / 100.0;

         result = Duration.getInstance(durationValue, units);
      }

      return result;
   }
880657
public void setPeriod(@Nullable Period period) {
    checkState(!initialized, "Period have already been initialized");
    this.period = period;
    this.initialized = true;
  }
1286955
def p_duration_duration_unit(self, p):
        ''
        logger.debug('duration = 1 of duration unit %s', p[1])
        p[0] = Duration.from_quantity_unit(1, p[1])
208821
@Override
    public Instant plus(long amountToAdd, TemporalUnit unit) {
        if (unit instanceof ChronoUnit) {
            switch ((ChronoUnit) unit) {
                case NANOS: return plusNanos(amountToAdd);
                case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
                case MILLIS: return plusMillis(amountToAdd);
                case SECONDS: return plusSeconds(amountToAdd);
                case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
                case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
                case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
                case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
            }
            throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
        }
        return unit.addTo(this, amountToAdd);
    }
784859
public static PeriodValue createFromDuration(DateValue start, DateValue dur) {
        DateValue end = TimeUtils.add(start, dur);
        if (end instanceof TimeValue && !(start instanceof TimeValue)) {
            start = TimeUtils.dayStart(start);
        }
        return new PeriodValueImpl(start, end);
    }
744772
public Duration subtract( Duration duration ) {
        return new Duration(this.durationInNanos - (duration == null ? 0l : duration.longValue()));
    }
935521
private static final double printDurationFractionsOfMinutes(Duration duration, int factor)
   {
      double result = 0;

      if (duration != null)
      {
         result = duration.getDuration();

         switch (duration.getUnits())
         {
            case HOURS:
            case ELAPSED_HOURS:
            {
               result *= 60;
               break;
            }

            case DAYS:
            {
               result *= (60 * 8);
               break;
            }

            case ELAPSED_DAYS:
            {
               result *= (60 * 24);
               break;
            }

            case WEEKS:
            {
               result *= (60 * 8 * 5);
               break;
            }

            case ELAPSED_WEEKS:
            {
               result *= (60 * 24 * 7);
               break;
            }

            case MONTHS:
            {
               result *= (60 * 8 * 5 * 4);
               break;
            }

            case ELAPSED_MONTHS:
            {
               result *= (60 * 24 * 30);
               break;
            }

            case YEARS:
            {
               result *= (60 * 8 * 5 * 52);
               break;
            }

            case ELAPSED_YEARS:
            {
               result *= (60 * 24 * 365);
               break;
            }

            default:
            {
               break;
            }
         }
      }

      result *= factor;

      return (result);
   }
508519
public DurationRule maxAge(long maxAge, TimeUnit timeUnit) {
    return maxAge(Duration.ofNanos(TimeUnit.NANOSECONDS.convert(maxAge, timeUnit)));
  }