< prev index next >

test/jdk/java/time/tck/java/time/zone/TCKZoneRules.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 924 
 925     public void test_Apia_jumpOverInternationalDateLine_M10_to_P14() {
 926         // transition occurred at 2011-12-30T00:00-10:00
 927         ZoneRules test = pacificApia();
 928         Instant instantBefore = LocalDate.of(2011, 12, 27).atStartOfDay(ZoneOffset.UTC).toInstant();
 929         ZoneOffsetTransition trans = test.nextTransition(instantBefore);
 930         assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2011, 12, 30, 0, 0));
 931         assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2011, 12, 31, 0, 0));
 932         assertEquals(trans.isGap(), true);
 933         assertEquals(trans.isOverlap(), false);
 934         assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-10)), false);
 935         assertEquals(trans.isValidOffset(ZoneOffset.ofHours(+14)), false);
 936         assertEquals(trans.getDuration(), Duration.ofHours(24));
 937         assertEquals(trans.getInstant(), LocalDateTime.of(2011, 12, 31, 0, 0).toInstant(ZoneOffset.ofHours(+14)));
 938 
 939         ZonedDateTime zdt = ZonedDateTime.of(2011, 12, 29, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
 940         assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(2011, 12, 31, 1, 0));
 941     }
 942 
 943     public void test_Apia_jumpForwardOverInternationalDateLine_P12_to_M12() {
 944         // transition occurred at 1879-07-04T00:00+12:33:04
 945         ZoneRules test = pacificApia();
 946         Instant instantBefore = LocalDate.of(1879, 7, 2).atStartOfDay(ZoneOffset.UTC).toInstant();
 947         ZoneOffsetTransition trans = test.nextTransition(instantBefore);
 948         assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(1879, 7, 5, 0, 0));
 949         assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(1879, 7, 4, 0, 0));
 950         assertEquals(trans.isGap(), false);
 951         assertEquals(trans.isOverlap(), true);
 952         assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(+12, 33, 4)), true);
 953         assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)), true);
 954         assertEquals(trans.getDuration(), Duration.ofHours(-24));
 955         assertEquals(trans.getInstant(), LocalDateTime.of(1879, 7, 4, 0, 0).toInstant(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)));
 956 
 957         ZonedDateTime zdt = ZonedDateTime.of(1879, 7, 4, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
 958         assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(1879, 7, 4, 1, 0, 0));
 959     }
 960 
 961     //-------------------------------------------------------------------------
 962     @Test(expectedExceptions=UnsupportedOperationException.class)
 963     public void test_getTransitions_immutable() {
 964         ZoneRules test = europeParis();
 965         test.getTransitions().clear();
 966     }
 967 
 968     @Test(expectedExceptions=UnsupportedOperationException.class)
 969     public void test_getTransitionRules_immutable() {
 970         ZoneRules test = europeParis();
 971         test.getTransitionRules().clear();
 972     }
 973 
 974     //-----------------------------------------------------------------------
 975     // of()
 976     //-----------------------------------------------------------------------
 977     public void test_of(){
 978         //used for standard offset


   1 /*
   2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 924 
 925     public void test_Apia_jumpOverInternationalDateLine_M10_to_P14() {
 926         // transition occurred at 2011-12-30T00:00-10:00
 927         ZoneRules test = pacificApia();
 928         Instant instantBefore = LocalDate.of(2011, 12, 27).atStartOfDay(ZoneOffset.UTC).toInstant();
 929         ZoneOffsetTransition trans = test.nextTransition(instantBefore);
 930         assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2011, 12, 30, 0, 0));
 931         assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2011, 12, 31, 0, 0));
 932         assertEquals(trans.isGap(), true);
 933         assertEquals(trans.isOverlap(), false);
 934         assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-10)), false);
 935         assertEquals(trans.isValidOffset(ZoneOffset.ofHours(+14)), false);
 936         assertEquals(trans.getDuration(), Duration.ofHours(24));
 937         assertEquals(trans.getInstant(), LocalDateTime.of(2011, 12, 31, 0, 0).toInstant(ZoneOffset.ofHours(+14)));
 938 
 939         ZonedDateTime zdt = ZonedDateTime.of(2011, 12, 29, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
 940         assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(2011, 12, 31, 1, 0));
 941     }
 942 
 943     public void test_Apia_jumpForwardOverInternationalDateLine_P12_to_M12() {
 944         // transition occurred at 1892-07-04T00:00+12:33:04
 945         ZoneRules test = pacificApia();
 946         Instant instantBefore = LocalDate.of(1892, 7, 2).atStartOfDay(ZoneOffset.UTC).toInstant();
 947         ZoneOffsetTransition trans = test.nextTransition(instantBefore);
 948         assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(1892, 7, 5, 0, 0));
 949         assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(1892, 7, 4, 0, 0));
 950         assertEquals(trans.isGap(), false);
 951         assertEquals(trans.isOverlap(), true);
 952         assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(+12, 33, 4)), true);
 953         assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)), true);
 954         assertEquals(trans.getDuration(), Duration.ofHours(-24));
 955         assertEquals(trans.getInstant(), LocalDateTime.of(1892, 7, 4, 0, 0).toInstant(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)));
 956 
 957         ZonedDateTime zdt = ZonedDateTime.of(1892, 7, 4, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
 958         assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(1892, 7, 4, 1, 0, 0));
 959     }
 960 
 961     //-------------------------------------------------------------------------
 962     @Test(expectedExceptions=UnsupportedOperationException.class)
 963     public void test_getTransitions_immutable() {
 964         ZoneRules test = europeParis();
 965         test.getTransitions().clear();
 966     }
 967 
 968     @Test(expectedExceptions=UnsupportedOperationException.class)
 969     public void test_getTransitionRules_immutable() {
 970         ZoneRules test = europeParis();
 971         test.getTransitionRules().clear();
 972     }
 973 
 974     //-----------------------------------------------------------------------
 975     // of()
 976     //-----------------------------------------------------------------------
 977     public void test_of(){
 978         //used for standard offset


< prev index next >