java.time.temporal.ChronoUnit#SECONDS源码实例Demo

下面列出了java.time.temporal.ChronoUnit#SECONDS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ehcache3   文件: ExpiryUtils.java
public static TemporalUnit jucTimeUnitToTemporalUnit(TimeUnit timeUnit) {
  switch (timeUnit) {
    case NANOSECONDS:
      return ChronoUnit.NANOS;
    case MICROSECONDS:
      return ChronoUnit.MICROS;
    case MILLISECONDS:
      return ChronoUnit.MILLIS;
    case SECONDS:
      return ChronoUnit.SECONDS;
    case MINUTES:
      return ChronoUnit.MINUTES;
    case HOURS:
      return ChronoUnit.HOURS;
    case DAYS:
      return ChronoUnit.DAYS;
    default:
      throw new AssertionError("Unkown TimeUnit: " + timeUnit);
  }
}
 
源代码2 项目: ehcache3   文件: XmlModel.java
public static TemporalUnit convertToJavaTimeUnit(org.ehcache.xml.model.TimeUnit unit) {
  switch (unit) {
    case NANOS:
      return ChronoUnit.NANOS;
    case MICROS:
      return ChronoUnit.MICROS;
    case MILLIS:
      return ChronoUnit.MILLIS;
    case SECONDS:
      return ChronoUnit.SECONDS;
    case MINUTES:
      return ChronoUnit.MINUTES;
    case HOURS:
      return ChronoUnit.HOURS;
    case DAYS:
      return ChronoUnit.DAYS;
    default:
      throw new IllegalArgumentException("Unknown time unit: " + unit);
  }
}
 
源代码3 项目: runelite   文件: XpGlobesPlugin.java
@Schedule(
	period = 1,
	unit = ChronoUnit.SECONDS
)
public void removeExpiredXpGlobes()
{
	if (!xpGlobes.isEmpty())
	{
		Instant currentTime = Instant.now();
		for (Iterator<XpGlobe> it = xpGlobes.iterator(); it.hasNext();)
		{
			XpGlobe globe = it.next();
			Instant globeCreationTime = globe.getTime();
			if (currentTime.isBefore(globeCreationTime.plusSeconds(config.xpOrbDuration())))
			{
				//if a globe is not expired, stop checking newer globes
				return;
			}
			it.remove();
		}
	}
}
 
源代码4 项目: elexis-3-core   文件: DateMatchers.java
private static ChronoUnit convertUnit(final TimeUnit unit) {
    switch (unit) {
    case DAYS:
        return ChronoUnit.DAYS;
    case HOURS:
        return ChronoUnit.HOURS;
    case MICROSECONDS:
        return ChronoUnit.MICROS;
    case MILLISECONDS:
        return ChronoUnit.MILLIS;
    case MINUTES:
        return ChronoUnit.MINUTES;
    case NANOSECONDS:
        return ChronoUnit.NANOS;
    case SECONDS:
        return ChronoUnit.SECONDS;
    default:
        throw new IllegalArgumentException("Unknown TimeUnit '" + unit + "'");
    }
}
 
源代码5 项目: chart-fx   文件: Cache.java
protected static ChronoUnit convertToChronoUnit(final TimeUnit timeUnit) {
    switch (timeUnit) {
    case NANOSECONDS:
        return ChronoUnit.NANOS;
    case MICROSECONDS:
        return ChronoUnit.MICROS;
    case SECONDS:
        return ChronoUnit.SECONDS;
    case MINUTES:
        return ChronoUnit.MINUTES;
    case HOURS:
        return ChronoUnit.HOURS;
    case DAYS:
        return ChronoUnit.DAYS;
    case MILLISECONDS:
    default:
        return ChronoUnit.MILLIS;
    }
}
 
源代码6 项目: grakn   文件: Temporals.java
public static ChronoUnit chronoUnit(TimeUnit unit) {
    switch (unit) {
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case HOURS:
            return ChronoUnit.HOURS;
        case DAYS:
            return ChronoUnit.DAYS;
        default:
            throw new IllegalArgumentException("Cannot convert timeunit");
    }
}
 
源代码7 项目: ehcache3   文件: XmlModel.java
public static TemporalUnit convertToJavaTemporalUnit(org.ehcache.xml.model.TimeUnit unit) {
  switch (unit) {
    case NANOS:
      return ChronoUnit.NANOS;
    case MICROS:
    return ChronoUnit.MICROS;
    case MILLIS:
      return ChronoUnit.MILLIS;
    case SECONDS:
      return ChronoUnit.SECONDS;
    case MINUTES:
      return ChronoUnit.MINUTES;
    case HOURS:
      return ChronoUnit.HOURS;
    case DAYS:
      return ChronoUnit.DAYS;
    default:
      throw new IllegalArgumentException("Unknown time unit: " + unit);
  }
}
 
源代码8 项目: java-coroutines   文件: ManualExecutor.java
private ChronoUnit toChronoUnit(final TimeUnit unit) {
	switch (unit) {
		case NANOSECONDS:
		case MICROSECONDS:
			return ChronoUnit.MICROS;
		case MILLISECONDS:
			return ChronoUnit.MILLIS;
		case SECONDS:
			return ChronoUnit.SECONDS;
		case MINUTES:
			return ChronoUnit.MINUTES;
		case HOURS:
			return ChronoUnit.HOURS;
		case DAYS:
			return ChronoUnit.DAYS;
		default:
			throw new AssertionError();
	}
}
 
private static ChronoUnit toChronoUnit(TimeUnit unit) {
  if(unit == null) {
    return null;
  }
  switch (unit) {
    case NANOSECONDS:  return ChronoUnit.NANOS;
    case MICROSECONDS: return ChronoUnit.MICROS;
    case MILLISECONDS: return ChronoUnit.MILLIS;
    case SECONDS:      return ChronoUnit.SECONDS;
    case MINUTES:      return ChronoUnit.MINUTES;
    case HOURS:        return ChronoUnit.HOURS;
    case DAYS:         return ChronoUnit.DAYS;
    default: throw new AssertionError("Unknown unit: " + unit);
  }
}
 
源代码10 项目: find   文件: FindResult.java
@SuppressWarnings("TypeMayBeWeakened")
private ZonedDateTime parseRelativeTime(final ZonedDateTime timeNow, final int timeAmount, final String timeUnit) {
    TemporalUnit temporalUnit = ChronoUnit.SECONDS;
    switch (timeUnit) {
        case "minute":
        case "minutes":
            temporalUnit = ChronoUnit.MINUTES;
            break;

        case "hour":
        case "hours":
            temporalUnit = ChronoUnit.HOURS;
            break;

        case "day":
        case "days":
            temporalUnit = ChronoUnit.DAYS;
            break;

        case "month":
        case "months":
            temporalUnit = ChronoUnit.MONTHS;
            break;

        case "year":
        case "years":
            temporalUnit = ChronoUnit.YEARS;
            break;
    }

    return timeNow.plus(timeAmount, temporalUnit);
}
 
@Override
@Bulkhead(waitingTaskQueue = 5, value = 5)
@Asynchronous
@Retry(retryOn =
{ BulkheadException.class }, delay = 1, delayUnit = ChronoUnit.SECONDS, maxRetries = 10, maxDuration=999999)
public Future test(BackendTestDelegate action) throws InterruptedException {
    Utils.log("in business method of bean " + this.getClass().getName());
    return action.perform();
}
 
源代码12 项目: plugins   文件: TimeTrackingPlugin.java
@Schedule(period = 10, unit = ChronoUnit.SECONDS)
public void checkCompletion()
{
	boolean birdHouseDataChanged = birdHouseTracker.checkCompletion();

	if (birdHouseDataChanged)
	{
		panel.update();
	}
}
 
/**
 * serviceD specifies a Timeout longer than the default, at 2 
 * seconds.
 * 
 * @param timeToSleepInMillis  How long should the execution take in millis
 * @return null or exception is raised
 */
@Timeout(value = 2, unit = ChronoUnit.SECONDS)
public Connection serviceD(long timeToSleepInMillis) {
    try {
        Thread.sleep(timeToSleepInMillis);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
源代码14 项目: elexis-3-core   文件: DateWrapper.java
public DateWrapper(final int year, final Month month, final int dayOfMonth, final int hour, final int minute,
		final int second) {
	wrapped = ZonedDateTime
			.of(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second), ZoneId.systemDefault())
				.toInstant();
	accuracy = ChronoUnit.SECONDS;
}
 
源代码15 项目: swage   文件: RollingFileWriter.java
/**
 * Create a RollingFileWriter as specified
 *
 * @param directory Path where the log files will be created
 * @param name Base name to use for log files
 * @param zone Time zone of timestamps on rolling file names
 * @param minuteRotation If true, rotate logs every minute, if false rotate every hour
 */
RollingFileWriter(Path directory, String name, TimeZone zone, boolean minuteRotation)
{
    if (directory == null) {
        throw new IllegalArgumentException("Directory required");
    }
    if (name == null) {
        throw new IllegalArgumentException("File base name required");
    }
    if (zone == null) {
        throw new IllegalArgumentException("Time zone required");
    }

    this.directory = directory;
    this.baseName = name;
    this.timeZone = zone.toZoneId();

    final String formatPattern = (minuteRotation ? ".yyyy-MM-dd-HH-mm" : ".yyyy-MM-dd-HH");
    this.format = DateTimeFormatter.ofPattern(formatPattern);

    if (minuteRotation) {
        rollInterval = ChronoUnit.SECONDS;
    } else {
        rollInterval = ChronoUnit.HOURS;
    }

    // Set to roll immediately on first write, to ensure file is created
    this.rollAt = Instant.now().truncatedTo(rollInterval);
}
 
源代码16 项目: plugins   文件: AlchemyRoomTimer.java
AlchemyRoomTimer(final Plugin plugin)
{
	super(RESET_PERIOD, ChronoUnit.SECONDS, getResetImage(), plugin);
	this.setTooltip("Time until items swap");
}
 
源代码17 项目: L2jOrg   文件: TimeUtil.java
/**
 * Parses patterns like:
 * <ul>
 * <li>1min or 10mins</li>
 * <li>1day or 10days</li>
 * <li>1week or 4weeks</li>
 * <li>1month or 12months</li>
 * <li>1year or 5years</li>
 * </ul>
 * @param datePattern
 * @return {@link Duration} object converted by the date pattern specified.
 * @throws IllegalStateException when malformed pattern specified.
 */
public static Duration parseDuration(String datePattern)
{
	final int index = findIndexOfNonDigit(datePattern);
	if (index == -1)
	{
		throw new IllegalStateException("Incorrect time format given: " + datePattern);
	}
	try
	{
		final int val = Integer.parseInt(datePattern.substring(0, index));
		final String type = datePattern.substring(index);
		final ChronoUnit unit;
		switch (type.toLowerCase())
		{
			case "sec":
			case "secs":
			{
				unit = ChronoUnit.SECONDS;
				break;
			}
			case "min":
			case "mins":
			{
				unit = ChronoUnit.MINUTES;
				break;
			}
			case "hour":
			case "hours":
			{
				unit = ChronoUnit.HOURS;
				break;
			}
			case "day":
			case "days":
			{
				unit = ChronoUnit.DAYS;
				break;
			}
			case "week":
			case "weeks":
			{
				unit = ChronoUnit.WEEKS;
				break;
			}
			case "month":
			case "months":
			{
				unit = ChronoUnit.MONTHS;
				break;
			}
			case "year":
			case "years":
			{
				unit = ChronoUnit.YEARS;
				break;
			}
			default:
			{
				unit = ChronoUnit.valueOf(type);
				if (unit == null)
				{
					throw new IllegalStateException("Incorrect format: " + type + " !!");
				}
			}
		}
		return Duration.of(val, unit);
	}
	catch (Exception e)
	{
		throw new IllegalStateException("Incorrect time format given: " + datePattern + " val: " + datePattern.substring(0, index));
	}
}
 
@Retry(maxRetries = 5, delay = 2, delayUnit = ChronoUnit.SECONDS, jitter = 0)
public void serviceDelay() {
    throw new TestException();
}
 
源代码19 项目: Bytecoder   文件: Duration.java
/**
 * Returns a copy of this {@code Duration} truncated to the specified unit.
 * <p>
 * Truncating the duration returns a copy of the original with conceptual fields
 * smaller than the specified unit set to zero.
 * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
 * round down towards zero to the nearest minute, setting the seconds and
 * nanoseconds to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all
 * {@linkplain ChronoUnit#isTimeBased() time-based units on {@code ChronoUnit}}
 * and {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit the unit to truncate to, not null
 * @return a {@code Duration} based on this duration with the time truncated, not null
 * @throws DateTimeException if the unit is invalid for truncation
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @since 9
 */
public Duration truncatedTo(TemporalUnit unit) {
    Objects.requireNonNull(unit, "unit");
    if (unit == ChronoUnit.SECONDS && (seconds >= 0 || nanos == 0)) {
        return new Duration(seconds, 0);
    } else if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
    long result = (nod / dur) * dur;
    return plusNanos(result - nod);
}
 
源代码20 项目: java-timeseries   文件: TimePeriod.java
/**
 * Create and return a new TimePeriod representing one second.
 *
 * @return a new TimePeriod representing one second.
 */
public static TimePeriod oneSecond() {
  return new TimePeriod(ChronoUnit.SECONDS, 1);
}