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  */
  23 
  24 /*
  25  * This file is available under and governed by the GNU General Public
  26  * License version 2 only, as published by the Free Software Foundation.
  27  * However, the following notice accompanied the original version of this
  28  * file:
  29  *
  30  * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
  31  *
  32  * All rights reserved.
  33  *
  34  * Redistribution and use in source and binary forms, with or without
  35  * modification, are permitted provided that the following conditions are met:
  36  *
  37  *  * Redistributions of source code must retain the above copyright notice,
  38  *    this list of conditions and the following disclaimer.
  39  *
  40  *  * Redistributions in binary form must reproduce the above copyright notice,
  41  *    this list of conditions and the following disclaimer in the documentation
  42  *    and/or other materials provided with the distribution.
  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import java.time.*;
  63 
  64 import static java.time.Month.JANUARY;
  65 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
  66 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
  67 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
  68 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
  69 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  70 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  71 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  72 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  73 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  74 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  75 import static java.time.temporal.ChronoField.EPOCH_DAY;
  76 import static java.time.temporal.ChronoField.EPOCH_MONTH;
  77 import static java.time.temporal.ChronoField.ERA;
  78 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  79 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  80 import static java.time.temporal.ChronoField.INSTANT_SECONDS;
  81 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  82 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  83 import static java.time.temporal.ChronoField.MILLI_OF_DAY;
  84 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  85 import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
  86 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
  87 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  88 import static java.time.temporal.ChronoField.NANO_OF_DAY;
  89 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  90 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
  91 import static java.time.temporal.ChronoField.SECOND_OF_DAY;
  92 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  93 import static java.time.temporal.ChronoField.YEAR;
  94 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  95 import static java.time.temporal.ChronoUnit.DAYS;
  96 import static java.time.temporal.ChronoUnit.HOURS;
  97 import static java.time.temporal.ChronoUnit.MINUTES;
  98 import static java.time.temporal.ChronoUnit.NANOS;
  99 import static java.time.temporal.ChronoUnit.SECONDS;
 100 import static org.testng.Assert.assertEquals;
 101 import static org.testng.Assert.assertTrue;
 102 
 103 import java.io.ByteArrayOutputStream;
 104 import java.io.DataOutputStream;
 105 import java.io.IOException;
 106 import java.util.ArrayList;
 107 import java.util.Arrays;
 108 import java.util.List;
 109 
 110 import java.time.temporal.ChronoField;
 111 import java.time.temporal.ChronoUnit;
 112 import java.time.temporal.Queries;
 113 import java.time.temporal.TemporalAmount;
 114 import java.time.temporal.TemporalAmount;
 115 import java.time.temporal.TemporalAdjuster;
 116 import java.time.temporal.TemporalAccessor;
 117 import java.time.temporal.TemporalQuery;
 118 import java.time.temporal.TemporalField;
 119 import java.time.chrono.IsoChronology;
 120 import java.time.temporal.JulianFields;
 121 import test.java.time.temporal.MockFieldNoValue;
 122 
 123 import java.time.format.DateTimeFormatter;
 124 import java.time.format.DateTimeFormatter;
 125 import java.time.format.DateTimeParseException;
 126 import java.time.OffsetDateTime;
 127 import java.time.Year;
 128 
 129 import org.testng.annotations.BeforeMethod;
 130 import org.testng.annotations.DataProvider;
 131 import org.testng.annotations.Test;
 132 
 133 /**
 134  * Test ZonedDateTime.
 135  */
 136 @Test
 137 public class TCKZonedDateTime extends AbstractDateTimeTest {
 138 
 139     private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1);
 140     private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2);
 141     private static final ZoneOffset OFFSET_0130 = ZoneOffset.of("+01:30");
 142     private static final ZoneOffset OFFSET_MAX = ZoneOffset.MAX;
 143     private static final ZoneOffset OFFSET_MIN = ZoneOffset.MIN;
 144 
 145     private static final ZoneId ZONE_0100 = OFFSET_0100;
 146     private static final ZoneId ZONE_0200 = OFFSET_0200;
 147     private static final ZoneId ZONE_M0100 = ZoneOffset.ofHours(-1);
 148     private static final ZoneId ZONE_LONDON = ZoneId.of("Europe/London");
 149     private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
 150     private LocalDateTime TEST_PARIS_GAP_2008_03_30_02_30;
 151     private LocalDateTime TEST_PARIS_OVERLAP_2008_10_26_02_30;
 152     private LocalDateTime TEST_LOCAL_2008_06_30_11_30_59_500;
 153     private ZonedDateTime TEST_DATE_TIME;
 154     private ZonedDateTime TEST_DATE_TIME_PARIS;
 155 
 156     @BeforeMethod(groups={"tck","implementation"})
 157     public void setUp() {
 158         TEST_LOCAL_2008_06_30_11_30_59_500 = LocalDateTime.of(2008, 6, 30, 11, 30, 59, 500);
 159         TEST_DATE_TIME = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
 160         TEST_DATE_TIME_PARIS = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
 161         TEST_PARIS_OVERLAP_2008_10_26_02_30 = LocalDateTime.of(2008, 10, 26, 2, 30);
 162         TEST_PARIS_GAP_2008_03_30_02_30 = LocalDateTime.of(2008, 3, 30, 2, 30);
 163     }
 164 
 165     //-----------------------------------------------------------------------
 166     @Override
 167     protected List<TemporalAccessor> samples() {
 168         TemporalAccessor[] array = {TEST_DATE_TIME, };
 169         return Arrays.asList(array);
 170     }
 171 
 172     @Override
 173     protected List<TemporalField> validFields() {
 174         TemporalField[] array = {
 175             NANO_OF_SECOND,
 176             NANO_OF_DAY,
 177             MICRO_OF_SECOND,
 178             MICRO_OF_DAY,
 179             MILLI_OF_SECOND,
 180             MILLI_OF_DAY,
 181             SECOND_OF_MINUTE,
 182             SECOND_OF_DAY,
 183             MINUTE_OF_HOUR,
 184             MINUTE_OF_DAY,
 185             CLOCK_HOUR_OF_AMPM,
 186             HOUR_OF_AMPM,
 187             CLOCK_HOUR_OF_DAY,
 188             HOUR_OF_DAY,
 189             AMPM_OF_DAY,
 190             DAY_OF_WEEK,
 191             ALIGNED_DAY_OF_WEEK_IN_MONTH,
 192             ALIGNED_DAY_OF_WEEK_IN_YEAR,
 193             DAY_OF_MONTH,
 194             DAY_OF_YEAR,
 195             EPOCH_DAY,
 196             ALIGNED_WEEK_OF_MONTH,
 197             ALIGNED_WEEK_OF_YEAR,
 198             MONTH_OF_YEAR,
 199             EPOCH_MONTH,
 200             YEAR_OF_ERA,
 201             YEAR,
 202             ERA,
 203             OFFSET_SECONDS,
 204             INSTANT_SECONDS,
 205             JulianFields.JULIAN_DAY,
 206             JulianFields.MODIFIED_JULIAN_DAY,
 207             JulianFields.RATA_DIE,
 208         };
 209         return Arrays.asList(array);
 210     }
 211 
 212     @Override
 213     protected List<TemporalField> invalidFields() {
 214         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 215         list.removeAll(validFields());
 216         return list;
 217     }
 218 
 219     //-----------------------------------------------------------------------
 220     @Test
 221     public void test_serialization() throws ClassNotFoundException, IOException {
 222         assertSerializable(TEST_DATE_TIME);
 223     }
 224 
 225     @Test
 226     public void test_serialization_format_zoneId() throws Exception {
 227         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 228         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 229             dos.writeByte(6);
 230             dos.writeInt(2012); // date
 231             dos.writeByte(9);
 232             dos.writeByte(16);
 233             dos.writeByte(22);  // time
 234             dos.writeByte(17);
 235             dos.writeByte(59);
 236             dos.writeInt(470_000_000);
 237             dos.writeByte(4);  // offset
 238             dos.writeByte(7);  // zoneId
 239             dos.writeUTF("Europe/London");
 240         }
 241         byte[] bytes = baos.toByteArray();
 242         ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneId.of("Europe/London"));
 243         assertSerializedBySer(zdt, bytes);
 244     }
 245 
 246     @Test
 247     public void test_serialization_format_zoneOffset() throws Exception {
 248         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 249         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 250             dos.writeByte(6);
 251             dos.writeInt(2012); // date
 252             dos.writeByte(9);
 253             dos.writeByte(16);
 254             dos.writeByte(22);  // time
 255             dos.writeByte(17);
 256             dos.writeByte(59);
 257             dos.writeInt(470_000_000);
 258             dos.writeByte(4);  // offset
 259             dos.writeByte(8);  // zoneId
 260             dos.writeByte(4);
 261         }
 262         byte[] bytes = baos.toByteArray();
 263         ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneOffset.ofHours(1));
 264         assertSerializedBySer(zdt, bytes);
 265     }
 266 
 267     //-----------------------------------------------------------------------
 268     // now()
 269     //-----------------------------------------------------------------------
 270     @Test(groups={"tck"})
 271     public void now() {
 272         ZonedDateTime expected = ZonedDateTime.now(Clock.systemDefaultZone());
 273         ZonedDateTime test = ZonedDateTime.now();
 274         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 275         if (diff >= 100000000) {
 276             // may be date change
 277             expected = ZonedDateTime.now(Clock.systemDefaultZone());
 278             test = ZonedDateTime.now();
 279             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 280         }
 281         assertTrue(diff < 100000000);  // less than 0.1 secs
 282     }
 283 
 284     //-----------------------------------------------------------------------
 285     // now(ZoneId)
 286     //-----------------------------------------------------------------------
 287     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 288     public void now_ZoneId_nullZoneId() {
 289         ZonedDateTime.now((ZoneId) null);
 290     }
 291 
 292     @Test(groups={"tck"})
 293     public void now_ZoneId() {
 294         ZoneId zone = ZoneId.of("UTC+01:02:03");
 295         ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone));
 296         ZonedDateTime test = ZonedDateTime.now(zone);
 297         for (int i = 0; i < 100; i++) {
 298             if (expected.equals(test)) {
 299                 return;
 300             }
 301             expected = ZonedDateTime.now(Clock.system(zone));
 302             test = ZonedDateTime.now(zone);
 303         }
 304         assertEquals(test, expected);
 305     }
 306 
 307     //-----------------------------------------------------------------------
 308     // now(Clock)
 309     //-----------------------------------------------------------------------
 310     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 311     public void now_Clock_nullClock() {
 312         ZonedDateTime.now((Clock)null);
 313     }
 314 
 315     @Test(groups={"tck"})
 316     public void now_Clock_allSecsInDay_utc() {
 317         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 318             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 319             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 320             ZonedDateTime test = ZonedDateTime.now(clock);
 321             assertEquals(test.getYear(), 1970);
 322             assertEquals(test.getMonth(), Month.JANUARY);
 323             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
 324             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 325             assertEquals(test.getMinute(), (i / 60) % 60);
 326             assertEquals(test.getSecond(), i % 60);
 327             assertEquals(test.getNano(), 123456789);
 328             assertEquals(test.getOffset(), ZoneOffset.UTC);
 329             assertEquals(test.getZone(), ZoneOffset.UTC);
 330         }
 331     }
 332 
 333     @Test(groups={"tck"})
 334     public void now_Clock_allSecsInDay_zone() {
 335         ZoneId zone = ZoneId.of("Europe/London");
 336         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 337             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 338             ZonedDateTime expected = ZonedDateTime.ofInstant(instant, zone);
 339             Clock clock = Clock.fixed(expected.toInstant(), zone);
 340             ZonedDateTime test = ZonedDateTime.now(clock);
 341             assertEquals(test, expected);
 342         }
 343     }
 344 
 345     @Test(groups={"tck"})
 346     public void now_Clock_allSecsInDay_beforeEpoch() {
 347         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 348         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 349             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 350             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 351             ZonedDateTime test = ZonedDateTime.now(clock);
 352             assertEquals(test.getYear(), 1969);
 353             assertEquals(test.getMonth(), Month.DECEMBER);
 354             assertEquals(test.getDayOfMonth(), 31);
 355             expected = expected.minusSeconds(1);
 356             assertEquals(test.toLocalTime(), expected);
 357             assertEquals(test.getOffset(), ZoneOffset.UTC);
 358             assertEquals(test.getZone(), ZoneOffset.UTC);
 359         }
 360     }
 361 
 362     @Test(groups={"tck"})
 363     public void now_Clock_offsets() {
 364         ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(1970, 1, 1, 12, 0), ZoneOffset.UTC);
 365         for (int i = -9; i < 15; i++) {
 366             ZoneOffset offset = ZoneOffset.ofHours(i);
 367             Clock clock = Clock.fixed(base.toInstant(), offset);
 368             ZonedDateTime test = ZonedDateTime.now(clock);
 369             assertEquals(test.getHour(), (12 + i) % 24);
 370             assertEquals(test.getMinute(), 0);
 371             assertEquals(test.getSecond(), 0);
 372             assertEquals(test.getNano(), 0);
 373             assertEquals(test.getOffset(), offset);
 374             assertEquals(test.getZone(), offset);
 375         }
 376     }
 377 
 378     //-----------------------------------------------------------------------
 379     // dateTime factories
 380     //-----------------------------------------------------------------------
 381     void check(ZonedDateTime test, int y, int m, int d, int h, int min, int s, int n, ZoneOffset offset, ZoneId zone) {
 382         assertEquals(test.getYear(), y);
 383         assertEquals(test.getMonth().getValue(), m);
 384         assertEquals(test.getDayOfMonth(), d);
 385         assertEquals(test.getHour(), h);
 386         assertEquals(test.getMinute(), min);
 387         assertEquals(test.getSecond(), s);
 388         assertEquals(test.getNano(), n);
 389         assertEquals(test.getOffset(), offset);
 390         assertEquals(test.getZone(), zone);
 391     }
 392 
 393     //-----------------------------------------------------------------------
 394     // of(LocalDate, LocalTime, ZoneId)
 395     //-----------------------------------------------------------------------
 396     @Test(groups={"tck"})
 397     public void factory_of_LocalDateLocalTime() {
 398         ZonedDateTime test = ZonedDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), ZONE_PARIS);
 399         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 400     }
 401 
 402     @Test(groups={"tck"})
 403     public void factory_of_LocalDateLocalTime_inGap() {
 404         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_GAP_2008_03_30_02_30.toLocalDate(), TEST_PARIS_GAP_2008_03_30_02_30.toLocalTime(), ZONE_PARIS);
 405         check(test, 2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // one hour later in summer offset
 406     }
 407 
 408     @Test(groups={"tck"})
 409     public void factory_of_LocalDateLocalTime_inOverlap() {
 410         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_OVERLAP_2008_10_26_02_30.toLocalDate(), TEST_PARIS_OVERLAP_2008_10_26_02_30.toLocalTime(), ZONE_PARIS);
 411         check(test, 2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // same time in summer offset
 412     }
 413 
 414     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 415     public void factory_of_LocalDateLocalTime_nullDate() {
 416         ZonedDateTime.of((LocalDate) null, LocalTime.of(11, 30, 10, 500), ZONE_PARIS);
 417     }
 418 
 419     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 420     public void factory_of_LocalDateLocalTime_nullTime() {
 421         ZonedDateTime.of(LocalDate.of(2008, 6, 30), (LocalTime) null, ZONE_PARIS);
 422     }
 423 
 424     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 425     public void factory_of_LocalDateLocalTime_nullZone() {
 426         ZonedDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), null);
 427     }
 428 
 429     //-----------------------------------------------------------------------
 430     // of(LocalDateTime, ZoneId)
 431     //-----------------------------------------------------------------------
 432     @Test(groups={"tck"})
 433     public void factory_of_LocalDateTime() {
 434         LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 435         ZonedDateTime test = ZonedDateTime.of(base, ZONE_PARIS);
 436         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 437     }
 438 
 439     @Test(groups={"tck"})
 440     public void factory_of_LocalDateTime_inGap() {
 441         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_GAP_2008_03_30_02_30, ZONE_PARIS);
 442         check(test, 2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // one hour later in summer offset
 443     }
 444 
 445     @Test(groups={"tck"})
 446     public void factory_of_LocalDateTime_inOverlap() {
 447         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_OVERLAP_2008_10_26_02_30, ZONE_PARIS);
 448         check(test, 2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // same time in summer offset
 449     }
 450 
 451     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 452     public void factory_of_LocalDateTime_nullDateTime() {
 453         ZonedDateTime.of((LocalDateTime) null, ZONE_PARIS);
 454     }
 455 
 456     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 457     public void factory_of_LocalDateTime_nullZone() {
 458         LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 459         ZonedDateTime.of(base, null);
 460     }
 461 
 462     //-----------------------------------------------------------------------
 463     // of(int..., ZoneId)
 464     //-----------------------------------------------------------------------
 465     @Test(groups={"tck"})
 466     public void factory_of_ints() {
 467         ZonedDateTime test = ZonedDateTime.of(2008, 6, 30, 11, 30, 10, 500, ZONE_PARIS);
 468         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 469     }
 470 
 471     //-----------------------------------------------------------------------
 472     // ofInstant(Instant, ZoneId)
 473     //-----------------------------------------------------------------------
 474     @Test(groups={"tck"})
 475     public void factory_ofInstant_Instant_ZR() {
 476         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 35).toInstant(OFFSET_0200);
 477         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 478         check(test, 2008, 6, 30, 11, 30, 10, 35, OFFSET_0200, ZONE_PARIS);
 479     }
 480 
 481     @Test(groups={"tck"})
 482     public void factory_ofInstant_Instant_ZO() {
 483         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 45).toInstant(OFFSET_0200);
 484         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_0200);
 485         check(test, 2008, 6, 30, 11, 30, 10, 45, OFFSET_0200, OFFSET_0200);
 486     }
 487 
 488     @Test(groups={"tck"})
 489     public void factory_ofInstant_Instant_inGap() {
 490         Instant instant = TEST_PARIS_GAP_2008_03_30_02_30.toInstant(OFFSET_0100);
 491         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 492         check(test, 2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // one hour later in summer offset
 493     }
 494 
 495     @Test(groups={"tck"})
 496     public void factory_ofInstant_Instant_inOverlap_earlier() {
 497         Instant instant = TEST_PARIS_OVERLAP_2008_10_26_02_30.toInstant(OFFSET_0200);
 498         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 499         check(test, 2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // same time and offset
 500     }
 501 
 502     @Test(groups={"tck"})
 503     public void factory_ofInstant_Instant_inOverlap_later() {
 504         Instant instant = TEST_PARIS_OVERLAP_2008_10_26_02_30.toInstant(OFFSET_0100);
 505         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 506         check(test, 2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS);  // same time and offset
 507     }
 508 
 509     @Test(groups={"tck"})
 510     public void factory_ofInstant_Instant_invalidOffset() {
 511         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500).toInstant(OFFSET_0130);
 512         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 513         check(test, 2008, 6, 30, 12, 0, 10, 500, OFFSET_0200, ZONE_PARIS);  // corrected offset, thus altered time
 514     }
 515 
 516     @Test(groups={"tck"})
 517     public void factory_ofInstant_allSecsInDay() {
 518         for (int i = 0; i < (24 * 60 * 60); i++) {
 519             Instant instant = Instant.ofEpochSecond(i);
 520             ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_0100);
 521             assertEquals(test.getYear(), 1970);
 522             assertEquals(test.getMonth(), Month.JANUARY);
 523             assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
 524             assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
 525             assertEquals(test.getMinute(), (i / 60) % 60);
 526             assertEquals(test.getSecond(), i % 60);
 527         }
 528     }
 529 
 530     @Test(groups={"tck"})
 531     public void factory_ofInstant_allDaysInCycle() {
 532         // sanity check using different algorithm
 533         ZonedDateTime expected = LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0).atZone(ZoneOffset.UTC);
 534         for (long i = 0; i < 146097; i++) {
 535             Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
 536             ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
 537             assertEquals(test, expected);
 538             expected = expected.plusDays(1);
 539         }
 540     }
 541 
 542     @Test(groups={"tck"})
 543     public void factory_ofInstant_minWithMinOffset() {
 544         long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
 545         int year = Year.MIN_VALUE;
 546         long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
 547         Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MIN.getTotalSeconds());
 548         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MIN);
 549         assertEquals(test.getYear(), Year.MIN_VALUE);
 550         assertEquals(test.getMonth().getValue(), 1);
 551         assertEquals(test.getDayOfMonth(), 1);
 552         assertEquals(test.getOffset(), OFFSET_MIN);
 553         assertEquals(test.getHour(), 0);
 554         assertEquals(test.getMinute(), 0);
 555         assertEquals(test.getSecond(), 0);
 556         assertEquals(test.getNano(), 0);
 557     }
 558 
 559     @Test(groups={"tck"})
 560     public void factory_ofInstant_minWithMaxOffset() {
 561         long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
 562         int year = Year.MIN_VALUE;
 563         long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
 564         Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MAX.getTotalSeconds());
 565         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MAX);
 566         assertEquals(test.getYear(), Year.MIN_VALUE);
 567         assertEquals(test.getMonth().getValue(), 1);
 568         assertEquals(test.getDayOfMonth(), 1);
 569         assertEquals(test.getOffset(), OFFSET_MAX);
 570         assertEquals(test.getHour(), 0);
 571         assertEquals(test.getMinute(), 0);
 572         assertEquals(test.getSecond(), 0);
 573         assertEquals(test.getNano(), 0);
 574     }
 575 
 576     @Test(groups={"tck"})
 577     public void factory_ofInstant_maxWithMinOffset() {
 578         long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
 579         int year = Year.MAX_VALUE;
 580         long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
 581         Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MIN.getTotalSeconds());
 582         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MIN);
 583         assertEquals(test.getYear(), Year.MAX_VALUE);
 584         assertEquals(test.getMonth().getValue(), 12);
 585         assertEquals(test.getDayOfMonth(), 31);
 586         assertEquals(test.getOffset(), OFFSET_MIN);
 587         assertEquals(test.getHour(), 23);
 588         assertEquals(test.getMinute(), 59);
 589         assertEquals(test.getSecond(), 59);
 590         assertEquals(test.getNano(), 0);
 591     }
 592 
 593     @Test(groups={"tck"})
 594     public void factory_ofInstant_maxWithMaxOffset() {
 595         long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
 596         int year = Year.MAX_VALUE;
 597         long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
 598         Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
 599         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MAX);
 600         assertEquals(test.getYear(), Year.MAX_VALUE);
 601         assertEquals(test.getMonth().getValue(), 12);
 602         assertEquals(test.getDayOfMonth(), 31);
 603         assertEquals(test.getOffset(), OFFSET_MAX);
 604         assertEquals(test.getHour(), 23);
 605         assertEquals(test.getMinute(), 59);
 606         assertEquals(test.getSecond(), 59);
 607         assertEquals(test.getNano(), 0);
 608     }
 609 
 610     //-----------------------------------------------------------------------
 611     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 612     public void factory_ofInstant_maxInstantWithMaxOffset() {
 613         Instant instant = Instant.ofEpochSecond(Long.MAX_VALUE);
 614         ZonedDateTime.ofInstant(instant, OFFSET_MAX);
 615     }
 616 
 617     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 618     public void factory_ofInstant_maxInstantWithMinOffset() {
 619         Instant instant = Instant.ofEpochSecond(Long.MAX_VALUE);
 620         ZonedDateTime.ofInstant(instant, OFFSET_MIN);
 621     }
 622 
 623     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 624     public void factory_ofInstant_tooBig() {
 625         long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
 626         long year = Year.MAX_VALUE + 1L;
 627         long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
 628         Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
 629         ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
 630     }
 631 
 632     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 633     public void factory_ofInstant_tooLow() {
 634         long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
 635         int year = Year.MIN_VALUE - 1;
 636         long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
 637         Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
 638         ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
 639     }
 640 
 641     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 642     public void factory_ofInstant_Instant_nullInstant() {
 643         ZonedDateTime.ofInstant((Instant) null, ZONE_0100);
 644     }
 645 
 646     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 647     public void factory_ofInstant_Instant_nullZone() {
 648         ZonedDateTime.ofInstant(Instant.EPOCH, null);
 649     }
 650 
 651     //-----------------------------------------------------------------------
 652     // ofStrict(LocalDateTime, ZoneId, ZoneOffset)
 653     //-----------------------------------------------------------------------
 654     @Test(groups={"tck"})
 655     public void factory_ofStrict_LDT_ZI_ZO() {
 656         LocalDateTime normal = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 657         ZonedDateTime test = ZonedDateTime.ofStrict(normal, OFFSET_0200, ZONE_PARIS);
 658         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 659     }
 660 
 661     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 662     public void factory_ofStrict_LDT_ZI_ZO_inGap() {
 663         try {
 664             ZonedDateTime.ofStrict(TEST_PARIS_GAP_2008_03_30_02_30, OFFSET_0100, ZONE_PARIS);
 665         } catch (DateTimeException ex) {
 666             assertEquals(ex.getMessage().contains(" gap"), true);
 667             throw ex;
 668         }
 669     }
 670 
 671     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 672     public void factory_ofStrict_LDT_ZI_ZO_inOverlap_invalidOfset() {
 673         try {
 674             ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0130, ZONE_PARIS);
 675         } catch (DateTimeException ex) {
 676             assertEquals(ex.getMessage().contains(" is not valid for "), true);
 677             throw ex;
 678         }
 679     }
 680 
 681     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 682     public void factory_ofStrict_LDT_ZI_ZO_invalidOffset() {
 683         try {
 684             ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0130, ZONE_PARIS);
 685         } catch (DateTimeException ex) {
 686             assertEquals(ex.getMessage().contains(" is not valid for "), true);
 687             throw ex;
 688         }
 689     }
 690 
 691     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 692     public void factory_ofStrict_LDT_ZI_ZO_nullLDT() {
 693         ZonedDateTime.ofStrict((LocalDateTime) null, OFFSET_0100, ZONE_PARIS);
 694     }
 695 
 696     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 697     public void factory_ofStrict_LDT_ZI_ZO_nullZO() {
 698         ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, null, ZONE_PARIS);
 699     }
 700 
 701     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 702     public void factory_ofStrict_LDT_ZI_ZO_nullZI() {
 703         ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0100, null);
 704     }
 705 
 706     //-----------------------------------------------------------------------
 707     // from(TemporalAccessor)
 708     //-----------------------------------------------------------------------
 709     @Test(groups={"tck"})
 710     public void factory_from_TemporalAccessor_ZDT() {
 711         assertEquals(ZonedDateTime.from(TEST_DATE_TIME_PARIS), TEST_DATE_TIME_PARIS);
 712     }
 713 
 714     @Test(groups={"tck"})
 715     public void factory_from_TemporalAccessor_LDT_ZoneId() {
 716         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 717             @Override
 718             public boolean isSupported(TemporalField field) {
 719                 return TEST_DATE_TIME_PARIS.toLocalDateTime().isSupported(field);
 720             }
 721             @Override
 722             public long getLong(TemporalField field) {
 723                 return TEST_DATE_TIME_PARIS.toLocalDateTime().getLong(field);
 724             }
 725             @SuppressWarnings("unchecked")
 726             @Override
 727             public <R> R query(TemporalQuery<R> query) {
 728                 if (query == Queries.zoneId()) {
 729                     return (R) TEST_DATE_TIME_PARIS.getZone();
 730                 }
 731                 return TemporalAccessor.super.query(query);
 732             }
 733         }), TEST_DATE_TIME_PARIS);
 734     }
 735 
 736     @Test(groups={"tck"})
 737     public void factory_from_TemporalAccessor_Instant_ZoneId() {
 738         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 739             @Override
 740             public boolean isSupported(TemporalField field) {
 741                 return field == INSTANT_SECONDS || field == NANO_OF_SECOND;
 742             }
 743 
 744             @Override
 745             public long getLong(TemporalField field) {
 746                 return TEST_DATE_TIME_PARIS.toInstant().getLong(field);
 747             }
 748 
 749             @SuppressWarnings("unchecked")
 750             @Override
 751             public <R> R query(TemporalQuery<R> query) {
 752                 if (query == Queries.zoneId()) {
 753                     return (R) TEST_DATE_TIME_PARIS.getZone();
 754                 }
 755                 return TemporalAccessor.super.query(query);
 756             }
 757         }), TEST_DATE_TIME_PARIS);
 758     }
 759 
 760     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 761     public void factory_from_TemporalAccessor_invalid_noDerive() {
 762         ZonedDateTime.from(LocalTime.of(12, 30));
 763     }
 764 
 765     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 766     public void factory_from_TemporalAccessor_null() {
 767         ZonedDateTime.from((TemporalAccessor) null);
 768     }
 769 
 770     //-----------------------------------------------------------------------
 771     // parse()
 772     //-----------------------------------------------------------------------
 773     @Test(dataProvider="sampleToString")
 774     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String zoneId, String text) {
 775         ZonedDateTime t = ZonedDateTime.parse(text);
 776         assertEquals(t.getYear(), y);
 777         assertEquals(t.getMonth().getValue(), month);
 778         assertEquals(t.getDayOfMonth(), d);
 779         assertEquals(t.getHour(), h);
 780         assertEquals(t.getMinute(), m);
 781         assertEquals(t.getSecond(), s);
 782         assertEquals(t.getNano(), n);
 783         assertEquals(t.getZone().getId(), zoneId);
 784     }
 785 
 786     @DataProvider(name="parseAdditional")
 787     Object[][] data_parseAdditional() {
 788         return new Object[][] {
 789                 {"2012-06-30T12:30:40Z[GMT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 790                 {"2012-06-30T12:30:40Z[UT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 791                 {"2012-06-30T12:30:40Z[UTC]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 792                 {"2012-06-30T12:30:40+01:00[+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 793                 {"2012-06-30T12:30:40+01:00[GMT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 794                 {"2012-06-30T12:30:40+01:00[UT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 795                 {"2012-06-30T12:30:40+01:00[UTC+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 796                 {"2012-06-30T12:30:40-01:00[-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 797                 {"2012-06-30T12:30:40-01:00[GMT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 798                 {"2012-06-30T12:30:40-01:00[UT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 799                 {"2012-06-30T12:30:40-01:00[UTC-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 800                 {"2012-06-30T12:30:40+01:00[Europe/London]", 2012, 6, 30, 12, 30, 40, 0, "Europe/London"},
 801         };
 802     }
 803 
 804     @Test(dataProvider="parseAdditional")
 805     public void test_parseAdditional(String text, int y, int month, int d, int h, int m, int s, int n, String zoneId) {
 806         ZonedDateTime t = ZonedDateTime.parse(text);
 807         assertEquals(t.getYear(), y);
 808         assertEquals(t.getMonth().getValue(), month);
 809         assertEquals(t.getDayOfMonth(), d);
 810         assertEquals(t.getHour(), h);
 811         assertEquals(t.getMinute(), m);
 812         assertEquals(t.getSecond(), s);
 813         assertEquals(t.getNano(), n);
 814         assertEquals(t.getZone().getId(), zoneId);
 815     }
 816 
 817     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 818     public void factory_parse_illegalValue() {
 819         ZonedDateTime.parse("2008-06-32T11:15+01:00[Europe/Paris]");
 820     }
 821 
 822     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 823     public void factory_parse_invalidValue() {
 824         ZonedDateTime.parse("2008-06-31T11:15+01:00[Europe/Paris]");
 825     }
 826 
 827     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 828     public void factory_parse_nullText() {
 829         ZonedDateTime.parse((String) null);
 830     }
 831 
 832     //-----------------------------------------------------------------------
 833     // parse(DateTimeFormatter)
 834     //-----------------------------------------------------------------------
 835     @Test(groups={"tck"})
 836     public void factory_parse_formatter() {
 837         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s VV");
 838         ZonedDateTime test = ZonedDateTime.parse("2010 12 3 11 30 0 Europe/London", f);
 839         assertEquals(test, ZonedDateTime.of(LocalDateTime.of(2010, 12, 3, 11, 30), ZoneId.of("Europe/London")));
 840     }
 841 
 842     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 843     public void factory_parse_formatter_nullText() {
 844         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 845         ZonedDateTime.parse((String) null, f);
 846     }
 847 
 848     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 849     public void factory_parse_formatter_nullFormatter() {
 850         ZonedDateTime.parse("ANY", null);
 851     }
 852 
 853     //-----------------------------------------------------------------------
 854     // basics
 855     //-----------------------------------------------------------------------
 856     @DataProvider(name="sampleTimes")
 857     Object[][] provider_sampleTimes() {
 858         return new Object[][] {
 859             {2008, 6, 30, 11, 30, 20, 500, ZONE_0100},
 860             {2008, 6, 30, 11, 0, 0, 0, ZONE_0100},
 861             {2008, 6, 30, 11, 30, 20, 500, ZONE_PARIS},
 862             {2008, 6, 30, 11, 0, 0, 0, ZONE_PARIS},
 863             {2008, 6, 30, 23, 59, 59, 999999999, ZONE_0100},
 864             {-1, 1, 1, 0, 0, 0, 0, ZONE_0100},
 865         };
 866     }
 867 
 868     @Test(dataProvider="sampleTimes", groups={"tck"})
 869     public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) {
 870         LocalDate localDate = LocalDate.of(y, o, d);
 871         LocalTime localTime = LocalTime.of(h, m, s, n);
 872         LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
 873         ZoneOffset offset = zone.getRules().getOffset(localDateTime);
 874         ZonedDateTime a = ZonedDateTime.of(localDateTime, zone);
 875 
 876         assertEquals(a.getYear(), localDate.getYear());
 877         assertEquals(a.getMonth(), localDate.getMonth());
 878         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 879         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 880         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 881 
 882         assertEquals(a.getHour(), localTime.getHour());
 883         assertEquals(a.getMinute(), localTime.getMinute());
 884         assertEquals(a.getSecond(), localTime.getSecond());
 885         assertEquals(a.getNano(), localTime.getNano());
 886 
 887         assertEquals(a.toLocalDate(), localDate);
 888         assertEquals(a.toLocalTime(), localTime);
 889         assertEquals(a.toLocalDateTime(), localDateTime);
 890         if (zone instanceof ZoneOffset) {
 891             assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 892         } else {
 893             assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
 894         }
 895     }
 896 
 897     //-----------------------------------------------------------------------
 898     // get(TemporalField)
 899     //-----------------------------------------------------------------------
 900     @Test
 901     public void test_get_TemporalField() {
 902         ZonedDateTime test = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321), ZONE_0100);
 903         assertEquals(test.get(ChronoField.YEAR), 2008);
 904         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 905         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 906         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 907         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 908 
 909         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 910         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 911         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 912         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 913         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 914         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 915 
 916         assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600);
 917     }
 918 
 919     @Test
 920     public void test_getLong_TemporalField() {
 921         ZonedDateTime test = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321), ZONE_0100);
 922         assertEquals(test.getLong(ChronoField.YEAR), 2008);
 923         assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
 924         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 925         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 926         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 927 
 928         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 929         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 930         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 931         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 932         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 933         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 934 
 935         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 936         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
 937     }
 938 
 939     //-----------------------------------------------------------------------
 940     // query(TemporalQuery)
 941     //-----------------------------------------------------------------------
 942     @Test
 943     public void test_query_chrono() {
 944         assertEquals(TEST_DATE_TIME.query(Queries.chronology()), IsoChronology.INSTANCE);
 945         assertEquals(Queries.chronology().queryFrom(TEST_DATE_TIME), IsoChronology.INSTANCE);
 946     }
 947 
 948     @Test
 949     public void test_query_zoneId() {
 950         assertEquals(TEST_DATE_TIME.query(Queries.zoneId()), TEST_DATE_TIME.getZone());
 951         assertEquals(Queries.zoneId().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
 952     }
 953 
 954     @Test
 955     public void test_query_precision() {
 956         assertEquals(TEST_DATE_TIME.query(Queries.precision()), NANOS);
 957         assertEquals(Queries.precision().queryFrom(TEST_DATE_TIME), NANOS);
 958     }
 959 
 960     @Test
 961     public void test_query_offset() {
 962         assertEquals(TEST_DATE_TIME.query(Queries.offset()), TEST_DATE_TIME.getOffset());
 963         assertEquals(Queries.offset().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getOffset());
 964     }
 965 
 966     @Test
 967     public void test_query_zone() {
 968         assertEquals(TEST_DATE_TIME.query(Queries.zone()), TEST_DATE_TIME.getZone());
 969         assertEquals(Queries.zone().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
 970     }
 971 
 972     @Test(expectedExceptions=NullPointerException.class)
 973     public void test_query_null() {
 974         TEST_DATE_TIME.query(null);
 975     }
 976 
 977     //-----------------------------------------------------------------------
 978     // withEarlierOffsetAtOverlap()
 979     //-----------------------------------------------------------------------
 980     @Test(groups={"tck"})
 981     public void test_withEarlierOffsetAtOverlap_notAtOverlap() {
 982         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
 983         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 984         assertEquals(test, base);  // not changed
 985     }
 986 
 987     @Test(groups={"tck"})
 988     public void test_withEarlierOffsetAtOverlap_atOverlap() {
 989         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0100, ZONE_PARIS);
 990         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 991         assertEquals(test.getOffset(), OFFSET_0200);  // offset changed to earlier
 992         assertEquals(test.toLocalDateTime(), base.toLocalDateTime());  // date-time not changed
 993     }
 994 
 995     @Test(groups={"tck"})
 996     public void test_withEarlierOffsetAtOverlap_atOverlap_noChange() {
 997         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0200, ZONE_PARIS);
 998         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 999         assertEquals(test, base);  // not changed
1000     }
1001 
1002     //-----------------------------------------------------------------------
1003     // withLaterOffsetAtOverlap()
1004     //-----------------------------------------------------------------------
1005     @Test(groups={"tck"})
1006     public void test_withLaterOffsetAtOverlap_notAtOverlap() {
1007         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
1008         ZonedDateTime test = base.withLaterOffsetAtOverlap();
1009         assertEquals(test, base);  // not changed
1010     }
1011 
1012     @Test(groups={"tck"})
1013     public void test_withLaterOffsetAtOverlap_atOverlap() {
1014         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0200, ZONE_PARIS);
1015         ZonedDateTime test = base.withLaterOffsetAtOverlap();
1016         assertEquals(test.getOffset(), OFFSET_0100);  // offset changed to later
1017         assertEquals(test.toLocalDateTime(), base.toLocalDateTime());  // date-time not changed
1018     }
1019 
1020     @Test(groups={"tck"})
1021     public void test_withLaterOffsetAtOverlap_atOverlap_noChange() {
1022         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0100, ZONE_PARIS);
1023         ZonedDateTime test = base.withLaterOffsetAtOverlap();
1024         assertEquals(test, base);  // not changed
1025     }
1026 
1027     //-----------------------------------------------------------------------
1028     // withZoneSameLocal(ZoneId)
1029     //-----------------------------------------------------------------------
1030     @Test(groups={"tck"})
1031     public void test_withZoneSameLocal() {
1032         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1033         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1034         ZonedDateTime test = base.withZoneSameLocal(ZONE_0200);
1035         assertEquals(test.toLocalDateTime(), base.toLocalDateTime());
1036     }
1037 
1038     @Test(groups={"tck","implementation"})
1039     public void test_withZoneSameLocal_noChange() {
1040         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1041         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1042         ZonedDateTime test = base.withZoneSameLocal(ZONE_0100);
1043         assertEquals(test, base);
1044     }
1045 
1046     @Test(groups={"tck"})
1047     public void test_withZoneSameLocal_retainOffset1() {
1048         LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
1049         ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-04:00") );
1050         ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
1051         assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
1052         assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
1053     }
1054 
1055     @Test(groups={"tck"})
1056     public void test_withZoneSameLocal_retainOffset2() {
1057         LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
1058         ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );
1059         ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
1060         assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
1061         assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
1062     }
1063 
1064     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1065     public void test_withZoneSameLocal_null() {
1066         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1067         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1068         base.withZoneSameLocal(null);
1069     }
1070 
1071     //-----------------------------------------------------------------------
1072     // withZoneSameInstant()
1073     //-----------------------------------------------------------------------
1074     @Test(groups={"tck"})
1075     public void test_withZoneSameInstant() {
1076         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1077         ZonedDateTime test = base.withZoneSameInstant(ZONE_0200);
1078         ZonedDateTime expected = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.plusHours(1), ZONE_0200);
1079         assertEquals(test, expected);
1080     }
1081 
1082     @Test(groups={"tck"})
1083     public void test_withZoneSameInstant_noChange() {
1084         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1085         ZonedDateTime test = base.withZoneSameInstant(ZONE_0100);
1086         assertEquals(test, base);
1087     }
1088 
1089     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1090     public void test_withZoneSameInstant_null() {
1091         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1092         base.withZoneSameInstant(null);
1093     }
1094 
1095     //-----------------------------------------------------------------------
1096     // withFixedOffsetZone()
1097     //-----------------------------------------------------------------------
1098     @Test(groups={"tck"})
1099     public void test_withZoneLocked() {
1100         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
1101         ZonedDateTime test = base.withFixedOffsetZone();
1102         ZonedDateTime expected = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0200);
1103         assertEquals(test, expected);
1104     }
1105 
1106     //-----------------------------------------------------------------------
1107     // with(WithAdjuster)
1108     //-----------------------------------------------------------------------
1109     @Test(groups={"tck"})
1110     public void test_with_WithAdjuster_LocalDateTime_sameOffset() {
1111         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
1112         ZonedDateTime test = base.with(LocalDateTime.of(2012, 7, 15, 14, 30));
1113         check(test, 2012, 7, 15, 14, 30, 0, 0, OFFSET_0200, ZONE_PARIS);
1114     }
1115 
1116     @Test(groups={"tck"})
1117     public void test_with_WithAdjuster_LocalDateTime_adjustedOffset() {
1118         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
1119         ZonedDateTime test = base.with(LocalDateTime.of(2012, 1, 15, 14, 30));
1120         check(test, 2012, 1, 15, 14, 30, 0, 0, OFFSET_0100, ZONE_PARIS);
1121     }
1122 
1123     @Test(groups={"tck"})
1124     public void test_with_WithAdjuster_LocalDate() {
1125         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
1126         ZonedDateTime test = base.with(LocalDate.of(2012, 7, 28));
1127         check(test, 2012, 7, 28, 11, 30, 59, 500, OFFSET_0200, ZONE_PARIS);
1128     }
1129 
1130     @Test(groups={"tck"})
1131     public void test_with_WithAdjuster_LocalTime() {
1132         ZonedDateTime base = ZonedDateTime.of(TEST_PARIS_OVERLAP_2008_10_26_02_30, ZONE_PARIS);
1133         ZonedDateTime test = base.with(LocalTime.of(2, 29));
1134         check(test, 2008, 10, 26, 2, 29, 0, 0, OFFSET_0200, ZONE_PARIS);
1135     }
1136 
1137     @Test(groups={"tck"})
1138     public void test_with_WithAdjuster_Year() {
1139         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1140         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1141         ZonedDateTime test = base.with(Year.of(2007));
1142         assertEquals(test, ZonedDateTime.of(ldt.withYear(2007), ZONE_0100));
1143     }
1144 
1145     @Test(groups={"tck"})
1146     public void test_with_WithAdjuster_Month_adjustedDayOfMonth() {
1147         ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(2012, 7, 31, 0, 0), ZONE_PARIS);
1148         ZonedDateTime test = base.with(Month.JUNE);
1149         check(test, 2012, 6, 30, 0, 0, 0, 0, OFFSET_0200, ZONE_PARIS);
1150     }
1151 
1152     @Test(groups={"tck"})
1153     public void test_with_WithAdjuster_Offset_same() {
1154         ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(2012, 7, 31, 0, 0), ZONE_PARIS);
1155         ZonedDateTime test = base.with(ZoneOffset.ofHours(2));
1156         check(test, 2012, 7, 31, 0, 0, 0, 0, OFFSET_0200, ZONE_PARIS);
1157     }
1158 
1159     @Test(groups={"tck"})
1160     public void test_with_WithAdjuster_Offset_timeAdjust() {
1161         ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(2012, 7, 31, 0, 0), ZONE_PARIS);
1162         ZonedDateTime test = base.with(ZoneOffset.ofHours(1));
1163         check(test, 2012, 7, 31, 1, 0, 0, 0, OFFSET_0200, ZONE_PARIS);  // time adjusted
1164     }
1165 
1166     @Test(groups={"tck"})
1167     public void test_with_WithAdjuster_LocalDate_retainOffset1() {
1168         ZoneId newYork = ZoneId.of("America/New_York");
1169         LocalDateTime ldt = LocalDateTime.of(2008, 11, 1, 1, 30);
1170         ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
1171         assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
1172         ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
1173         assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
1174     }
1175 
1176     @Test(groups={"tck"})
1177     public void test_with_WithAdjuster_LocalDate_retainOffset2() {
1178         ZoneId newYork = ZoneId.of("America/New_York");
1179         LocalDateTime ldt = LocalDateTime.of(2008, 11, 3, 1, 30);
1180         ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
1181         assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
1182         ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
1183         assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
1184     }
1185 
1186     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1187     public void test_with_WithAdjuster_null() {
1188         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1189         base.with((TemporalAdjuster) null);
1190     }
1191 
1192     //-----------------------------------------------------------------------
1193     // withYear()
1194     //-----------------------------------------------------------------------
1195     @Test(groups={"tck"})
1196     public void test_withYear_normal() {
1197         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1198         ZonedDateTime test = base.withYear(2007);
1199         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withYear(2007), ZONE_0100));
1200     }
1201 
1202     @Test(groups={"tck"})
1203     public void test_withYear_noChange() {
1204         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1205         ZonedDateTime test = base.withYear(2008);
1206         assertEquals(test, base);
1207     }
1208 
1209     //-----------------------------------------------------------------------
1210     // with(Month)
1211     //-----------------------------------------------------------------------
1212     @Test(groups={"tck"})
1213     public void test_withMonth_Month_normal() {
1214         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1215         ZonedDateTime test = base.with(JANUARY);
1216         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMonth(1), ZONE_0100));
1217     }
1218 
1219     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
1220     public void test_withMonth_Month_null() {
1221         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1222         base.with((Month) null);
1223     }
1224 
1225     //-----------------------------------------------------------------------
1226     // withMonth()
1227     //-----------------------------------------------------------------------
1228     @Test(groups={"tck"})
1229     public void test_withMonth_normal() {
1230         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1231         ZonedDateTime test = base.withMonth(1);
1232         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMonth(1), ZONE_0100));
1233     }
1234 
1235     @Test(groups={"tck"})
1236     public void test_withMonth_noChange() {
1237         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1238         ZonedDateTime test = base.withMonth(6);
1239         assertEquals(test, base);
1240     }
1241 
1242     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1243     public void test_withMonth_tooBig() {
1244         TEST_DATE_TIME.withMonth(13);
1245     }
1246 
1247     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1248     public void test_withMonth_tooSmall() {
1249         TEST_DATE_TIME.withMonth(0);
1250     }
1251 
1252     //-----------------------------------------------------------------------
1253     // withDayOfMonth()
1254     //-----------------------------------------------------------------------
1255     @Test(groups={"tck"})
1256     public void test_withDayOfMonth_normal() {
1257         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1258         ZonedDateTime test = base.withDayOfMonth(15);
1259         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfMonth(15), ZONE_0100));
1260     }
1261 
1262     @Test(groups={"tck"})
1263     public void test_withDayOfMonth_noChange() {
1264         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1265         ZonedDateTime test = base.withDayOfMonth(30);
1266         assertEquals(test, base);
1267     }
1268 
1269     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1270     public void test_withDayOfMonth_tooBig() {
1271         LocalDateTime.of(2007, 7, 2, 11, 30).atZone(ZONE_PARIS).withDayOfMonth(32);
1272     }
1273 
1274     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1275     public void test_withDayOfMonth_tooSmall() {
1276         TEST_DATE_TIME.withDayOfMonth(0);
1277     }
1278 
1279     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1280     public void test_withDayOfMonth_invalid31() {
1281         LocalDateTime.of(2007, 6, 2, 11, 30).atZone(ZONE_PARIS).withDayOfMonth(31);
1282     }
1283 
1284     //-----------------------------------------------------------------------
1285     // withDayOfYear()
1286     //-----------------------------------------------------------------------
1287     @Test(groups={"tck"})
1288     public void test_withDayOfYear_normal() {
1289         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1290         ZonedDateTime test = base.withDayOfYear(33);
1291         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withDayOfYear(33), ZONE_0100));
1292     }
1293 
1294     @Test(groups={"tck"})
1295     public void test_withDayOfYear_noChange() {
1296         LocalDateTime ldt = LocalDateTime.of(2008, 2, 5, 23, 30, 59, 0);
1297         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1298         ZonedDateTime test = base.withDayOfYear(36);
1299         assertEquals(test, base);
1300     }
1301 
1302     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1303     public void test_withDayOfYear_tooBig() {
1304         TEST_DATE_TIME.withDayOfYear(367);
1305     }
1306 
1307     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1308     public void test_withDayOfYear_tooSmall() {
1309         TEST_DATE_TIME.withDayOfYear(0);
1310     }
1311 
1312     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
1313     public void test_withDayOfYear_invalid366() {
1314         LocalDateTime.of(2007, 2, 2, 11, 30).atZone(ZONE_PARIS).withDayOfYear(366);
1315     }
1316 
1317     //-----------------------------------------------------------------------
1318     // withHour()
1319     //-----------------------------------------------------------------------
1320     @Test(groups={"tck"})
1321     public void test_withHour_normal() {
1322         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1323         ZonedDateTime test = base.withHour(15);
1324         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100));
1325     }
1326 
1327     @Test(groups={"tck"})
1328     public void test_withHour_noChange() {
1329         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1330         ZonedDateTime test = base.withHour(11);
1331         assertEquals(test, base);
1332     }
1333 
1334     //-----------------------------------------------------------------------
1335     // withMinute()
1336     //-----------------------------------------------------------------------
1337     @Test(groups={"tck"})
1338     public void test_withMinute_normal() {
1339         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1340         ZonedDateTime test = base.withMinute(15);
1341         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
1342     }
1343 
1344     @Test(groups={"tck"})
1345     public void test_withMinute_noChange() {
1346         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1347         ZonedDateTime test = base.withMinute(30);
1348         assertEquals(test, base);
1349     }
1350 
1351     //-----------------------------------------------------------------------
1352     // withSecond()
1353     //-----------------------------------------------------------------------
1354     @Test(groups={"tck"})
1355     public void test_withSecond_normal() {
1356         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1357         ZonedDateTime test = base.withSecond(12);
1358         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withSecond(12), ZONE_0100));
1359     }
1360 
1361     @Test(groups={"tck"})
1362     public void test_withSecond_noChange() {
1363         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1364         ZonedDateTime test = base.withSecond(59);
1365         assertEquals(test, base);
1366     }
1367 
1368     //-----------------------------------------------------------------------
1369     // withNano()
1370     //-----------------------------------------------------------------------
1371     @Test(groups={"tck"})
1372     public void test_withNanoOfSecond_normal() {
1373         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1374         ZonedDateTime test = base.withNano(15);
1375         assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withNano(15), ZONE_0100));
1376     }
1377 
1378     @Test(groups={"tck"})
1379     public void test_withNanoOfSecond_noChange() {
1380         ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
1381         ZonedDateTime test = base.withNano(500);
1382         assertEquals(test, base);
1383     }
1384 
1385     //-----------------------------------------------------------------------
1386     // truncatedTo(TemporalUnit)
1387     //-----------------------------------------------------------------------
1388     @Test(groups={"tck"})
1389     public void test_truncatedTo_normal() {
1390         assertEquals(TEST_DATE_TIME.truncatedTo(NANOS), TEST_DATE_TIME);
1391         assertEquals(TEST_DATE_TIME.truncatedTo(SECONDS), TEST_DATE_TIME.withNano(0));
1392         assertEquals(TEST_DATE_TIME.truncatedTo(DAYS), TEST_DATE_TIME.with(LocalTime.MIDNIGHT));
1393     }
1394 
1395     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1396     public void test_truncatedTo_null() {
1397         TEST_DATE_TIME.truncatedTo(null);
1398     }
1399 
1400     //-----------------------------------------------------------------------
1401     // plus/minus
1402     //-----------------------------------------------------------------------
1403     @DataProvider(name="plusDays")
1404     Object[][] data_plusDays() {
1405         return new Object[][] {
1406             // normal
1407             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 0, dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1408             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 1, dateTime(2008, 7, 1, 23, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1409             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), -1, dateTime(2008, 6, 29, 23, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1410             // skip over gap
1411             {dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS), 1, dateTime(2008, 3, 31, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1412             {dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS), -1, dateTime(2008, 3, 29, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1413             // land in gap
1414             {dateTime(2008, 3, 29, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS), 1, dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1415             {dateTime(2008, 3, 31, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), -1, dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1416             // skip over overlap
1417             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 27, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1418             {dateTime(2008, 10, 25, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1419             // land in overlap
1420             {dateTime(2008, 10, 25, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1421             {dateTime(2008, 10, 27, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS), -1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1422         };
1423     }
1424 
1425     @DataProvider(name="plusTime")
1426     Object[][] data_plusTime() {
1427         return new Object[][] {
1428             // normal
1429             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 0, dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1430             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 1, dateTime(2008, 7, 1, 0, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1431             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), -1, dateTime(2008, 6, 30, 22, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1432             // gap
1433             {dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS), 1, dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1434             {dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS), -1, dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1435             // overlap
1436             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1437             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 2, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1438             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 3, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1439             {dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1440             {dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 2, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1441         };
1442     }
1443 
1444     //-----------------------------------------------------------------------
1445     // plus(TemporalAmount)
1446     //-----------------------------------------------------------------------
1447     @Test(groups={"tck"}, dataProvider="plusDays")
1448     public void test_plus_TemporalAmount_Period_days(ZonedDateTime base, int amount, ZonedDateTime expected) {
1449         assertEquals(base.plus(Period.ofDays(amount)), expected);
1450     }
1451 
1452     @Test(groups={"tck"}, dataProvider="plusTime")
1453     public void test_plus_TemporalAmount_Period_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1454         assertEquals(base.plus(MockSimplePeriod.of(amount, HOURS)), expected);
1455     }
1456 
1457     @Test(groups={"tck"}, dataProvider="plusTime")
1458     public void test_plus_TemporalAmount_Duration_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1459         assertEquals(base.plus(Duration.ofHours(amount)), expected);
1460     }
1461 
1462     @Test(groups={"tck"})
1463     public void test_plus_TemporalAmount() {
1464         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1465         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1466         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2009, 1, 1, 12, 30, 59, 500), ZONE_0100);
1467         assertEquals(t.plus(period), expected);
1468     }
1469 
1470     @Test(groups={"tck"})
1471     public void test_plus_TemporalAmount_Duration() {
1472         Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
1473         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1474         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 16, 36, 5, 500), ZONE_0100);
1475         assertEquals(t.plus(duration), expected);
1476     }
1477 
1478     @Test(groups={"tck"})
1479     public void test_plus_TemporalAmount_Period_zero() {
1480         ZonedDateTime t = TEST_DATE_TIME.plus(MockSimplePeriod.ZERO_DAYS);
1481         assertEquals(t, TEST_DATE_TIME);
1482     }
1483 
1484     @Test(groups={"tck"})
1485     public void test_plus_TemporalAmount_Duration_zero() {
1486         ZonedDateTime t = TEST_DATE_TIME.plus(Duration.ZERO);
1487         assertEquals(t, TEST_DATE_TIME);
1488     }
1489 
1490     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1491     public void test_plus_TemporalAmount_null() {
1492         TEST_DATE_TIME.plus((TemporalAmount) null);
1493     }
1494 
1495     //-----------------------------------------------------------------------
1496     // plus(long,TemporalUnit)
1497     //-----------------------------------------------------------------------
1498     @Test(groups={"tck"}, dataProvider="plusDays")
1499     public void test_plus_longUnit_days(ZonedDateTime base, long amount, ZonedDateTime expected) {
1500         assertEquals(base.plus(amount, DAYS), expected);
1501     }
1502 
1503     @Test(groups={"tck"}, dataProvider="plusTime")
1504     public void test_plus_longUnit_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1505         assertEquals(base.plus(amount, HOURS), expected);
1506     }
1507 
1508     @Test(groups={"tck"}, dataProvider="plusTime")
1509     public void test_plus_longUnit_minutes(ZonedDateTime base, long amount, ZonedDateTime expected) {
1510         assertEquals(base.plus(amount * 60, MINUTES), expected);
1511     }
1512 
1513     @Test(groups={"tck"}, dataProvider="plusTime")
1514     public void test_plus_longUnit_seconds(ZonedDateTime base, long amount, ZonedDateTime expected) {
1515         assertEquals(base.plus(amount * 3600, SECONDS), expected);
1516     }
1517 
1518     @Test(groups={"tck"}, dataProvider="plusTime")
1519     public void test_plus_longUnit_nanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
1520         assertEquals(base.plus(amount * 3600_000_000_000L, NANOS), expected);
1521     }
1522 
1523     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1524     public void test_plus_longUnit_null() {
1525         TEST_DATE_TIME_PARIS.plus(0, null);
1526     }
1527 
1528     //-----------------------------------------------------------------------
1529     // plusYears()
1530     //-----------------------------------------------------------------------
1531     @Test(groups={"tck"})
1532     public void test_plusYears() {
1533         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1534         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1535         ZonedDateTime test = base.plusYears(1);
1536         assertEquals(test, ZonedDateTime.of(ldt.plusYears(1), ZONE_0100));
1537     }
1538 
1539     @Test(groups={"tck"})
1540     public void test_plusYears_zero() {
1541         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1542         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1543         ZonedDateTime test = base.plusYears(0);
1544         assertEquals(test, base);
1545     }
1546 
1547     //-----------------------------------------------------------------------
1548     // plusMonths()
1549     //-----------------------------------------------------------------------
1550     @Test(groups={"tck"})
1551     public void test_plusMonths() {
1552         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1553         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1554         ZonedDateTime test = base.plusMonths(1);
1555         assertEquals(test, ZonedDateTime.of(ldt.plusMonths(1), ZONE_0100));
1556     }
1557 
1558     @Test(groups={"tck"})
1559     public void test_plusMonths_zero() {
1560         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1561         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1562         ZonedDateTime test = base.plusMonths(0);
1563         assertEquals(test, base);
1564     }
1565 
1566     //-----------------------------------------------------------------------
1567     // plusWeeks()
1568     //-----------------------------------------------------------------------
1569     @Test(groups={"tck"})
1570     public void test_plusWeeks() {
1571         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1572         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1573         ZonedDateTime test = base.plusWeeks(1);
1574         assertEquals(test, ZonedDateTime.of(ldt.plusWeeks(1), ZONE_0100));
1575     }
1576 
1577     @Test(groups={"tck"})
1578     public void test_plusWeeks_zero() {
1579         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1580         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1581         ZonedDateTime test = base.plusWeeks(0);
1582         assertEquals(test, base);
1583     }
1584 
1585     //-----------------------------------------------------------------------
1586     // plusDays()
1587     //-----------------------------------------------------------------------
1588     @Test(groups={"tck"}, dataProvider="plusDays")
1589     public void test_plusDays(ZonedDateTime base, long amount, ZonedDateTime expected) {
1590         assertEquals(base.plusDays(amount), expected);
1591     }
1592 
1593     //-----------------------------------------------------------------------
1594     // plusHours()
1595     //-----------------------------------------------------------------------
1596     @Test(groups={"tck"}, dataProvider="plusTime")
1597     public void test_plusHours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1598         assertEquals(base.plusHours(amount), expected);
1599     }
1600 
1601     //-----------------------------------------------------------------------
1602     // plusMinutes()
1603     //-----------------------------------------------------------------------
1604     @Test(groups={"tck"}, dataProvider="plusTime")
1605     public void test_plusMinutes(ZonedDateTime base, long amount, ZonedDateTime expected) {
1606         assertEquals(base.plusMinutes(amount * 60), expected);
1607     }
1608 
1609     @Test(groups={"tck"})
1610     public void test_plusMinutes_minutes() {
1611         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1612         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1613         ZonedDateTime test = base.plusMinutes(30);
1614         assertEquals(test, ZonedDateTime.of(ldt.plusMinutes(30), ZONE_0100));
1615     }
1616 
1617     //-----------------------------------------------------------------------
1618     // plusSeconds()
1619     //-----------------------------------------------------------------------
1620     @Test(groups={"tck"}, dataProvider="plusTime")
1621     public void test_plusSeconds(ZonedDateTime base, long amount, ZonedDateTime expected) {
1622         assertEquals(base.plusSeconds(amount * 3600), expected);
1623     }
1624 
1625     @Test(groups={"tck"})
1626     public void test_plusSeconds_seconds() {
1627         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1628         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1629         ZonedDateTime test = base.plusSeconds(1);
1630         assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
1631     }
1632 
1633     //-----------------------------------------------------------------------
1634     // plusNanos()
1635     //-----------------------------------------------------------------------
1636     @Test(groups={"tck"}, dataProvider="plusTime")
1637     public void test_plusNanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
1638         assertEquals(base.plusNanos(amount * 3600_000_000_000L), expected);
1639     }
1640 
1641     @Test(groups={"tck"})
1642     public void test_plusNanos_nanos() {
1643         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1644         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1645         ZonedDateTime test = base.plusNanos(1);
1646         assertEquals(test, ZonedDateTime.of(ldt.plusNanos(1), ZONE_0100));
1647     }
1648 
1649     //-----------------------------------------------------------------------
1650     // minus(TemporalAmount)
1651     //-----------------------------------------------------------------------
1652     @Test(groups={"tck"}, dataProvider="plusDays")
1653     public void test_minus_TemporalAmount_Period_days(ZonedDateTime base, int amount, ZonedDateTime expected) {
1654         assertEquals(base.minus(Period.ofDays(-amount)), expected);
1655     }
1656 
1657     @Test(groups={"tck"}, dataProvider="plusTime")
1658     public void test_minus_TemporalAmount_Period_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1659         assertEquals(base.minus(MockSimplePeriod.of(-amount, HOURS)), expected);
1660     }
1661 
1662     @Test(groups={"tck"}, dataProvider="plusTime")
1663     public void test_minus_TemporalAmount_Duration_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1664         assertEquals(base.minus(Duration.ofHours(-amount)), expected);
1665     }
1666 
1667     @Test(groups={"tck"})
1668     public void test_minus_TemporalAmount() {
1669         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1670         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1671         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2007, 11, 1, 12, 30, 59, 500), ZONE_0100);
1672         assertEquals(t.minus(period), expected);
1673     }
1674 
1675     @Test(groups={"tck"})
1676     public void test_minus_TemporalAmount_Duration() {
1677         Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
1678         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1679         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 8, 25, 53, 500), ZONE_0100);
1680         assertEquals(t.minus(duration), expected);
1681     }
1682 
1683     @Test(groups={"tck"})
1684     public void test_minus_TemporalAmount_Period_zero() {
1685         ZonedDateTime t = TEST_DATE_TIME.minus(MockSimplePeriod.ZERO_DAYS);
1686         assertEquals(t, TEST_DATE_TIME);
1687     }
1688 
1689     @Test(groups={"tck"})
1690     public void test_minus_TemporalAmount_Duration_zero() {
1691         ZonedDateTime t = TEST_DATE_TIME.minus(Duration.ZERO);
1692         assertEquals(t, TEST_DATE_TIME);
1693     }
1694 
1695     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1696     public void test_minus_TemporalAmount_null() {
1697         TEST_DATE_TIME.minus((TemporalAmount) null);
1698     }
1699 
1700     //-----------------------------------------------------------------------
1701     // minusYears()
1702     //-----------------------------------------------------------------------
1703     @Test(groups={"tck"})
1704     public void test_minusYears() {
1705         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1706         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1707         ZonedDateTime test = base.minusYears(1);
1708         assertEquals(test, ZonedDateTime.of(ldt.minusYears(1), ZONE_0100));
1709     }
1710 
1711     @Test(groups={"tck"})
1712     public void test_minusYears_zero() {
1713         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1714         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1715         ZonedDateTime test = base.minusYears(0);
1716         assertEquals(test, base);
1717     }
1718 
1719     //-----------------------------------------------------------------------
1720     // minusMonths()
1721     //-----------------------------------------------------------------------
1722     @Test(groups={"tck"})
1723     public void test_minusMonths() {
1724         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1725         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1726         ZonedDateTime test = base.minusMonths(1);
1727         assertEquals(test, ZonedDateTime.of(ldt.minusMonths(1), ZONE_0100));
1728     }
1729 
1730     @Test(groups={"tck"})
1731     public void test_minusMonths_zero() {
1732         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1733         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1734         ZonedDateTime test = base.minusMonths(0);
1735         assertEquals(test, base);
1736     }
1737 
1738     //-----------------------------------------------------------------------
1739     // minusWeeks()
1740     //-----------------------------------------------------------------------
1741     @Test(groups={"tck"})
1742     public void test_minusWeeks() {
1743         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1744         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1745         ZonedDateTime test = base.minusWeeks(1);
1746         assertEquals(test, ZonedDateTime.of(ldt.minusWeeks(1), ZONE_0100));
1747     }
1748 
1749     @Test(groups={"tck"})
1750     public void test_minusWeeks_zero() {
1751         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1752         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1753         ZonedDateTime test = base.minusWeeks(0);
1754         assertEquals(test, base);
1755     }
1756 
1757     //-----------------------------------------------------------------------
1758     // minusDays()
1759     //-----------------------------------------------------------------------
1760     @Test(groups={"tck"}, dataProvider="plusDays")
1761     public void test_minusDays(ZonedDateTime base, long amount, ZonedDateTime expected) {
1762         assertEquals(base.minusDays(-amount), expected);
1763     }
1764 
1765     //-----------------------------------------------------------------------
1766     // minusHours()
1767     //-----------------------------------------------------------------------
1768     @Test(groups={"tck"}, dataProvider="plusTime")
1769     public void test_minusHours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1770         assertEquals(base.minusHours(-amount), expected);
1771     }
1772 
1773     //-----------------------------------------------------------------------
1774     // minusMinutes()
1775     //-----------------------------------------------------------------------
1776     @Test(groups={"tck"}, dataProvider="plusTime")
1777     public void test_minusMinutes(ZonedDateTime base, long amount, ZonedDateTime expected) {
1778         assertEquals(base.minusMinutes(-amount * 60), expected);
1779     }
1780 
1781     @Test(groups={"tck"})
1782     public void test_minusMinutes_minutes() {
1783         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1784         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1785         ZonedDateTime test = base.minusMinutes(30);
1786         assertEquals(test, ZonedDateTime.of(ldt.minusMinutes(30), ZONE_0100));
1787     }
1788 
1789     //-----------------------------------------------------------------------
1790     // minusSeconds()
1791     //-----------------------------------------------------------------------
1792     @Test(groups={"tck"}, dataProvider="plusTime")
1793     public void test_minusSeconds(ZonedDateTime base, long amount, ZonedDateTime expected) {
1794         assertEquals(base.minusSeconds(-amount * 3600), expected);
1795     }
1796 
1797     @Test(groups={"tck"})
1798     public void test_minusSeconds_seconds() {
1799         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1800         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1801         ZonedDateTime test = base.minusSeconds(1);
1802         assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
1803     }
1804 
1805     //-----------------------------------------------------------------------
1806     // minusNanos()
1807     //-----------------------------------------------------------------------
1808     @Test(groups={"tck"}, dataProvider="plusTime")
1809     public void test_minusNanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
1810         assertEquals(base.minusNanos(-amount * 3600_000_000_000L), expected);
1811     }
1812 
1813     @Test(groups={"tck"})
1814     public void test_minusNanos_nanos() {
1815         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1816         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1817         ZonedDateTime test = base.minusNanos(1);
1818         assertEquals(test, ZonedDateTime.of(ldt.minusNanos(1), ZONE_0100));
1819     }
1820 
1821     //-----------------------------------------------------------------------
1822     // periodUntil(Temporal,TemporalUnit)
1823     //-----------------------------------------------------------------------
1824     // TODO: more tests for period between two different zones
1825     // compare results to OffsetDateTime.periodUntil, especially wrt dates
1826 
1827     @Test(groups={"tck"}, dataProvider="plusDays")
1828     public void test_periodUntil_days(ZonedDateTime base, long expected, ZonedDateTime end) {
1829         assertEquals(base.periodUntil(end, DAYS), expected);
1830     }
1831 
1832     @Test(groups={"tck"}, dataProvider="plusTime")
1833     public void test_periodUntil_hours(ZonedDateTime base, long expected, ZonedDateTime end) {
1834         assertEquals(base.periodUntil(end, HOURS), expected);
1835     }
1836 
1837     @Test(groups={"tck"}, dataProvider="plusTime")
1838     public void test_periodUntil_minutes(ZonedDateTime base, long expected, ZonedDateTime end) {
1839         assertEquals(base.periodUntil(end, MINUTES), expected * 60);
1840     }
1841 
1842     @Test(groups={"tck"}, dataProvider="plusTime")
1843     public void test_periodUntil_seconds(ZonedDateTime base, long expected, ZonedDateTime end) {
1844         assertEquals(base.periodUntil(end, SECONDS), expected * 3600);
1845     }
1846 
1847     @Test(groups={"tck"}, dataProvider="plusTime")
1848     public void test_periodUntil_nanos(ZonedDateTime base, long expected, ZonedDateTime end) {
1849         assertEquals(base.periodUntil(end, NANOS), expected * 3600_000_000_000L);
1850     }
1851 
1852     @Test(groups={"tck"})
1853     public void test_periodUntil_parisLondon() {
1854         ZonedDateTime midnightLondon = LocalDate.of(2012, 6, 28).atStartOfDay(ZONE_LONDON);
1855         ZonedDateTime midnightParis1 = LocalDate.of(2012, 6, 29).atStartOfDay(ZONE_PARIS);
1856         ZonedDateTime oneAm1 = LocalDateTime.of(2012, 6, 29, 1, 0).atZone(ZONE_PARIS);
1857         ZonedDateTime midnightParis2 = LocalDate.of(2012, 6, 30).atStartOfDay(ZONE_PARIS);
1858 
1859         assertEquals(midnightLondon.periodUntil(midnightParis1, HOURS), 23);
1860         assertEquals(midnightLondon.periodUntil(oneAm1, HOURS), 24);
1861         assertEquals(midnightLondon.periodUntil(midnightParis2, HOURS), 23 + 24);
1862 
1863         assertEquals(midnightLondon.periodUntil(midnightParis1, DAYS), 0);
1864         assertEquals(midnightLondon.periodUntil(oneAm1, DAYS), 1);
1865         assertEquals(midnightLondon.periodUntil(midnightParis2, DAYS), 1);
1866     }
1867 
1868     @Test(groups={"tck"})
1869     public void test_periodUntil_gap() {
1870         ZonedDateTime before = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
1871         ZonedDateTime after = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
1872 
1873         assertEquals(before.periodUntil(after, HOURS), 23);
1874         assertEquals(before.periodUntil(after, DAYS), 1);
1875     }
1876 
1877     @Test(groups={"tck"})
1878     public void test_periodUntil_overlap() {
1879         ZonedDateTime before = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
1880         ZonedDateTime after = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
1881 
1882         assertEquals(before.periodUntil(after, HOURS), 25);
1883         assertEquals(before.periodUntil(after, DAYS), 1);
1884     }
1885 
1886     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
1887     public void test_periodUntil_differentType() {
1888         TEST_DATE_TIME_PARIS.periodUntil(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
1889     }
1890 
1891     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1892     public void test_periodUntil_nullTemporal() {
1893         TEST_DATE_TIME_PARIS.periodUntil(null, DAYS);
1894     }
1895 
1896     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1897     public void test_periodUntil_nullUnit() {
1898         TEST_DATE_TIME_PARIS.periodUntil(TEST_DATE_TIME_PARIS, null);
1899     }
1900 
1901     //-----------------------------------------------------------------------
1902     // toOffsetDateTime()
1903     //-----------------------------------------------------------------------
1904     @Test(groups={"tck"})
1905     public void test_toOffsetDateTime() {
1906         assertEquals(TEST_DATE_TIME.toOffsetDateTime(), OffsetDateTime.of(TEST_DATE_TIME.toLocalDateTime(), TEST_DATE_TIME.getOffset()));
1907     }
1908 
1909     //-----------------------------------------------------------------------
1910     // toInstant()
1911     //-----------------------------------------------------------------------
1912     @DataProvider(name="toInstant")
1913     Object[][] data_toInstant() {
1914         return new Object[][] {
1915             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0), 0L, 0},
1916             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 1), 0L, 1},
1917             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 999_999_999), 0L, 999_999_999},
1918             {LocalDateTime.of(1970, 1, 1, 0, 0, 1, 0), 1L, 0},
1919             {LocalDateTime.of(1970, 1, 1, 0, 0, 1, 1), 1L, 1},
1920             {LocalDateTime.of(1969, 12, 31, 23, 59, 59, 999999999), -1L, 999_999_999},
1921             {LocalDateTime.of(1970, 1, 2, 0, 0), 24L * 60L * 60L, 0},
1922             {LocalDateTime.of(1969, 12, 31, 0, 0), -24L * 60L * 60L, 0},
1923         };
1924     }
1925 
1926     @Test(groups={"tck"}, dataProvider="toInstant")
1927     public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1928         ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
1929         Instant test = dt.toInstant();
1930         assertEquals(test.getEpochSecond(), expectedEpSec);
1931         assertEquals(test.getNano(), expectedNos);
1932     }
1933 
1934     @Test(groups={"tck"}, dataProvider="toInstant")
1935     public void test_toInstant_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1936         ZonedDateTime dt = ldt.atZone(ZONE_0100);
1937         Instant test = dt.toInstant();
1938         assertEquals(test.getEpochSecond(), expectedEpSec - 3600);
1939         assertEquals(test.getNano(), expectedNos);
1940     }
1941 
1942     @Test(groups={"tck"}, dataProvider="toInstant")
1943     public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1944         ZonedDateTime dt = ldt.atZone(ZONE_M0100);
1945         Instant test = dt.toInstant();
1946         assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
1947         assertEquals(test.getNano(), expectedNos);
1948     }
1949 
1950     //-----------------------------------------------------------------------
1951     // toEpochSecond()
1952     //-----------------------------------------------------------------------
1953     @Test(groups={"tck"})
1954     public void test_toEpochSecond_afterEpoch() {
1955         LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
1956         for (int i = 0; i < 100000; i++) {
1957             ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
1958             assertEquals(a.toEpochSecond(), i);
1959             ldt = ldt.plusSeconds(1);
1960         }
1961     }
1962 
1963     @Test(groups={"tck"})
1964     public void test_toEpochSecond_beforeEpoch() {
1965         LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
1966         for (int i = 0; i < 100000; i++) {
1967             ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
1968             assertEquals(a.toEpochSecond(), -i);
1969             ldt = ldt.minusSeconds(1);
1970         }
1971     }
1972 
1973     @Test(groups={"tck"}, dataProvider="toInstant")
1974     public void test_toEpochSecond_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1975         ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
1976         assertEquals(dt.toEpochSecond(), expectedEpSec);
1977     }
1978 
1979     @Test(groups={"tck"}, dataProvider="toInstant")
1980     public void test_toEpochSecond_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1981         ZonedDateTime dt = ldt.atZone(ZONE_0100);
1982         assertEquals(dt.toEpochSecond(), expectedEpSec - 3600);
1983     }
1984 
1985     @Test(groups={"tck"}, dataProvider="toInstant")
1986     public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1987         ZonedDateTime dt = ldt.atZone(ZONE_M0100);
1988         assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
1989     }
1990 
1991     //-----------------------------------------------------------------------
1992     // compareTo()
1993     //-----------------------------------------------------------------------
1994     @Test(groups={"tck"})
1995     public void test_compareTo_time1() {
1996         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 39, 0, ZONE_0100);
1997         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 41, 0, ZONE_0100);  // a is before b due to time
1998         assertEquals(a.compareTo(b) < 0, true);
1999         assertEquals(b.compareTo(a) > 0, true);
2000         assertEquals(a.compareTo(a) == 0, true);
2001         assertEquals(b.compareTo(b) == 0, true);
2002     }
2003 
2004     @Test(groups={"tck"})
2005     public void test_compareTo_time2() {
2006         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 4, ZONE_0100);
2007         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 5, ZONE_0100);  // a is before b due to time
2008         assertEquals(a.compareTo(b) < 0, true);
2009         assertEquals(b.compareTo(a) > 0, true);
2010         assertEquals(a.compareTo(a) == 0, true);
2011         assertEquals(b.compareTo(b) == 0, true);
2012     }
2013 
2014     @Test(groups={"tck"})
2015     public void test_compareTo_offset1() {
2016         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 41, 0, ZONE_0200);
2017         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 39, 0, ZONE_0100);  // a is before b due to offset
2018         assertEquals(a.compareTo(b) < 0, true);
2019         assertEquals(b.compareTo(a) > 0, true);
2020         assertEquals(a.compareTo(a) == 0, true);
2021         assertEquals(b.compareTo(b) == 0, true);
2022     }
2023 
2024     @Test(groups={"tck"})
2025     public void test_compareTo_offset2() {
2026         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 5, ZoneId.of("UTC+01:01"));
2027         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 4, ZONE_0100);  // a is before b due to offset
2028         assertEquals(a.compareTo(b) < 0, true);
2029         assertEquals(b.compareTo(a) > 0, true);
2030         assertEquals(a.compareTo(a) == 0, true);
2031         assertEquals(b.compareTo(b) == 0, true);
2032     }
2033 
2034     @Test(groups={"tck"})
2035     public void test_compareTo_both() {
2036         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 50, 0, 0, ZONE_0200);
2037         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 20, 0, 0, ZONE_0100);  // a is before b on instant scale
2038         assertEquals(a.compareTo(b) < 0, true);
2039         assertEquals(b.compareTo(a) > 0, true);
2040         assertEquals(a.compareTo(a) == 0, true);
2041         assertEquals(b.compareTo(b) == 0, true);
2042     }
2043 
2044     @Test(groups={"tck"})
2045     public void test_compareTo_bothNanos() {
2046         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 20, 40, 5, ZONE_0200);
2047         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 10, 20, 40, 6, ZONE_0100);  // a is before b on instant scale
2048         assertEquals(a.compareTo(b) < 0, true);
2049         assertEquals(b.compareTo(a) > 0, true);
2050         assertEquals(a.compareTo(a) == 0, true);
2051         assertEquals(b.compareTo(b) == 0, true);
2052     }
2053 
2054     @Test(groups={"tck"})
2055     public void test_compareTo_hourDifference() {
2056         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 10, 0, 0, 0, ZONE_0100);
2057         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 0, 0, 0, ZONE_0200);  // a is before b despite being same time-line time
2058         assertEquals(a.compareTo(b) < 0, true);
2059         assertEquals(b.compareTo(a) > 0, true);
2060         assertEquals(a.compareTo(a) == 0, true);
2061         assertEquals(b.compareTo(b) == 0, true);
2062     }
2063 
2064     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2065     public void test_compareTo_null() {
2066         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
2067         a.compareTo(null);
2068     }
2069 
2070     //-----------------------------------------------------------------------
2071     // isBefore()
2072     //-----------------------------------------------------------------------
2073     @DataProvider(name="IsBefore")
2074     Object[][] data_isBefore() {
2075         return new Object[][] {
2076             {11, 30, ZONE_0100, 11, 31, ZONE_0100, true}, // a is before b due to time
2077             {11, 30, ZONE_0200, 11, 30, ZONE_0100, true}, // a is before b due to offset
2078             {11, 30, ZONE_0200, 10, 30, ZONE_0100, false}, // a is equal b due to same instant
2079         };
2080     }
2081 
2082     @Test(dataProvider="IsBefore", groups={"tck"})
2083     public void test_isBefore(int hour1, int minute1, ZoneId zone1, int hour2, int minute2, ZoneId zone2, boolean expected) {
2084         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, hour1, minute1, 0, 0, zone1);
2085         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, hour2, minute2, 0, 0, zone2);
2086         assertEquals(a.isBefore(b), expected);
2087         assertEquals(b.isBefore(a), false);
2088         assertEquals(a.isBefore(a), false);
2089         assertEquals(b.isBefore(b), false);
2090     }
2091 
2092     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2093     public void test_isBefore_null() {
2094         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
2095         a.isBefore(null);
2096     }
2097 
2098     //-----------------------------------------------------------------------
2099     // isAfter()
2100     //-----------------------------------------------------------------------
2101     @DataProvider(name="IsAfter")
2102     Object[][] data_isAfter() {
2103         return new Object[][] {
2104             {11, 31, ZONE_0100, 11, 30, ZONE_0100, true}, // a is after b due to time
2105             {11, 30, ZONE_0100, 11, 30, ZONE_0200, true}, // a is after b due to offset
2106             {11, 30, ZONE_0200, 10, 30, ZONE_0100, false}, // a is equal b due to same instant
2107         };
2108     }
2109 
2110     @Test(dataProvider="IsAfter", groups={"tck"})
2111     public void test_isAfter(int hour1, int minute1, ZoneId zone1, int hour2, int minute2, ZoneId zone2, boolean expected) {
2112         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, hour1, minute1, 0, 0, zone1);
2113         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, hour2, minute2, 0, 0, zone2);
2114         assertEquals(a.isAfter(b), expected);
2115         assertEquals(b.isAfter(a), false);
2116         assertEquals(a.isAfter(a), false);
2117         assertEquals(b.isAfter(b), false);
2118     }
2119 
2120     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2121     public void test_isAfter_null() {
2122         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
2123         a.isAfter(null);
2124     }
2125 
2126     //-----------------------------------------------------------------------
2127     // equals() / hashCode()
2128     //-----------------------------------------------------------------------
2129     @Test(dataProvider="sampleTimes", groups={"tck"})
2130     public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2131         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2132         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2133         assertEquals(a.equals(b), true);
2134         assertEquals(a.hashCode() == b.hashCode(), true);
2135     }
2136     @Test(dataProvider="sampleTimes", groups={"tck"})
2137     public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2138         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2139         ZonedDateTime b = ZonedDateTime.of(dateTime(y + 1, o, d, h, m, s, n), ZONE_0100);
2140         assertEquals(a.equals(b), false);
2141     }
2142     @Test(dataProvider="sampleTimes", groups={"tck"})
2143     public void test_equals_false_hour_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2144         h = (h == 23 ? 22 : h);
2145         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2146         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h + 1, m, s, n), ZONE_0100);
2147         assertEquals(a.equals(b), false);
2148     }
2149     @Test(dataProvider="sampleTimes", groups={"tck"})
2150     public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2151         m = (m == 59 ? 58 : m);
2152         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2153         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m + 1, s, n), ZONE_0100);
2154         assertEquals(a.equals(b), false);
2155     }
2156     @Test(dataProvider="sampleTimes", groups={"tck"})
2157     public void test_equals_false_second_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2158         s = (s == 59 ? 58 : s);
2159         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2160         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s + 1, n), ZONE_0100);
2161         assertEquals(a.equals(b), false);
2162     }
2163     @Test(dataProvider="sampleTimes", groups={"tck"})
2164     public void test_equals_false_nano_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2165         n = (n == 999999999 ? 999999998 : n);
2166         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2167         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n + 1), ZONE_0100);
2168         assertEquals(a.equals(b), false);
2169     }
2170     @Test(dataProvider="sampleTimes", groups={"tck"})
2171     public void test_equals_false_offset_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2172         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2173         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0200);
2174         assertEquals(a.equals(b), false);
2175     }
2176 
2177     @Test(groups={"tck"})
2178     public void test_equals_itself_true() {
2179         assertEquals(TEST_DATE_TIME.equals(TEST_DATE_TIME), true);
2180     }
2181 
2182     @Test(groups={"tck"})
2183     public void test_equals_string_false() {
2184         assertEquals(TEST_DATE_TIME.equals("2007-07-15"), false);
2185     }
2186 
2187     //-----------------------------------------------------------------------
2188     // toString()
2189     //-----------------------------------------------------------------------
2190     @DataProvider(name="sampleToString")
2191     Object[][] provider_sampleToString() {
2192         return new Object[][] {
2193             {2008, 6, 30, 11, 30, 59, 0, "Z", "2008-06-30T11:30:59Z"},
2194             {2008, 6, 30, 11, 30, 59, 0, "+01:00", "2008-06-30T11:30:59+01:00"},
2195             {2008, 6, 30, 11, 30, 59, 999000000, "Z", "2008-06-30T11:30:59.999Z"},
2196             {2008, 6, 30, 11, 30, 59, 999000000, "+01:00", "2008-06-30T11:30:59.999+01:00"},
2197             {2008, 6, 30, 11, 30, 59, 999000, "Z", "2008-06-30T11:30:59.000999Z"},
2198             {2008, 6, 30, 11, 30, 59, 999000, "+01:00", "2008-06-30T11:30:59.000999+01:00"},
2199             {2008, 6, 30, 11, 30, 59, 999, "Z", "2008-06-30T11:30:59.000000999Z"},
2200             {2008, 6, 30, 11, 30, 59, 999, "+01:00", "2008-06-30T11:30:59.000000999+01:00"},
2201 
2202             {2008, 6, 30, 11, 30, 59, 999, "Europe/London", "2008-06-30T11:30:59.000000999+01:00[Europe/London]"},
2203             {2008, 6, 30, 11, 30, 59, 999, "Europe/Paris", "2008-06-30T11:30:59.000000999+02:00[Europe/Paris]"},
2204         };
2205     }
2206 
2207     @Test(dataProvider="sampleToString", groups={"tck"})
2208     public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
2209         ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
2210         String str = t.toString();
2211         assertEquals(str, expected);
2212     }
2213 
2214     //-----------------------------------------------------------------------
2215     // toString(DateTimeFormatter)
2216     //-----------------------------------------------------------------------
2217     @Test(groups={"tck"})
2218     public void test_toString_formatter() {
2219         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
2220         String t = ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).toString(f);
2221         assertEquals(t, "2010 12 3 11 30 0");
2222     }
2223 
2224     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2225     public void test_toString_formatter_null() {
2226         ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).toString(null);
2227     }
2228 
2229     //-------------------------------------------------------------------------
2230     private static LocalDateTime dateTime(
2231             int year, int month, int dayOfMonth,
2232             int hour, int minute) {
2233         return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
2234     }
2235 
2236     private static LocalDateTime dateTime(
2237                     int year, int month, int dayOfMonth,
2238                     int hour, int minute, int second, int nanoOfSecond) {
2239                 return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
2240             }
2241 
2242     private static ZonedDateTime dateTime(
2243             int year, int month, int dayOfMonth,
2244             int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset, ZoneId zoneId) {
2245         return ZonedDateTime.ofStrict(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond), offset, zoneId);
2246     }
2247 
2248 }