Java Code Examples for java.util.concurrent.TimeUnit#DAYS

The following examples show how to use java.util.concurrent.TimeUnit#DAYS . 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: TestPrometheusSplit.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitTimesCorrect()
        throws Exception
{
    io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(3, TimeUnit.DAYS);
    io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(1, TimeUnit.DAYS);
    LocalDateTime now = ofInstant(Instant.ofEpochMilli(1000000000L), ZoneId.systemDefault());
    PrometheusTimeMachine.useFixedClockAt(now);

    List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(
            now,
            maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
    List<String> expectedSplitTimes = ImmutableList.of(
            "827199.998", "913599.999", "1000000");
    assertEquals(splitTimes, expectedSplitTimes);
}
 
Example 2
Source File: SessionHandler.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
private TimeUnit convertTimeUnit(int unit) {
    switch (unit) {
        case 0:
            return TimeUnit.NANOSECONDS;
        case 1:
            return TimeUnit.MICROSECONDS;
        case 2:
            return TimeUnit.MILLISECONDS;
        case 3:
            return TimeUnit.SECONDS;
        case 4:
            return TimeUnit.MINUTES;
        case 5:
            return TimeUnit.HOURS;
        case 6:
            return TimeUnit.DAYS;
        default:
            return TimeUnit.MILLISECONDS;
    }
}
 
Example 3
Source File: MachineTime.java    From Time4A with Apache License 2.0 6 votes vote down vote up
@Override
protected TimeUnit getUnit(char symbol) {

    switch (symbol) {
        case 'D':
            return TimeUnit.DAYS;
        case 'h':
            return TimeUnit.HOURS;
        case 'm':
            return TimeUnit.MINUTES;
        case 's':
            return TimeUnit.SECONDS;
        case 'f':
            return TimeUnit.NANOSECONDS;
        default:
            throw new IllegalArgumentException(
                "Unsupported pattern symbol: " + symbol);
    }

}
 
Example 4
Source File: ThirdEyeUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Guess time unit from period.
 *
 * @param granularity dataset granularity
 * @return
 */
public static TimeUnit getTimeUnit(Period granularity) {
  if (granularity.getDays() > 0) {
    return TimeUnit.DAYS;
  }
  if (granularity.getHours() > 0) {
    return TimeUnit.HOURS;
  }
  if (granularity.getMinutes() > 0) {
    return TimeUnit.MINUTES;
  }
  if (granularity.getSeconds() > 0) {
    return TimeUnit.SECONDS;
  }
  return TimeUnit.MILLISECONDS;
}
 
Example 5
Source File: Temporals.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
public static TimeUnit timeUnit(ChronoUnit unit) {
    switch (unit) {
        case NANOS:
            return TimeUnit.NANOSECONDS;
        case MICROS:
            return TimeUnit.MICROSECONDS;
        case MILLIS:
            return TimeUnit.MILLISECONDS;
        case SECONDS:
            return TimeUnit.SECONDS;
        case MINUTES:
            return TimeUnit.MINUTES;
        case HOURS:
            return TimeUnit.HOURS;
        case DAYS:
            return TimeUnit.DAYS;
        default:
            throw new IllegalArgumentException("Cannot convert chronounit");
    }
}
 
Example 6
Source File: UnitFormatUtils.java    From RxHttp with GNU General Public License v3.0 6 votes vote down vote up
public static String formatTimeUnit(TimeUnit timeUnit){
    if (timeUnit == null) {
        return "-";
    }
    if (timeUnit == TimeUnit.NANOSECONDS) {
        return "ns";
    } else if (timeUnit == TimeUnit.MICROSECONDS){
        return "us";
    } else if (timeUnit == TimeUnit.MILLISECONDS){
        return "ms";
    } else if (timeUnit == TimeUnit.SECONDS){
        return "s";
    } else if (timeUnit == TimeUnit.MINUTES){
        return "m";
    } else if (timeUnit == TimeUnit.HOURS){
        return "h";
    } else if (timeUnit == TimeUnit.DAYS){
        return "d";
    } else {
        return "-";
    }
}
 
Example 7
Source File: TimeValue.java    From bboss-elasticsearch with Apache License 2.0 5 votes vote down vote up
public static TimeValue parseTimeValue(String sValue, TimeValue defaultValue, String settingName) {
	settingName = requireNonNull(settingName);
	if (sValue == null) {
		return defaultValue;
	}
	final String normalized = sValue.toLowerCase(Locale.ROOT).trim();
	if (normalized.endsWith("nanos")) {
		return new TimeValue(parse(sValue, normalized, "nanos"), TimeUnit.NANOSECONDS);
	} else if (normalized.endsWith("micros")) {
		return new TimeValue(parse(sValue, normalized, "micros"), TimeUnit.MICROSECONDS);
	} else if (normalized.endsWith("ms")) {
		return new TimeValue(parse(sValue, normalized, "ms"), TimeUnit.MILLISECONDS);
	} else if (normalized.endsWith("s")) {
		return new TimeValue(parse(sValue, normalized, "s"), TimeUnit.SECONDS);
	} else if (sValue.endsWith("m")) {
		// parsing minutes should be case-sensitive as 'M' means "months", not "minutes"; this is the only special case.
		return new TimeValue(parse(sValue, normalized, "m"), TimeUnit.MINUTES);
	} else if (normalized.endsWith("h")) {
		return new TimeValue(parse(sValue, normalized, "h"), TimeUnit.HOURS);
	} else if (normalized.endsWith("d")) {
		return new TimeValue(parse(sValue, normalized, "d"), TimeUnit.DAYS);
	} else if (normalized.matches("-0*1")) {
		return TimeValue.MINUS_ONE;
	} else if (normalized.matches("0+")) {
		return TimeValue.ZERO;
	} else {
		// Missing units:
		throw new IllegalArgumentException("failed to parse setting [" + settingName + "] with value [" + sValue +
				"] as a time value: unit is missing or unrecognized");
	}
}
 
Example 8
Source File: TimeUnitTestTarget.java    From AVM with MIT License 5 votes vote down vote up
@Callable
public static boolean testavm_values() {
    TimeUnit[] values =  (TimeUnit[]) TimeUnit.values();
    return TimeUnit.DAYS == values[0] &&
            TimeUnit.HOURS == values[1] &&
            TimeUnit.MINUTES == values[2] &&
            TimeUnit.SECONDS == values[3] &&
            TimeUnit.MILLISECONDS == values[4] &&
            TimeUnit.MICROSECONDS == values[5] &&
            TimeUnit.NANOSECONDS == values[6];
}
 
Example 9
Source File: MCRRestObjects.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@GET
@Path("{" + PARAM_MCRID + "}/thumb.{ext : (jpg|jpeg|png)}")
@Produces({ "image/png", "image/jpeg" })
@Operation(
    summary = "Returns thumbnail of MCRObject with the given " + PARAM_MCRID + ".",
    tags = MCRRestUtils.TAG_MYCORE_OBJECT)
@MCRCacheControl(maxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS),
    sMaxAge = @MCRCacheControl.Age(time = 1, unit = TimeUnit.DAYS))
public Response getThumbnail(@PathParam(PARAM_MCRID) String id, @PathParam("ext") String ext) {
    int defaultSize = MCRConfiguration2.getOrThrow("MCR.Media.Thumbnail.DefaultSize", Integer::parseInt);
    return getThumbnail(id, defaultSize, ext);
}
 
Example 10
Source File: TimeTest.java    From twister2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  this.sampleTimeMilli = new Time(period, TimeUnit.MILLISECONDS);
  this.sampleTimeSeconds = new Time(period, TimeUnit.SECONDS);
  this.sampleTimeMinutes = new Time(period, TimeUnit.MINUTES);
  this.sampleTimeHours = new Time(period, TimeUnit.HOURS);
  this.sampleTimeDays = new Time(period, TimeUnit.DAYS);
}
 
Example 11
Source File: DBasicMetricsRWIntegrationTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void delayedMetric_shouldGetBoundStatement() throws Exception {
    Clock clock = new DefaultClockImpl();
    TimeValue aDay = new TimeValue(1, TimeUnit.DAYS);

    DBasicMetricsRW metricsRW = new DBasicMetricsRW(locatorIO, delayedLocatorIO, false, clock);
    Locator locator = Locator.createLocatorFromPathComponents("123456", "foo.bar");
    IMetric metric = new Metric(locator,
            987L, clock.now().getMillis() - aDay.toMillis(),
            aDay, null);
    assertNotNull("delayed metric should get a boundStatement", metricsRW.getBoundStatementForMetricIfDelayed(metric));
}
 
Example 12
Source File: Duration.java    From monasca-common with Apache License 2.0 4 votes vote down vote up
public static Duration days(long count) {
  return new Duration(count, TimeUnit.DAYS);
}
 
Example 13
Source File: Duration.java    From lyra with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a Duration of {@code count} days.
 */
public static Duration days(long count) {
  return new Duration(count, TimeUnit.DAYS);
}
 
Example 14
Source File: IntegrationTestBase.java    From blueflood with Apache License 2.0 4 votes vote down vote up
protected Metric getRandomIntMetricMaxValue(final Locator locator, long timestamp, int max) {
    locatorToUnitMap.putIfAbsent(locator, UNIT_ENUM.values()[new Random().nextInt(UNIT_ENUM.values().length)].unit);
    return new Metric(locator, RAND.nextInt( max ), timestamp, new TimeValue(1, TimeUnit.DAYS), locatorToUnitMap.get(locator));
}
 
Example 15
Source File: Printer.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Every(period = 1, unit = TimeUnit.DAYS)
public void cleanup() {
    System.out.println("Cleanup !");
}
 
Example 16
Source File: FormatUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@link TimeUnit} enum that maps to the provided raw {@code String} input. The
 * highest time unit is {@code TimeUnit.DAYS}. Any input that cannot be parsed will result in
 * an {@link IllegalArgumentException}.
 *
 * @param rawUnit the String to parse
 * @return the TimeUnit
 */
protected static TimeUnit determineTimeUnit(String rawUnit) {
    switch (rawUnit.toLowerCase()) {
        case "ns":
        case "nano":
        case "nanos":
        case "nanoseconds":
            return TimeUnit.NANOSECONDS;
        case "µs":
        case "micro":
        case "micros":
        case "microseconds":
            return TimeUnit.MICROSECONDS;
        case "ms":
        case "milli":
        case "millis":
        case "milliseconds":
            return TimeUnit.MILLISECONDS;
        case "s":
        case "sec":
        case "secs":
        case "second":
        case "seconds":
            return TimeUnit.SECONDS;
        case "m":
        case "min":
        case "mins":
        case "minute":
        case "minutes":
            return TimeUnit.MINUTES;
        case "h":
        case "hr":
        case "hrs":
        case "hour":
        case "hours":
            return TimeUnit.HOURS;
        case "d":
        case "day":
        case "days":
            return TimeUnit.DAYS;
        default:
            throw new IllegalArgumentException("Could not parse '" + rawUnit + "' to TimeUnit");
    }
}
 
Example 17
Source File: MapBuilder.java    From AnnihilationPro with MIT License 4 votes vote down vote up
public static TimeUnit getUnit(String input)
{
	TimeUnit u;
	switch(input.toLowerCase())
	{
		case "error":
			default:
			return null;
			
		case "s":
		case "sec":
		case "secs":
		case "second":
		case "seconds":
			u = TimeUnit.SECONDS;
			break;
		
		case "m":
		case "min":
		case "mins":
		case "minute":
		case "minutes":
			u = TimeUnit.MINUTES;
			break;
			
		case "h":
		case "hr":
		case "hrs":
		case "hour":
		case "hours":
			u = TimeUnit.HOURS;
			break;
			
		case "d":
		case "day":
		case "days":
			u = TimeUnit.DAYS;
			break;
	}
	return u;
}
 
Example 18
Source File: Duration.java    From monasca-common with Apache License 2.0 4 votes vote down vote up
/** Infinite constructor. */
private Duration() {
  finite = false;
  this.length = Long.MAX_VALUE;
  this.timeUnit = TimeUnit.DAYS;
}
 
Example 19
Source File: Configuration.java    From flink with Apache License 2.0 votes vote down vote up
TimeUnit unit() { return TimeUnit.DAYS; } 
Example 20
Source File: Configuration.java    From hadoop with Apache License 2.0 votes vote down vote up
TimeUnit unit() { return TimeUnit.DAYS; }