8285519: Change usages of TimeUnit.convert to TimeUnit.toXXX
Reviewed-by: rriggs
This commit is contained in:
parent
e7d52e25a2
commit
e833c1d179
@ -97,8 +97,8 @@ class ZipUtils {
|
||||
if (month > 0 && month < 13 && day > 0 && hour < 24 && minute < 60 && second < 60) {
|
||||
try {
|
||||
LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
|
||||
return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
|
||||
ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
|
||||
return TimeUnit.SECONDS.toMillis(ldt.toEpochSecond(
|
||||
ZoneId.systemDefault().getRules().getOffset(ldt)));
|
||||
} catch (DateTimeException dte) {
|
||||
// ignore
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
||||
private static long tryLock(ReentrantLock lock, long timeout, TimeUnit unit) {
|
||||
assert timeout > 0;
|
||||
boolean interrupted = false;
|
||||
long nanos = NANOSECONDS.convert(timeout, unit);
|
||||
long nanos = unit.toNanos(timeout);
|
||||
long remainingNanos = nanos;
|
||||
long startNanos = System.nanoTime();
|
||||
boolean acquired = false;
|
||||
|
@ -25,9 +25,11 @@
|
||||
|
||||
package jdk.jfr.internal;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
import static java.util.concurrent.TimeUnit.HOURS;
|
||||
import static java.util.concurrent.TimeUnit.MICROSECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
@ -311,22 +313,22 @@ public final class Utils {
|
||||
return Long.parseLong(s.substring(0, s.length() - 2).trim());
|
||||
}
|
||||
if (s.endsWith("us")) {
|
||||
return NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 2).trim()), MICROSECONDS);
|
||||
return MICROSECONDS.toNanos(Long.parseLong(s.substring(0, s.length() - 2).trim()));
|
||||
}
|
||||
if (s.endsWith("ms")) {
|
||||
return NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 2).trim()), MILLISECONDS);
|
||||
return MILLISECONDS.toNanos(Long.parseLong(s.substring(0, s.length() - 2).trim()));
|
||||
}
|
||||
if (s.endsWith("s")) {
|
||||
return NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), SECONDS);
|
||||
return SECONDS.toNanos(Long.parseLong(s.substring(0, s.length() - 1).trim()));
|
||||
}
|
||||
if (s.endsWith("m")) {
|
||||
return 60 * NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), SECONDS);
|
||||
return MINUTES.toNanos(Long.parseLong(s.substring(0, s.length() - 1).trim()));
|
||||
}
|
||||
if (s.endsWith("h")) {
|
||||
return 60 * 60 * NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), SECONDS);
|
||||
return HOURS.toNanos(Long.parseLong(s.substring(0, s.length() - 1).trim()));
|
||||
}
|
||||
if (s.endsWith("d")) {
|
||||
return 24 * 60 * 60 * NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), SECONDS);
|
||||
return DAYS.toNanos(Long.parseLong(s.substring(0, s.length() - 1).trim()));
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -214,8 +214,8 @@ class ZipUtils {
|
||||
if (month > 0 && month < 13 && day > 0 && hour < 24 && minute < 60 && second < 60) {
|
||||
try {
|
||||
LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
|
||||
return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
|
||||
ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
|
||||
return TimeUnit.SECONDS.toMillis(ldt.toEpochSecond(
|
||||
ZoneId.systemDefault().getRules().getOffset(ldt)));
|
||||
} catch (DateTimeException dte) {
|
||||
// ignore
|
||||
}
|
||||
@ -253,22 +253,22 @@ class ZipUtils {
|
||||
|
||||
// used to adjust values between Windows and java epoch
|
||||
private static final long WINDOWS_EPOCH_IN_MICROSECONDS = -11644473600000000L;
|
||||
public static final long winToJavaTime(long wtime) {
|
||||
return TimeUnit.MILLISECONDS.convert(
|
||||
wtime / 10 + WINDOWS_EPOCH_IN_MICROSECONDS, TimeUnit.MICROSECONDS);
|
||||
public static long winToJavaTime(long wtime) {
|
||||
return TimeUnit.MICROSECONDS.toMillis(
|
||||
wtime / 10 + WINDOWS_EPOCH_IN_MICROSECONDS);
|
||||
}
|
||||
|
||||
public static final long javaToWinTime(long time) {
|
||||
return (TimeUnit.MICROSECONDS.convert(time, TimeUnit.MILLISECONDS)
|
||||
public static long javaToWinTime(long time) {
|
||||
return (TimeUnit.MILLISECONDS.toMicros(time)
|
||||
- WINDOWS_EPOCH_IN_MICROSECONDS) * 10;
|
||||
}
|
||||
|
||||
public static final long unixToJavaTime(long utime) {
|
||||
return TimeUnit.MILLISECONDS.convert(utime, TimeUnit.SECONDS);
|
||||
public static long unixToJavaTime(long utime) {
|
||||
return TimeUnit.SECONDS.toMillis(utime);
|
||||
}
|
||||
|
||||
public static final long javaToUnixTime(long time) {
|
||||
return TimeUnit.SECONDS.convert(time, TimeUnit.MILLISECONDS);
|
||||
public static long javaToUnixTime(long time) {
|
||||
return TimeUnit.MILLISECONDS.toSeconds(time);
|
||||
}
|
||||
|
||||
private static final String regexMetaChars = ".^$+{[]|()";
|
||||
|
Loading…
x
Reference in New Issue
Block a user