diff --git a/classpath/java/util/concurrent/TimeUnit.java b/classpath/java/util/concurrent/TimeUnit.java index fa378a4885..3fd9385cfe 100644 --- a/classpath/java/util/concurrent/TimeUnit.java +++ b/classpath/java/util/concurrent/TimeUnit.java @@ -34,7 +34,7 @@ public enum TimeUnit { @Override public long toMinutes(long d) { - return d / NANOSECONDS_PER_MINUET; + return d / NANOSECONDS_PER_MINUTE; } @Override @@ -80,7 +80,7 @@ public enum TimeUnit { @Override public long toMinutes(long d) { - return d / MICROSECONDS_PER_MINUET; + return d / MICROSECONDS_PER_MINUTE; } @Override @@ -126,7 +126,7 @@ public enum TimeUnit { @Override public long toMinutes(long d) { - return d / MILLISECONDS_PER_MINUET; + return d / MILLISECONDS_PER_MINUTE; } @Override @@ -172,7 +172,7 @@ public enum TimeUnit { @Override public long toMinutes(long d) { - return d / SECONDS_PER_MINUET; + return d / SECONDS_PER_MINUTE; } @Override @@ -198,22 +198,22 @@ public enum TimeUnit { MINUTES { @Override public long toNanos(long d) { - return scale(d, NANOSECONDS_PER_MINUET); + return scale(d, NANOSECONDS_PER_MINUTE); } @Override public long toMicros(long d) { - return scale(d, MICROSECONDS_PER_MINUET); + return scale(d, MICROSECONDS_PER_MINUTE); } @Override public long toMillis(long d) { - return scale(d, MILLISECONDS_PER_MINUET); + return scale(d, MILLISECONDS_PER_MINUTE); } @Override public long toSeconds(long d) { - return scale(d, SECONDS_PER_MINUET); + return scale(d, SECONDS_PER_MINUTE); } @Override @@ -337,26 +337,26 @@ public enum TimeUnit { private static final long NANOSECONDS_PER_MICROSECOND = 1000L; private static final long MICROSECONDS_PER_MILLISECOND = 1000L; private static final long MILLISECONDS_PER_SECOND = 1000L; - private static final long SECONDS_PER_MINUET = 60; + private static final long SECONDS_PER_MINUTE = 60; private static final long MINUETS_PER_HOUR = 60; private static final long HOURS_PER_DAY = 24; private static final long NANOSECONDS_PER_MILLISECOND = NANOSECONDS_PER_MICROSECOND * MICROSECONDS_PER_MILLISECOND; private static final long NANOSECONDS_PER_SECOND = NANOSECONDS_PER_MILLISECOND * MILLISECONDS_PER_SECOND; - private static final long NANOSECONDS_PER_MINUET = NANOSECONDS_PER_SECOND * SECONDS_PER_MINUET; - private static final long NANOSECONDS_PER_HOUR = NANOSECONDS_PER_MINUET * MINUETS_PER_HOUR; + private static final long NANOSECONDS_PER_MINUTE = NANOSECONDS_PER_SECOND * SECONDS_PER_MINUTE; + private static final long NANOSECONDS_PER_HOUR = NANOSECONDS_PER_MINUTE * MINUETS_PER_HOUR; private static final long NANOSECONDS_PER_DAY = NANOSECONDS_PER_HOUR * HOURS_PER_DAY; private static final long MICROSECONDS_PER_SECOND = MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_SECOND; - private static final long MICROSECONDS_PER_MINUET = MICROSECONDS_PER_SECOND * SECONDS_PER_MINUET; - private static final long MICROSECONDS_PER_HOUR = MICROSECONDS_PER_MINUET * MINUETS_PER_HOUR; + private static final long MICROSECONDS_PER_MINUTE = MICROSECONDS_PER_SECOND * SECONDS_PER_MINUTE; + private static final long MICROSECONDS_PER_HOUR = MICROSECONDS_PER_MINUTE * MINUETS_PER_HOUR; private static final long MICROSECONDS_PER_DAY = MICROSECONDS_PER_HOUR * HOURS_PER_DAY; - private static final long MILLISECONDS_PER_MINUET = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUET; - private static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUET * MINUETS_PER_HOUR; + private static final long MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE; + private static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUETS_PER_HOUR; private static final long MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * HOURS_PER_DAY; - private static final long SECONDS_PER_HOUR = SECONDS_PER_MINUET * MINUETS_PER_HOUR; + private static final long SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUETS_PER_HOUR; private static final long SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; private static final long MINUETS_PER_DAY = MINUETS_PER_HOUR * HOURS_PER_DAY; diff --git a/test/TimeUnitConversions.java b/test/TimeUnitConversions.java new file mode 100644 index 0000000000..b681f60076 --- /dev/null +++ b/test/TimeUnitConversions.java @@ -0,0 +1,117 @@ +import java.util.concurrent.TimeUnit; + +public class TimeUnitConversions { + private static void expect(long v1, long v2) { + if (v1 != v2) { + throw new RuntimeException(v1 + " != " + v2); + } + } + + private static void toNanoConversionTest() { + long expectedValue = 1; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS), expectedValue); + expectedValue *= 1000; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.MICROSECONDS), expectedValue); + expectedValue *= 1000; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.MILLISECONDS), expectedValue); + expectedValue *= 1000; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS), expectedValue); + expectedValue *= 60; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.MINUTES), expectedValue); + expectedValue *= 60; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.HOURS), expectedValue); + expectedValue *= 24; + expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.DAYS), expectedValue); + } + + private static void toMicroConversionTest() { + long expectedValue = 1; + expect(TimeUnit.MICROSECONDS.convert(1000, TimeUnit.NANOSECONDS), expectedValue); + expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.MICROSECONDS), expectedValue); + expectedValue *= 1000; + expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.MILLISECONDS), expectedValue); + expectedValue *= 1000; + expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.SECONDS), expectedValue); + expectedValue *= 60; + expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.MINUTES), expectedValue); + expectedValue *= 60; + expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.HOURS), expectedValue); + expectedValue *= 24; + expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.DAYS), expectedValue); + } + + private static void toMilliConversionTest() { + long expectedValue = 1; + expect(TimeUnit.MILLISECONDS.convert(1000L * 1000, TimeUnit.NANOSECONDS), expectedValue); + expect(TimeUnit.MILLISECONDS.convert(1000, TimeUnit.MICROSECONDS), expectedValue); + expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.MILLISECONDS), expectedValue); + expectedValue *= 1000; + expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS), expectedValue); + expectedValue *= 60; + expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES), expectedValue); + expectedValue *= 60; + expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS), expectedValue); + expectedValue *= 24; + expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS), expectedValue); + } + + private static void toSecondConversionTest() { + long expectedValue = 1; + expect(TimeUnit.SECONDS.convert(1000L * 1000 * 1000, TimeUnit.NANOSECONDS), expectedValue); + expect(TimeUnit.SECONDS.convert(1000L * 1000, TimeUnit.MICROSECONDS), expectedValue); + expect(TimeUnit.SECONDS.convert(1000, TimeUnit.MILLISECONDS), expectedValue); + expect(TimeUnit.SECONDS.convert(1, TimeUnit.SECONDS), expectedValue); + expectedValue *= 60; + expect(TimeUnit.SECONDS.convert(1, TimeUnit.MINUTES), expectedValue); + expectedValue *= 60; + expect(TimeUnit.SECONDS.convert(1, TimeUnit.HOURS), expectedValue); + expectedValue *= 24; + expect(TimeUnit.SECONDS.convert(1, TimeUnit.DAYS), expectedValue); + } + + private static void toMinuteConversionTest() { + long expectedValue = 1; + expect(TimeUnit.MINUTES.convert(1000L * 1000 * 1000 * 60, TimeUnit.NANOSECONDS), expectedValue); + expect(TimeUnit.MINUTES.convert(1000L * 1000 * 60, TimeUnit.MICROSECONDS), expectedValue); + expect(TimeUnit.MINUTES.convert(1000L * 60, TimeUnit.MILLISECONDS), expectedValue); + expect(TimeUnit.MINUTES.convert(60, TimeUnit.SECONDS), expectedValue); + expect(TimeUnit.MINUTES.convert(1, TimeUnit.MINUTES), expectedValue); + expectedValue *= 60; + expect(TimeUnit.MINUTES.convert(1, TimeUnit.HOURS), expectedValue); + expectedValue *= 24; + expect(TimeUnit.MINUTES.convert(1, TimeUnit.DAYS), expectedValue); + } + + private static void toHourConversionTest() { + long expectedValue = 1; + expect(TimeUnit.HOURS.convert(1000L * 1000 * 1000 * 60 * 60, TimeUnit.NANOSECONDS), expectedValue); + expect(TimeUnit.HOURS.convert(1000L * 1000 * 60 * 60, TimeUnit.MICROSECONDS), expectedValue); + expect(TimeUnit.HOURS.convert(1000L * 60 * 60, TimeUnit.MILLISECONDS), expectedValue); + expect(TimeUnit.HOURS.convert(60L * 60, TimeUnit.SECONDS), expectedValue); + expect(TimeUnit.HOURS.convert(60, TimeUnit.MINUTES), expectedValue); + expect(TimeUnit.HOURS.convert(1, TimeUnit.HOURS), expectedValue); + expectedValue *= 24; + expect(TimeUnit.HOURS.convert(1, TimeUnit.DAYS), expectedValue); + } + + private static void toDayConversionTest() { + long expectedValue = 1; + expect(TimeUnit.DAYS.convert(1000L * 1000 * 1000 * 60 * 60 * 24, TimeUnit.NANOSECONDS), expectedValue); + expect(TimeUnit.DAYS.convert(1000L * 1000 * 60 * 60 * 24, TimeUnit.MICROSECONDS), expectedValue); + expect(TimeUnit.DAYS.convert(1000L * 60 * 60 * 24, TimeUnit.MILLISECONDS), expectedValue); + expect(TimeUnit.DAYS.convert(60L * 60 * 24, TimeUnit.SECONDS), expectedValue); + expect(TimeUnit.DAYS.convert(60L * 24, TimeUnit.MINUTES), expectedValue); + expect(TimeUnit.DAYS.convert(24, TimeUnit.HOURS), expectedValue); + expect(TimeUnit.DAYS.convert(1, TimeUnit.DAYS), expectedValue); + } + + public static void main(String[] args) { + toNanoConversionTest(); + toMicroConversionTest(); + toMilliConversionTest(); + toSecondConversionTest(); + toMinuteConversionTest(); + toHourConversionTest(); + toDayConversionTest(); + } +}