diff --git a/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java b/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java index 32ab6b82ddf..c1568e46364 100644 --- a/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java +++ b/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -156,6 +156,7 @@ public final class ZoneOffsetTransition * @param offsetAfter the offset at and after the transition, not null */ ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) { + assert transition.getNano() == 0; this.epochSecond = transition.toEpochSecond(offsetBefore); this.transition = transition; this.offsetBefore = offsetBefore; @@ -250,7 +251,7 @@ public final class ZoneOffsetTransition * @return the transition instant, not null */ public Instant getInstant() { - return transition.toInstant(offsetBefore); + return Instant.ofEpochSecond(epochSecond); } /** @@ -403,13 +404,7 @@ public final class ZoneOffsetTransition */ @Override public int compareTo(ZoneOffsetTransition transition) { - if (epochSecond < transition.epochSecond) { - return -1; - } else if (epochSecond > transition.epochSecond) { - return 1; - } else { - return this.getInstant().compareTo(transition.getInstant()); - } + return Long.compare(epochSecond, transition.epochSecond); } //----------------------------------------------------------------------- @@ -429,7 +424,6 @@ public final class ZoneOffsetTransition if (other instanceof ZoneOffsetTransition) { ZoneOffsetTransition d = (ZoneOffsetTransition) other; return epochSecond == d.epochSecond && - transition.equals(d.transition) && offsetBefore.equals(d.offsetBefore) && offsetAfter.equals(d.offsetAfter); } return false; diff --git a/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java b/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java index db1a055a8b0..9c700d5ec70 100644 --- a/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java +++ b/jdk/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -167,6 +167,7 @@ public final class ZoneOffsetTransitionRule implements Serializable { * @return the rule, not null * @throws IllegalArgumentException if the day of month indicator is invalid * @throws IllegalArgumentException if the end of day flag is true when the time is not midnight + * @throws IllegalArgumentException if {@code time.getNano()} returns non-zero value */ public static ZoneOffsetTransitionRule of( Month month, @@ -190,6 +191,9 @@ public final class ZoneOffsetTransitionRule implements Serializable { if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) { throw new IllegalArgumentException("Time must be midnight when end of day flag is true"); } + if (time.getNano() != 0) { + throw new IllegalArgumentException("Time's nano-of-second must be zero"); + } return new ZoneOffsetTransitionRule(month, dayOfMonthIndicator, dayOfWeek, time, timeEndOfDay, timeDefnition, standardOffset, offsetBefore, offsetAfter); } @@ -220,6 +224,7 @@ public final class ZoneOffsetTransitionRule implements Serializable { ZoneOffset standardOffset, ZoneOffset offsetBefore, ZoneOffset offsetAfter) { + assert time.getNano() == 0; this.month = month; this.dom = (byte) dayOfMonthIndicator; this.dow = dayOfWeek; diff --git a/jdk/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java b/jdk/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java index 58e2ff56e7b..3c0c14c1ca6 100644 --- a/jdk/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java +++ b/jdk/test/java/time/tck/java/time/zone/TCKZoneOffsetTransitionRule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -156,6 +156,13 @@ public class TCKZoneOffsetTransitionRule extends AbstractTCKTest { OFFSET_0200, OFFSET_0200, OFFSET_0300); } + @Test(expectedExceptions=IllegalArgumentException.class) + public void test_factory_nonZeroTimeNanos() { + ZoneOffsetTransitionRule.of( + Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.of(1, 2, 3, 400_000_000), + false, TimeDefinition.WALL, OFFSET_0200, OFFSET_0200, OFFSET_0300); + } + //----------------------------------------------------------------------- // getters //-----------------------------------------------------------------------