java.time.Duration#getNano ( )源码实例Demo

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

源代码1 项目: phoebus   文件: GaussianWavePV.java
@Override
public double[] compute()
{
    final double[] value = new double[shape.length];

    final Duration dist = Duration.between(start, Instant.now());
    final double t = dist.getSeconds() + dist.getNano()*1e-9;
    final double periods = period > 0 ? t / period : 0.0;
    final int i0 = (int) ((periods - (int)periods) * value.length);

    // value[..] = shape[i0 to end] concatenated with shape[0 to i0-1]
    final int rest = value.length - i0;
    System.arraycopy(shape, i0, value, 0, rest);
    System.arraycopy(shape, 0, value, rest, i0);
    return value;
}
 
源代码2 项目: r2dbc-mysql   文件: DurationCodec.java
private void encodeTo(ParameterWriter writer) {
    boolean isNegative = this.value.isNegative();
    Duration abs = this.value.abs();
    long totalSeconds = abs.getSeconds();
    int hours = (int) (totalSeconds / SECONDS_OF_HOUR);
    int minutes = (int) ((totalSeconds % SECONDS_OF_HOUR) / SECONDS_OF_MINUTE);
    int seconds = (int) (totalSeconds % SECONDS_OF_MINUTE);
    int micros = abs.getNano() / NANOS_OF_MICRO;

    if (hours < 0 || minutes < 0 || seconds < 0 || micros < 0) {
        throw new IllegalStateException(String.format("Too large duration %s, abs value overflowing to %02d:%02d:%02d.%06d", value, hours, minutes, seconds, micros));
    }

    encodeTime(writer, isNegative, hours, minutes, seconds, micros);
}
 
源代码3 项目: r2dbc-mysql   文件: DurationCodec.java
private void encodeTo(ParameterWriter writer) {
    boolean isNegative = this.value.isNegative();
    Duration abs = this.value.abs();
    long totalSeconds = abs.getSeconds();
    int hours = (int) (totalSeconds / SECONDS_OF_HOUR);
    int minutes = (int) ((totalSeconds % SECONDS_OF_HOUR) / SECONDS_OF_MINUTE);
    int seconds = (int) (totalSeconds % SECONDS_OF_MINUTE);
    int micros = abs.getNano() / NANOS_OF_MICRO;

    if (hours < 0 || minutes < 0 || seconds < 0 || micros < 0) {
        throw new IllegalStateException(String.format("Too large duration %s, abs value overflowing to %02d:%02d:%02d.%06d", value, hours, minutes, seconds, micros));
    }

    encodeTime(writer, isNegative, hours, minutes, seconds, micros);
}
 
源代码4 项目: java-trader   文件: ExchangeableTradingTimes.java
/**
 * 返回开市以来的时间(毫秒)
 */
public int getTradingTime(LocalDateTime marketTime) {
    if ( marketTime.isBefore(marketTimes[0]) || compareTimeNoNanos(marketTime,marketTimes[marketTimes.length-1])>0) {
        return -1;
    }
    int result = 0;
    for(int i=0;i<marketTimes.length;i+=2) {
        LocalDateTime marketTimeStageBegin = marketTimes[i];
        LocalDateTime marketTimeStageEnd = marketTimes[i+1];
        if ( compareTimeNoNanos(marketTime, marketTimeStageBegin)<=0 ) {
            break;
        }
        Duration d = null;
        int compareResult = compareTimeNoNanos(marketTime, marketTimeStageEnd);
        if ( compareResult<=0 ) {
            d = DateUtil.between(marketTimeStageBegin, marketTime);
        }else {
            d = DateUtil.between(marketTimeStageBegin, marketTimeStageEnd);
        }
        long millis = d.getSeconds()*1000+d.getNano()/1000000;
        result += millis;
        if ( compareResult<=0 ) {
            break;
        }
    }
    return result;
}
 
源代码5 项目: vertexium   文件: CypherDuration.java
public CypherDuration(Period period, Duration duration) {
    this.negative = (period.isNegative() || duration.isNegative());

    if (period.isNegative()) {
        period = period.negated();
    }
    if (duration.isNegative()) {
        duration = duration.negated();
    }

    this.nanos = ((duration.getSeconds() * NANOS_IN_SECOND) + duration.getNano()) % NANOS_IN_DAY;
    this.period = period.minusDays(this.nanos > 0 ? 1 : 0);
}
 
源代码6 项目: phoebus   文件: TimeAxis.java
/** Scale Duration by floating point number
 *  @param start Start of a duration
 *  @param end End of a duration
 *  @param factor Scaling factor
 *  @return Scaled Duration
 */
final private static Duration scaledDuration(final Instant start, final Instant end, final double factor)
{
    final Duration duration = Duration.between(start, end);
    final double scaled = (duration.getSeconds() + 1e-9*duration.getNano()) * factor;
    final int seconds = (int)scaled;
    final int nano = (int) ((scaled - seconds) * 1e9);
    return Duration.ofSeconds(seconds, nano);
}
 
源代码7 项目: datakernel   文件: StringFormatUtils.java
public static String formatDuration(Duration value) {
	if (value.isZero()) {
		return "0 seconds";
	}
	String result = "";
	long days, hours, minutes, seconds, nano, milli;
	days = value.toDays();
	if (days != 0) {
		result += days + " days ";
	}
	hours = value.toHours() - days * 24;
	if (hours != 0) {
		result += hours + " hours ";
	}
	minutes = value.toMinutes() - days * 1440 - hours * 60;
	if (minutes != 0) {
		result += minutes + " minutes ";
	}
	seconds = value.getSeconds() - days * 86400 - hours * 3600 - minutes * 60;
	if (seconds != 0) {
		result += seconds + " seconds ";
	}
	nano = value.getNano();
	milli = (nano - nano % 1000000) / 1000000;
	if (milli != 0) {
		result += milli + " millis ";
	}
	nano = nano % 1000000;
	if (nano != 0) {
		result += nano + " nanos ";
	}
	return result.trim();
}
 
源代码8 项目: diirt   文件: TimeDuration.java
/**
 * Returns the number of times the given duration is present in this duration.
 *
 * @param dividendDuration the duration to be devided
 * @param divisorDuration the divisor
 * @return the result of the division
 */
public static int dividedBy(Duration dividendDuration, Duration divisorDuration) {
    // (a + b)/(c + d) = 1 / ((c + d) / a) + 1 / ((c + d) / b)
    // XXX This will not have the precision it should
    double thisDuration = (double) dividendDuration.getSeconds() * (double) NANOSEC_IN_SEC + (double) dividendDuration.getNano();
    double otherDuration = (double) divisorDuration.getSeconds() * (double) NANOSEC_IN_SEC + (double) divisorDuration.getNano();
    return (int) (thisDuration / otherDuration);
}
 
源代码9 项目: phoebus   文件: TimeDuration.java
/**
 * Returns the number of times the given duration is present in this duration.
 *
 * @param dividendDuration the duration to be devided
 * @param divisorDuration the divisor
 * @return the result of the division
 */
public static int dividedBy(Duration dividendDuration, Duration divisorDuration) {
    // (a + b)/(c + d) = 1 / ((c + d) / a) + 1 / ((c + d) / b)
    // XXX This will not have the precision it should
    double thisDuration = (double) dividendDuration.getSeconds() * (double) NANOSEC_IN_SEC + (double) dividendDuration.getNano();
    double otherDuration = (double) divisorDuration.getSeconds() * (double) NANOSEC_IN_SEC + (double) divisorDuration.getNano();
    return (int) (thisDuration / otherDuration);
}
 
源代码10 项目: visualvm   文件: DurationFormatter.java
public static StringBuffer format(Duration d, StringBuffer b) {
    if (ValuesChecker.isMaxDuration(d)) return b.append("∞"); // NOI18N
        
    long s = d.getSeconds();
    if (s > 0) formatSeconds(s, b);

    int n = d.getNano();
    return b.append(DURATION_MS_FORMAT.format(n / 1000000f)).append(" ms"); // NOI18N
}
 
源代码11 项目: tutorials   文件: UUIDGenerator.java
private static long get64MostSignificantBitsForVersion1() {
    LocalDateTime start = LocalDateTime.of(1582, 10, 15, 0, 0, 0);
    Duration duration = Duration.between(start, LocalDateTime.now());
    long seconds = duration.getSeconds();
    long nanos = duration.getNano();
    long timeForUuidIn100Nanos = seconds * 10000000 + nanos * 100;
    long least12SignificatBitOfTime = (timeForUuidIn100Nanos & 0x000000000000FFFFL) >> 4;
    long version = 1 << 12;
    return (timeForUuidIn100Nanos & 0xFFFFFFFFFFFF0000L) + version + least12SignificatBitOfTime;
}
 
源代码12 项目: java-timeseries   文件: TimePeriod.java
/**
 * The total amount of time in this time period measured in seconds, the base SI unit of time.
 *
 * @return the total amount of time in this time period measured in seconds.
 */
public double totalSeconds() {
  final double nanoSecondsPerSecond = 1E9;
  Duration thisDuration = this.timeUnit.getDuration();
  double seconds = thisDuration.getSeconds() * this.length;
  double nanos = thisDuration.getNano();
  nanos = (nanos * this.length);
  nanos = (nanos / nanoSecondsPerSecond);
  return seconds + nanos;
}
 
源代码13 项目: hesperides   文件: MongoHealthCheckRequester.java
static MongoHealthCheckResult performHealthCheck(MongoTemplate mongoTemplate) {
    Instant start = Instant.now();
    Document result = mongoTemplate.executeCommand("{ buildInfo: 1 }");
    Instant end = Instant.now();
    Duration duration = Duration.between(start, end);
    return new MongoHealthCheckResult(
            result.getString("version"),
            duration.getSeconds() * 1000 + duration.getNano() / 1000000.0);
}
 
源代码14 项目: alibaba-rsocket-broker   文件: DurationHandle.java
public DurationHandle(Duration o) {
    this.seconds = o.getSeconds();
    this.nanos = o.getNano();
}
 
源代码15 项目: joyrpc   文件: DurationHandle.java
@Override
public void wrap(final Duration duration) {
    this.seconds = duration.getSeconds();
    this.nano = duration.getNano();
}
 
源代码16 项目: IGUANA   文件: TimeUtils.java
public static double durationInMilliseconds(Instant start, Instant end) {
	Duration duration = Duration.between(start, end);
	return ((long)duration.getNano() + duration.getSeconds() * 1000000000 /*ns*/) / 1000000d /*ms*/;
}
 
源代码17 项目: ProjectAres   文件: TimeUtils.java
public static Duration multiply(Duration duration, double factor) {
    final long nanosPerSecond = ChronoUnit.SECONDS.getDuration().toNanos();
    final long nanos = (long) (duration.getNano() * factor);
    return Duration.ofSeconds(Math.addExact((long) (duration.getSeconds() * factor), Math.floorDiv(nanos, nanosPerSecond)),
                              Math.floorMod(nanos, nanosPerSecond));
}
 
源代码18 项目: visualvm   文件: ValuesConverter.java
public static long durationToMicros(Duration duration) {
    long micros = duration.getSeconds() * 1000000;
    micros += duration.getNano() / 1000;
    return micros;
}
 
源代码19 项目: diirt   文件: TimeDuration.java
/**
 *  Convert the entire duration to seconds represented in a double
 *
 * @param duration the duration to be converted
 * @return the duration in seconds
 */
public static double toSecondsDouble(Duration duration){
    return duration.getSeconds() + (duration.getNano() / (double) NANOSEC_IN_SEC);
}
 
源代码20 项目: visualvm   文件: ValuesChecker.java
public static boolean isMaxDuration(Duration val) { return 9223372036854775l == val.getSeconds() && 807000000 == val.getNano(); }