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 static java.time.Month.DECEMBER;
  63 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
  64 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
  65 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
  66 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
  67 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  68 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  69 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  70 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  71 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  72 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  73 import static java.time.temporal.ChronoField.EPOCH_DAY;
  74 import static java.time.temporal.ChronoField.EPOCH_MONTH;
  75 import static java.time.temporal.ChronoField.ERA;
  76 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  77 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  78 import static java.time.temporal.ChronoField.INSTANT_SECONDS;
  79 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  80 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  81 import static java.time.temporal.ChronoField.MILLI_OF_DAY;
  82 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  83 import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
  84 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
  85 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  86 import static java.time.temporal.ChronoField.NANO_OF_DAY;
  87 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  88 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
  89 import static java.time.temporal.ChronoField.SECOND_OF_DAY;
  90 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  91 import static java.time.temporal.ChronoField.YEAR;
  92 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  93 import static java.time.temporal.ChronoUnit.DAYS;
  94 import static java.time.temporal.ChronoUnit.NANOS;
  95 import static java.time.temporal.ChronoUnit.SECONDS;
  96 import static org.testng.Assert.assertEquals;
  97 import static org.testng.Assert.assertTrue;
  98 
  99 import java.io.ByteArrayOutputStream;
 100 import java.io.DataOutputStream;
 101 import java.lang.reflect.Constructor;
 102 import java.lang.reflect.InvocationTargetException;
 103 import java.time.Clock;
 104 import java.time.DateTimeException;
 105 import java.time.Duration;
 106 import java.time.Instant;
 107 import java.time.LocalDate;
 108 import java.time.LocalDateTime;
 109 import java.time.LocalTime;
 110 import java.time.Month;
 111 import java.time.OffsetDateTime;
 112 import java.time.OffsetTime;
 113 import java.time.Year;
 114 import java.time.ZoneId;
 115 import java.time.ZoneOffset;
 116 import java.time.ZonedDateTime;
 117 import java.time.chrono.IsoChronology;
 118 import java.time.format.DateTimeFormatter;
 119 import java.time.format.DateTimeParseException;
 120 import java.time.temporal.ChronoField;
 121 import java.time.temporal.ChronoUnit;
 122 import java.time.temporal.JulianFields;
 123 import java.time.temporal.Queries;
 124 import java.time.temporal.Temporal;
 125 import java.time.temporal.TemporalAccessor;
 126 import java.time.temporal.TemporalAdjuster;
 127 import java.time.temporal.TemporalField;
 128 import java.time.temporal.TemporalQuery;
 129 import java.util.ArrayList;
 130 import java.util.Arrays;
 131 import java.util.List;
 132 
 133 import org.testng.annotations.BeforeMethod;
 134 import org.testng.annotations.DataProvider;
 135 import org.testng.annotations.Test;
 136 import test.java.time.MockSimplePeriod;
 137 
 138 /**
 139  * Test OffsetDateTime.
 140  */
 141 @Test
 142 public class TCKOffsetDateTime extends AbstractDateTimeTest {
 143 
 144     private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
 145     private static final ZoneId ZONE_GAZA = ZoneId.of("Asia/Gaza");
 146     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 147     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 148     private static final ZoneOffset OFFSET_MONE = ZoneOffset.ofHours(-1);
 149     private static final ZoneOffset OFFSET_MTWO = ZoneOffset.ofHours(-2);
 150     private OffsetDateTime TEST_2008_6_30_11_30_59_000000500;
 151 
 152     @BeforeMethod(groups={"tck","implementation"})
 153     public void setUp() {
 154         TEST_2008_6_30_11_30_59_000000500 = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE);
 155     }
 156 
 157     //-----------------------------------------------------------------------
 158     @Override
 159     protected List<TemporalAccessor> samples() {
 160         TemporalAccessor[] array = {TEST_2008_6_30_11_30_59_000000500, OffsetDateTime.MIN, OffsetDateTime.MAX};
 161         return Arrays.asList(array);
 162     }
 163 
 164     @Override
 165     protected List<TemporalField> validFields() {
 166         TemporalField[] array = {
 167             NANO_OF_SECOND,
 168             NANO_OF_DAY,
 169             MICRO_OF_SECOND,
 170             MICRO_OF_DAY,
 171             MILLI_OF_SECOND,
 172             MILLI_OF_DAY,
 173             SECOND_OF_MINUTE,
 174             SECOND_OF_DAY,
 175             MINUTE_OF_HOUR,
 176             MINUTE_OF_DAY,
 177             CLOCK_HOUR_OF_AMPM,
 178             HOUR_OF_AMPM,
 179             CLOCK_HOUR_OF_DAY,
 180             HOUR_OF_DAY,
 181             AMPM_OF_DAY,
 182             DAY_OF_WEEK,
 183             ALIGNED_DAY_OF_WEEK_IN_MONTH,
 184             ALIGNED_DAY_OF_WEEK_IN_YEAR,
 185             DAY_OF_MONTH,
 186             DAY_OF_YEAR,
 187             EPOCH_DAY,
 188             ALIGNED_WEEK_OF_MONTH,
 189             ALIGNED_WEEK_OF_YEAR,
 190             MONTH_OF_YEAR,
 191             EPOCH_MONTH,
 192             YEAR_OF_ERA,
 193             YEAR,
 194             ERA,
 195             OFFSET_SECONDS,
 196             INSTANT_SECONDS,
 197             JulianFields.JULIAN_DAY,
 198             JulianFields.MODIFIED_JULIAN_DAY,
 199             JulianFields.RATA_DIE,
 200         };
 201         return Arrays.asList(array);
 202     }
 203 
 204     @Override
 205     protected List<TemporalField> invalidFields() {
 206         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 207         list.removeAll(validFields());
 208         return list;
 209     }
 210 
 211     //-----------------------------------------------------------------------
 212     @Test
 213     public void test_serialization() throws Exception {
 214         assertSerializable(TEST_2008_6_30_11_30_59_000000500);
 215         assertSerializable(OffsetDateTime.MIN);
 216         assertSerializable(OffsetDateTime.MAX);
 217     }
 218 
 219     @Test
 220     public void test_serialization_format() throws Exception {
 221         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 222         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 223             dos.writeByte(10);       // java.time.Ser.OFFSET_DATE_TIME_TYPE
 224         }
 225         byte[] bytes = baos.toByteArray();
 226         ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream();
 227         try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) {
 228             dos.writeByte(5);
 229             dos.writeInt(2012);
 230             dos.writeByte(9);
 231             dos.writeByte(16);
 232             dos.writeByte(22);
 233             dos.writeByte(17);
 234             dos.writeByte(59);
 235             dos.writeInt(464_000_000);
 236         }
 237         byte[] bytesDateTime = baosDateTime.toByteArray();
 238         ByteArrayOutputStream baosOffset = new ByteArrayOutputStream();
 239         try (DataOutputStream dos = new DataOutputStream(baosOffset) ) {
 240             dos.writeByte(8);
 241             dos.writeByte(4);  // quarter hours stored: 3600 / 900
 242         }
 243         byte[] bytesOffset = baosOffset.toByteArray();
 244         LocalDateTime ldt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 464_000_000);
 245         assertSerializedBySer(OffsetDateTime.of(ldt, ZoneOffset.ofHours(1)), bytes, bytesDateTime, bytesOffset);
 246     }
 247 
 248     //-----------------------------------------------------------------------
 249     // constants
 250     //-----------------------------------------------------------------------
 251     @Test
 252     public void constant_MIN() {
 253         check(OffsetDateTime.MIN, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, ZoneOffset.MAX);
 254     }
 255 
 256     @Test
 257     public void constant_MAX() {
 258         check(OffsetDateTime.MAX, Year.MAX_VALUE, 12, 31, 23, 59, 59, 999999999, ZoneOffset.MIN);
 259     }
 260 
 261     //-----------------------------------------------------------------------
 262     // now()
 263     //-----------------------------------------------------------------------
 264     @Test(groups={"tck"})
 265     public void now() {
 266         OffsetDateTime expected = OffsetDateTime.now(Clock.systemDefaultZone());
 267         OffsetDateTime test = OffsetDateTime.now();
 268         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 269         if (diff >= 100000000) {
 270             // may be date change
 271             expected = OffsetDateTime.now(Clock.systemDefaultZone());
 272             test = OffsetDateTime.now();
 273             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 274         }
 275         assertTrue(diff < 100000000);  // less than 0.1 secs
 276     }
 277 
 278     //-----------------------------------------------------------------------
 279     // now(Clock)
 280     //-----------------------------------------------------------------------
 281     @Test(groups={"tck"})
 282     public void now_Clock_allSecsInDay_utc() {
 283         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 284             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 285             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 286             OffsetDateTime test = OffsetDateTime.now(clock);
 287             assertEquals(test.getYear(), 1970);
 288             assertEquals(test.getMonth(), Month.JANUARY);
 289             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
 290             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 291             assertEquals(test.getMinute(), (i / 60) % 60);
 292             assertEquals(test.getSecond(), i % 60);
 293             assertEquals(test.getNano(), 123456789);
 294             assertEquals(test.getOffset(), ZoneOffset.UTC);
 295         }
 296     }
 297 
 298     @Test(groups={"tck"})
 299     public void now_Clock_allSecsInDay_offset() {
 300         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 301             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 302             Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
 303             OffsetDateTime test = OffsetDateTime.now(clock);
 304             assertEquals(test.getYear(), 1970);
 305             assertEquals(test.getMonth(), Month.JANUARY);
 306             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
 307             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 308             assertEquals(test.getMinute(), (i / 60) % 60);
 309             assertEquals(test.getSecond(), i % 60);
 310             assertEquals(test.getNano(), 123456789);
 311             assertEquals(test.getOffset(), OFFSET_PONE);
 312         }
 313     }
 314 
 315     @Test(groups={"tck"})
 316     public void now_Clock_allSecsInDay_beforeEpoch() {
 317         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 318         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 319             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 320             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 321             OffsetDateTime test = OffsetDateTime.now(clock);
 322             assertEquals(test.getYear(), 1969);
 323             assertEquals(test.getMonth(), Month.DECEMBER);
 324             assertEquals(test.getDayOfMonth(), 31);
 325             expected = expected.minusSeconds(1);
 326             assertEquals(test.toLocalTime(), expected);
 327             assertEquals(test.getOffset(), ZoneOffset.UTC);
 328         }
 329     }
 330 
 331     @Test(groups={"tck"})
 332     public void now_Clock_offsets() {
 333         OffsetDateTime base = OffsetDateTime.of(1970, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC);
 334         for (int i = -9; i < 15; i++) {
 335             ZoneOffset offset = ZoneOffset.ofHours(i);
 336             Clock clock = Clock.fixed(base.toInstant(), offset);
 337             OffsetDateTime test = OffsetDateTime.now(clock);
 338             assertEquals(test.getHour(), (12 + i) % 24);
 339             assertEquals(test.getMinute(), 0);
 340             assertEquals(test.getSecond(), 0);
 341             assertEquals(test.getNano(), 0);
 342             assertEquals(test.getOffset(), offset);
 343         }
 344     }
 345 
 346     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 347     public void now_Clock_nullZoneId() {
 348         OffsetDateTime.now((ZoneId) null);
 349     }
 350 
 351     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 352     public void now_Clock_nullClock() {
 353         OffsetDateTime.now((Clock) null);
 354     }
 355 
 356     //-----------------------------------------------------------------------
 357     private void check(OffsetDateTime test, int y, int mo, int d, int h, int m, int s, int n, ZoneOffset offset) {
 358         assertEquals(test.getYear(), y);
 359         assertEquals(test.getMonth().getValue(), mo);
 360         assertEquals(test.getDayOfMonth(), d);
 361         assertEquals(test.getHour(), h);
 362         assertEquals(test.getMinute(), m);
 363         assertEquals(test.getSecond(), s);
 364         assertEquals(test.getNano(), n);
 365         assertEquals(test.getOffset(), offset);
 366         assertEquals(test, test);
 367         assertEquals(test.hashCode(), test.hashCode());
 368         assertEquals(OffsetDateTime.of(LocalDateTime.of(y, mo, d, h, m, s, n), offset), test);
 369     }
 370 
 371     //-----------------------------------------------------------------------
 372     // factories
 373     //-----------------------------------------------------------------------
 374     @Test(groups={"tck"})
 375     public void factory_of_intsHMSN() {
 376         OffsetDateTime test = OffsetDateTime.of(2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 377         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 378     }
 379 
 380     //-----------------------------------------------------------------------
 381     @Test(groups={"tck"})
 382     public void factory_of_LocalDateLocalTimeZoneOffset() {
 383         LocalDate date = LocalDate.of(2008, 6, 30);
 384         LocalTime time = LocalTime.of(11, 30, 10, 500);
 385         OffsetDateTime test = OffsetDateTime.of(date, time, OFFSET_PONE);
 386         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 387     }
 388 
 389     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 390     public void factory_of_LocalDateLocalTimeZoneOffset_nullLocalDate() {
 391         LocalTime time = LocalTime.of(11, 30, 10, 500);
 392         OffsetDateTime.of((LocalDate) null, time, OFFSET_PONE);
 393     }
 394 
 395     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 396     public void factory_of_LocalDateLocalTimeZoneOffset_nullLocalTime() {
 397         LocalDate date = LocalDate.of(2008, 6, 30);
 398         OffsetDateTime.of(date, (LocalTime) null, OFFSET_PONE);
 399     }
 400 
 401     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 402     public void factory_of_LocalDateLocalTimeZoneOffset_nullOffset() {
 403         LocalDate date = LocalDate.of(2008, 6, 30);
 404         LocalTime time = LocalTime.of(11, 30, 10, 500);
 405         OffsetDateTime.of(date, time, (ZoneOffset) null);
 406     }
 407 
 408     //-----------------------------------------------------------------------
 409     @Test(groups={"tck"})
 410     public void factory_of_LocalDateTimeZoneOffset() {
 411         LocalDateTime dt = LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500));
 412         OffsetDateTime test = OffsetDateTime.of(dt, OFFSET_PONE);
 413         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 414     }
 415 
 416     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 417     public void factory_of_LocalDateTimeZoneOffset_nullProvider() {
 418         OffsetDateTime.of((LocalDateTime) null, OFFSET_PONE);
 419     }
 420 
 421     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 422     public void factory_of_LocalDateTimeZoneOffset_nullOffset() {
 423         LocalDateTime dt = LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500));
 424         OffsetDateTime.of(dt, (ZoneOffset) null);
 425     }
 426 
 427     //-----------------------------------------------------------------------
 428     // from()
 429     //-----------------------------------------------------------------------
 430     @Test(groups={"tck"})
 431     public void test_factory_CalendricalObject() {
 432         assertEquals(OffsetDateTime.from(
 433                 OffsetDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(17, 30), OFFSET_PONE)),
 434                 OffsetDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(17, 30), OFFSET_PONE));
 435     }
 436 
 437     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 438     public void test_factory_CalendricalObject_invalid_noDerive() {
 439         OffsetDateTime.from(LocalTime.of(12, 30));
 440     }
 441 
 442     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 443     public void test_factory_Calendricals_null() {
 444         OffsetDateTime.from((TemporalAccessor) null);
 445     }
 446 
 447     //-----------------------------------------------------------------------
 448     // parse()
 449     //-----------------------------------------------------------------------
 450     @Test(dataProvider="sampleToString", groups={"tck"})
 451     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String offsetId, String text) {
 452         OffsetDateTime t = OffsetDateTime.parse(text);
 453         assertEquals(t.getYear(), y);
 454         assertEquals(t.getMonth().getValue(), month);
 455         assertEquals(t.getDayOfMonth(), d);
 456         assertEquals(t.getHour(), h);
 457         assertEquals(t.getMinute(), m);
 458         assertEquals(t.getSecond(), s);
 459         assertEquals(t.getNano(), n);
 460         assertEquals(t.getOffset().getId(), offsetId);
 461     }
 462 
 463     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 464     public void factory_parse_illegalValue() {
 465         OffsetDateTime.parse("2008-06-32T11:15+01:00");
 466     }
 467 
 468     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 469     public void factory_parse_invalidValue() {
 470         OffsetDateTime.parse("2008-06-31T11:15+01:00");
 471     }
 472 
 473     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 474     public void factory_parse_nullText() {
 475         OffsetDateTime.parse((String) null);
 476     }
 477 
 478     //-----------------------------------------------------------------------
 479     // parse(DateTimeFormatter)
 480     //-----------------------------------------------------------------------
 481     @Test(groups={"tck"})
 482     public void factory_parse_formatter() {
 483         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s XXX");
 484         OffsetDateTime test = OffsetDateTime.parse("2010 12 3 11 30 0 +01:00", f);
 485         assertEquals(test, OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), ZoneOffset.ofHours(1)));
 486     }
 487 
 488     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 489     public void factory_parse_formatter_nullText() {
 490         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 491         OffsetDateTime.parse((String) null, f);
 492     }
 493 
 494     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 495     public void factory_parse_formatter_nullFormatter() {
 496         OffsetDateTime.parse("ANY", null);
 497     }
 498 
 499     //-----------------------------------------------------------------------
 500     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 501     public void constructor_nullTime() throws Throwable  {
 502         Constructor<OffsetDateTime> con = OffsetDateTime.class.getDeclaredConstructor(LocalDateTime.class, ZoneOffset.class);
 503         con.setAccessible(true);
 504         try {
 505             con.newInstance(null, OFFSET_PONE);
 506         } catch (InvocationTargetException ex) {
 507             throw ex.getCause();
 508         }
 509     }
 510 
 511     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 512     public void constructor_nullOffset() throws Throwable  {
 513         Constructor<OffsetDateTime> con = OffsetDateTime.class.getDeclaredConstructor(LocalDateTime.class, ZoneOffset.class);
 514         con.setAccessible(true);
 515         try {
 516             con.newInstance(LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30)), null);
 517         } catch (InvocationTargetException ex) {
 518             throw ex.getCause();
 519         }
 520     }
 521 
 522     //-----------------------------------------------------------------------
 523     // basics
 524     //-----------------------------------------------------------------------
 525     @DataProvider(name="sampleTimes")
 526     Object[][] provider_sampleTimes() {
 527         return new Object[][] {
 528             {2008, 6, 30, 11, 30, 20, 500, OFFSET_PONE},
 529             {2008, 6, 30, 11, 0, 0, 0, OFFSET_PONE},
 530             {2008, 6, 30, 23, 59, 59, 999999999, OFFSET_PONE},
 531             {-1, 1, 1, 0, 0, 0, 0, OFFSET_PONE},
 532         };
 533     }
 534 
 535     @Test(dataProvider="sampleTimes", groups={"tck"})
 536     public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneOffset offset) {
 537         LocalDate localDate = LocalDate.of(y, o, d);
 538         LocalTime localTime = LocalTime.of(h, m, s, n);
 539         LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
 540         OffsetDateTime a = OffsetDateTime.of(localDateTime, offset);
 541 
 542         assertEquals(a.getYear(), localDate.getYear());
 543         assertEquals(a.getMonth(), localDate.getMonth());
 544         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 545         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 546         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 547 
 548         assertEquals(a.getHour(), localDateTime.getHour());
 549         assertEquals(a.getMinute(), localDateTime.getMinute());
 550         assertEquals(a.getSecond(), localDateTime.getSecond());
 551         assertEquals(a.getNano(), localDateTime.getNano());
 552 
 553         assertEquals(a.toOffsetTime(), OffsetTime.of(localTime, offset));
 554         assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 555     }
 556 
 557     //-----------------------------------------------------------------------
 558     // get(TemporalField)
 559     //-----------------------------------------------------------------------
 560     @Test
 561     public void test_get_TemporalField() {
 562         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
 563         assertEquals(test.get(ChronoField.YEAR), 2008);
 564         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 565         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 566         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 567         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 568 
 569         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 570         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 571         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 572         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 573         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 574         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 575 
 576         assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600);
 577     }
 578 
 579     @Test
 580     public void test_getLong_TemporalField() {
 581         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
 582         assertEquals(test.getLong(ChronoField.YEAR), 2008);
 583         assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
 584         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 585         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 586         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 587 
 588         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 589         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 590         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 591         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 592         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 593         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 594 
 595         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
 596         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 597     }
 598 
 599     //-----------------------------------------------------------------------
 600     // query(TemporalQuery)
 601     //-----------------------------------------------------------------------
 602     @DataProvider(name="query")
 603     Object[][] data_query() {
 604         return new Object[][] {
 605                 {TEST_2008_6_30_11_30_59_000000500, Queries.chronology(), IsoChronology.INSTANCE},
 606                 {TEST_2008_6_30_11_30_59_000000500, Queries.zoneId(), null},
 607                 {TEST_2008_6_30_11_30_59_000000500, Queries.precision(), ChronoUnit.NANOS},
 608                 {TEST_2008_6_30_11_30_59_000000500, Queries.zone(), OFFSET_PONE},
 609                 {TEST_2008_6_30_11_30_59_000000500, Queries.offset(), OFFSET_PONE},
 610                 {TEST_2008_6_30_11_30_59_000000500, Queries.localDate(), LocalDate.of(2008, 6, 30)},
 611                 {TEST_2008_6_30_11_30_59_000000500, Queries.localTime(), LocalTime.of(11, 30, 59, 500)},
 612         };
 613     }
 614 
 615     @Test(dataProvider="query")
 616     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 617         assertEquals(temporal.query(query), expected);
 618     }
 619 
 620     @Test(dataProvider="query")
 621     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 622         assertEquals(query.queryFrom(temporal), expected);
 623     }
 624 
 625     @Test(expectedExceptions=NullPointerException.class)
 626     public void test_query_null() {
 627         TEST_2008_6_30_11_30_59_000000500.query(null);
 628     }
 629 
 630     //-----------------------------------------------------------------------
 631     // with(WithAdjuster)
 632     //-----------------------------------------------------------------------
 633     @Test(groups={"tck"})
 634     public void test_with_adjustment() {
 635         final OffsetDateTime sample = OffsetDateTime.of(LocalDate.of(2012, 3, 4), LocalTime.of(23, 5), OFFSET_PONE);
 636         TemporalAdjuster adjuster = new TemporalAdjuster() {
 637             @Override
 638             public Temporal adjustInto(Temporal dateTime) {
 639                 return sample;
 640             }
 641         };
 642         assertEquals(TEST_2008_6_30_11_30_59_000000500.with(adjuster), sample);
 643     }
 644 
 645     @Test(groups={"tck"})
 646     public void test_with_adjustment_LocalDate() {
 647         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalDate.of(2012, 9, 3));
 648         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 649     }
 650 
 651     @Test(groups={"tck"})
 652     public void test_with_adjustment_LocalTime() {
 653         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalTime.of(19, 15));
 654         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(19, 15), OFFSET_PONE));
 655     }
 656 
 657     @Test(groups={"tck"})
 658     public void test_with_adjustment_LocalDateTime() {
 659         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15)));
 660         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PONE));
 661     }
 662 
 663     @Test(groups={"tck"})
 664     public void test_with_adjustment_OffsetTime() {
 665         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetTime.of(LocalTime.of(19, 15), OFFSET_PTWO));
 666         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(19, 15), OFFSET_PTWO));
 667     }
 668 
 669     @Test(groups={"tck"})
 670     public void test_with_adjustment_OffsetDateTime() {
 671         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PTWO));
 672         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PTWO));
 673     }
 674 
 675     @Test(groups={"tck"})
 676     public void test_with_adjustment_Month() {
 677         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(DECEMBER);
 678         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 12, 30),LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 679     }
 680 
 681     @Test(groups={"tck"})
 682     public void test_with_adjustment_ZoneOffset() {
 683         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OFFSET_PTWO);
 684         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PTWO));
 685     }
 686 
 687     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 688     public void test_with_adjustment_null() {
 689         TEST_2008_6_30_11_30_59_000000500.with((TemporalAdjuster) null);
 690     }
 691 
 692     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 693     public void test_withOffsetSameLocal_null() {
 694         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 695         base.withOffsetSameLocal(null);
 696     }
 697 
 698     //-----------------------------------------------------------------------
 699     // withOffsetSameInstant()
 700     //-----------------------------------------------------------------------
 701     @Test(groups={"tck"})
 702     public void test_withOffsetSameInstant() {
 703         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 704         OffsetDateTime test = base.withOffsetSameInstant(OFFSET_PTWO);
 705         OffsetDateTime expected = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 59), OFFSET_PTWO);
 706         assertEquals(test, expected);
 707     }
 708 
 709     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 710     public void test_withOffsetSameInstant_null() {
 711         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 712         base.withOffsetSameInstant(null);
 713     }
 714 
 715     //-----------------------------------------------------------------------
 716     // withYear()
 717     //-----------------------------------------------------------------------
 718     @Test(groups={"tck"})
 719     public void test_withYear_normal() {
 720         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 721         OffsetDateTime test = base.withYear(2007);
 722         assertEquals(test, OffsetDateTime.of(LocalDate.of(2007, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
 723     }
 724 
 725     //-----------------------------------------------------------------------
 726     // withMonth()
 727     //-----------------------------------------------------------------------
 728     @Test(groups={"tck"})
 729     public void test_withMonth_normal() {
 730         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 731         OffsetDateTime test = base.withMonth(1);
 732         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 1, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
 733     }
 734 
 735     //-----------------------------------------------------------------------
 736     // withDayOfMonth()
 737     //-----------------------------------------------------------------------
 738     @Test(groups={"tck"})
 739     public void test_withDayOfMonth_normal() {
 740         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 741         OffsetDateTime test = base.withDayOfMonth(15);
 742         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 15), LocalTime.of(11, 30, 59), OFFSET_PONE));
 743     }
 744 
 745     //-----------------------------------------------------------------------
 746     // withDayOfYear(int)
 747     //-----------------------------------------------------------------------
 748     @Test(groups={"tck"})
 749     public void test_withDayOfYear_normal() {
 750         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.withDayOfYear(33);
 751         assertEquals(t, OffsetDateTime.of(LocalDate.of(2008, 2, 2), LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 752     }
 753 
 754     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 755     public void test_withDayOfYear_illegal() {
 756         TEST_2008_6_30_11_30_59_000000500.withDayOfYear(367);
 757     }
 758 
 759     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 760     public void test_withDayOfYear_invalid() {
 761         OffsetDateTime.of(LocalDate.of(2007, 2, 2), LocalTime.of(11, 30), OFFSET_PONE).withDayOfYear(366);
 762     }
 763 
 764     //-----------------------------------------------------------------------
 765     // withHour()
 766     //-----------------------------------------------------------------------
 767     @Test(groups={"tck"})
 768     public void test_withHour_normal() {
 769         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 770         OffsetDateTime test = base.withHour(15);
 771         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(15, 30, 59), OFFSET_PONE));
 772     }
 773 
 774     //-----------------------------------------------------------------------
 775     // withMinute()
 776     //-----------------------------------------------------------------------
 777     @Test(groups={"tck"})
 778     public void test_withMinute_normal() {
 779         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 780         OffsetDateTime test = base.withMinute(15);
 781         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 15, 59), OFFSET_PONE));
 782     }
 783 
 784     //-----------------------------------------------------------------------
 785     // withSecond()
 786     //-----------------------------------------------------------------------
 787     @Test(groups={"tck"})
 788     public void test_withSecond_normal() {
 789         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 790         OffsetDateTime test = base.withSecond(15);
 791         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 15), OFFSET_PONE));
 792     }
 793 
 794     //-----------------------------------------------------------------------
 795     // withNano()
 796     //-----------------------------------------------------------------------
 797     @Test(groups={"tck"})
 798     public void test_withNanoOfSecond_normal() {
 799         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 1), OFFSET_PONE);
 800         OffsetDateTime test = base.withNano(15);
 801         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 15), OFFSET_PONE));
 802     }
 803 
 804     //-----------------------------------------------------------------------
 805     // truncatedTo(TemporalUnit)
 806     //-----------------------------------------------------------------------
 807     @Test(groups={"tck"})
 808     public void test_truncatedTo_normal() {
 809         assertEquals(TEST_2008_6_30_11_30_59_000000500.truncatedTo(NANOS), TEST_2008_6_30_11_30_59_000000500);
 810         assertEquals(TEST_2008_6_30_11_30_59_000000500.truncatedTo(SECONDS), TEST_2008_6_30_11_30_59_000000500.withNano(0));
 811         assertEquals(TEST_2008_6_30_11_30_59_000000500.truncatedTo(DAYS), TEST_2008_6_30_11_30_59_000000500.with(LocalTime.MIDNIGHT));
 812     }
 813 
 814     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 815     public void test_truncatedTo_null() {
 816         TEST_2008_6_30_11_30_59_000000500.truncatedTo(null);
 817     }
 818 
 819     //-----------------------------------------------------------------------
 820     // plus(Period)
 821     //-----------------------------------------------------------------------
 822     @Test(groups={"tck"})
 823     public void test_plus_Period() {
 824         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
 825         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(period);
 826         assertEquals(t, OffsetDateTime.of(2009, 1, 30, 11, 30, 59, 500, OFFSET_PONE));
 827     }
 828 
 829     //-----------------------------------------------------------------------
 830     // plus(Duration)
 831     //-----------------------------------------------------------------------
 832     @Test(groups={"tck"})
 833     public void test_plus_Duration() {
 834         Duration dur = Duration.ofSeconds(62, 3);
 835         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(dur);
 836         assertEquals(t, OffsetDateTime.of(2008, 6, 30, 11, 32, 1, 503, OFFSET_PONE));
 837     }
 838 
 839     @Test(groups={"tck"})
 840     public void test_plus_Duration_zero() {
 841         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(Duration.ZERO);
 842         assertEquals(t, TEST_2008_6_30_11_30_59_000000500);
 843     }
 844 
 845     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 846     public void test_plus_Duration_null() {
 847         TEST_2008_6_30_11_30_59_000000500.plus((Duration) null);
 848     }
 849 
 850     //-----------------------------------------------------------------------
 851     // plusYears()
 852     //-----------------------------------------------------------------------
 853     @Test(groups={"tck"})
 854     public void test_plusYears() {
 855         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 856         OffsetDateTime test = base.plusYears(1);
 857         assertEquals(test, OffsetDateTime.of(2009, 6, 30, 11, 30, 59, 0, OFFSET_PONE));
 858     }
 859 
 860     //-----------------------------------------------------------------------
 861     // plusMonths()
 862     //-----------------------------------------------------------------------
 863     @Test(groups={"tck"})
 864     public void test_plusMonths() {
 865         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 866         OffsetDateTime test = base.plusMonths(1);
 867         assertEquals(test, OffsetDateTime.of(2008, 7, 30, 11, 30, 59, 0, OFFSET_PONE));
 868     }
 869 
 870     //-----------------------------------------------------------------------
 871     // plusWeeks()
 872     //-----------------------------------------------------------------------
 873     @Test(groups={"tck"})
 874     public void test_plusWeeks() {
 875         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 876         OffsetDateTime test = base.plusWeeks(1);
 877         assertEquals(test, OffsetDateTime.of(2008, 7, 7, 11, 30, 59, 0, OFFSET_PONE));
 878     }
 879 
 880     //-----------------------------------------------------------------------
 881     // plusDays()
 882     //-----------------------------------------------------------------------
 883     @Test(groups={"tck"})
 884     public void test_plusDays() {
 885         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 886         OffsetDateTime test = base.plusDays(1);
 887         assertEquals(test, OffsetDateTime.of(2008, 7, 1, 11, 30, 59, 0, OFFSET_PONE));
 888     }
 889 
 890     //-----------------------------------------------------------------------
 891     // plusHours()
 892     //-----------------------------------------------------------------------
 893     @Test(groups={"tck"})
 894     public void test_plusHours() {
 895         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 896         OffsetDateTime test = base.plusHours(13);
 897         assertEquals(test, OffsetDateTime.of(2008, 7, 1, 0, 30, 59, 0, OFFSET_PONE));
 898     }
 899 
 900     //-----------------------------------------------------------------------
 901     // plusMinutes()
 902     //-----------------------------------------------------------------------
 903     @Test(groups={"tck"})
 904     public void test_plusMinutes() {
 905         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 906         OffsetDateTime test = base.plusMinutes(30);
 907         assertEquals(test, OffsetDateTime.of(2008, 6, 30, 12, 0, 59, 0, OFFSET_PONE));
 908     }
 909 
 910     //-----------------------------------------------------------------------
 911     // plusSeconds()
 912     //-----------------------------------------------------------------------
 913     @Test(groups={"tck"})
 914     public void test_plusSeconds() {
 915         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 916         OffsetDateTime test = base.plusSeconds(1);
 917         assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 31, 0, 0, OFFSET_PONE));
 918     }
 919 
 920     //-----------------------------------------------------------------------
 921     // plusNanos()
 922     //-----------------------------------------------------------------------
 923     @Test(groups={"tck"})
 924     public void test_plusNanos() {
 925         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 926         OffsetDateTime test = base.plusNanos(1);
 927         assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 1, OFFSET_PONE));
 928     }
 929 
 930     //-----------------------------------------------------------------------
 931     // minus(Period)
 932     //-----------------------------------------------------------------------
 933     @Test(groups={"tck"})
 934     public void test_minus_Period() {
 935         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
 936         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(period);
 937         assertEquals(t, OffsetDateTime.of(2007, 11, 30, 11, 30, 59, 500, OFFSET_PONE));
 938     }
 939 
 940     //-----------------------------------------------------------------------
 941     // minus(Duration)
 942     //-----------------------------------------------------------------------
 943     @Test(groups={"tck"})
 944     public void test_minus_Duration() {
 945         Duration dur = Duration.ofSeconds(62, 3);
 946         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(dur);
 947         assertEquals(t, OffsetDateTime.of(2008, 6, 30, 11, 29, 57, 497, OFFSET_PONE));
 948     }
 949 
 950     @Test(groups={"tck"})
 951     public void test_minus_Duration_zero() {
 952         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(Duration.ZERO);
 953         assertEquals(t, TEST_2008_6_30_11_30_59_000000500);
 954     }
 955 
 956     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 957     public void test_minus_Duration_null() {
 958         TEST_2008_6_30_11_30_59_000000500.minus((Duration) null);
 959     }
 960 
 961     //-----------------------------------------------------------------------
 962     // minusYears()
 963     //-----------------------------------------------------------------------
 964     @Test(groups={"tck"})
 965     public void test_minusYears() {
 966         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 967         OffsetDateTime test = base.minusYears(1);
 968         assertEquals(test, OffsetDateTime.of(2007, 6, 30, 11, 30, 59, 0, OFFSET_PONE));
 969     }
 970 
 971     //-----------------------------------------------------------------------
 972     // minusMonths()
 973     //-----------------------------------------------------------------------
 974     @Test(groups={"tck"})
 975     public void test_minusMonths() {
 976         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 977         OffsetDateTime test = base.minusMonths(1);
 978         assertEquals(test, OffsetDateTime.of(2008, 5, 30, 11, 30, 59, 0, OFFSET_PONE));
 979     }
 980 
 981     //-----------------------------------------------------------------------
 982     // minusWeeks()
 983     //-----------------------------------------------------------------------
 984     @Test(groups={"tck"})
 985     public void test_minusWeeks() {
 986         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 987         OffsetDateTime test = base.minusWeeks(1);
 988         assertEquals(test, OffsetDateTime.of(2008, 6, 23, 11, 30, 59, 0, OFFSET_PONE));
 989     }
 990 
 991     //-----------------------------------------------------------------------
 992     // minusDays()
 993     //-----------------------------------------------------------------------
 994     @Test(groups={"tck"})
 995     public void test_minusDays() {
 996         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
 997         OffsetDateTime test = base.minusDays(1);
 998         assertEquals(test, OffsetDateTime.of(2008, 6, 29, 11, 30, 59, 0, OFFSET_PONE));
 999     }
1000 
1001     //-----------------------------------------------------------------------
1002     // minusHours()
1003     //-----------------------------------------------------------------------
1004     @Test(groups={"tck"})
1005     public void test_minusHours() {
1006         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1007         OffsetDateTime test = base.minusHours(13);
1008         assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE));
1009     }
1010 
1011     //-----------------------------------------------------------------------
1012     // minusMinutes()
1013     //-----------------------------------------------------------------------
1014     @Test(groups={"tck"})
1015     public void test_minusMinutes() {
1016         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1017         OffsetDateTime test = base.minusMinutes(30);
1018         assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 0, 59, 0, OFFSET_PONE));
1019     }
1020 
1021     //-----------------------------------------------------------------------
1022     // minusSeconds()
1023     //-----------------------------------------------------------------------
1024     @Test(groups={"tck"})
1025     public void test_minusSeconds() {
1026         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1027         OffsetDateTime test = base.minusSeconds(1);
1028         assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 30, 58, 0, OFFSET_PONE));
1029     }
1030 
1031     //-----------------------------------------------------------------------
1032     // minusNanos()
1033     //-----------------------------------------------------------------------
1034     @Test(groups={"tck"})
1035     public void test_minusNanos() {
1036         OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1037         OffsetDateTime test = base.minusNanos(1);
1038         assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 30, 58, 999999999, OFFSET_PONE));
1039     }
1040 
1041     //-----------------------------------------------------------------------
1042     // atZoneSameInstant()
1043     //-----------------------------------------------------------------------
1044     @Test(groups={"tck"})
1045     public void test_atZone() {
1046         OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_MTWO);
1047         assertEquals(t.atZoneSameInstant(ZONE_PARIS),
1048                 ZonedDateTime.of(2008, 6, 30, 15, 30, 0, 0, ZONE_PARIS));
1049     }
1050 
1051     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1052     public void test_atZone_nullTimeZone() {
1053         OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PTWO);
1054         t.atZoneSameInstant((ZoneId) null);
1055     }
1056 
1057     //-----------------------------------------------------------------------
1058     // atZoneSimilarLocal()
1059     //-----------------------------------------------------------------------
1060     @Test(groups={"tck"})
1061     public void test_atZoneSimilarLocal() {
1062         OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_MTWO);
1063         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS),
1064                 ZonedDateTime.of(2008, 6, 30, 11, 30, 0, 0, ZONE_PARIS));
1065     }
1066 
1067     @Test(groups={"tck"})
1068     public void test_atZoneSimilarLocal_dstGap() {
1069         OffsetDateTime t = OffsetDateTime.of(2007, 4, 1, 0, 0, 0, 0, OFFSET_MTWO);
1070         assertEquals(t.atZoneSimilarLocal(ZONE_GAZA),
1071                 ZonedDateTime.of(2007, 4, 1, 1, 0, 0, 0, ZONE_GAZA));
1072     }
1073 
1074     @Test(groups={"tck"})
1075     public void test_atZone_dstOverlapSummer() {
1076         OffsetDateTime t = OffsetDateTime.of(2007, 10, 28, 2, 30, 0, 0, OFFSET_PTWO);
1077         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).toLocalDateTime(), t.toLocalDateTime());
1078         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PTWO);
1079         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS);
1080     }
1081 
1082     @Test(groups={"tck"})
1083     public void test_atZone_dstOverlapWinter() {
1084         OffsetDateTime t = OffsetDateTime.of(2007, 10, 28, 2, 30, 0, 0, OFFSET_PONE);
1085         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).toLocalDateTime(), t.toLocalDateTime());
1086         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PONE);
1087         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS);
1088     }
1089 
1090     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1091     public void test_atZoneSimilarLocal_nullTimeZone() {
1092         OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PTWO);
1093         t.atZoneSimilarLocal((ZoneId) null);
1094     }
1095 
1096     //-----------------------------------------------------------------------
1097     // toEpochSecond()
1098     //-----------------------------------------------------------------------
1099     @Test(groups={"tck"})
1100     public void test_toEpochSecond_afterEpoch() {
1101         for (int i = 0; i < 100000; i++) {
1102             OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(i);
1103             assertEquals(a.toEpochSecond(), i);
1104         }
1105     }
1106 
1107     @Test(groups={"tck"})
1108     public void test_toEpochSecond_beforeEpoch() {
1109         for (int i = 0; i < 100000; i++) {
1110             OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).minusSeconds(i);
1111             assertEquals(a.toEpochSecond(), -i);
1112         }
1113     }
1114 
1115     //-----------------------------------------------------------------------
1116     // compareTo()
1117     //-----------------------------------------------------------------------
1118     @Test(groups={"tck"})
1119     public void test_compareTo_timeMins() {
1120         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 3, 0, OFFSET_PONE);
1121         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 2, 0, OFFSET_PONE);  // a is before b due to time
1122         assertEquals(a.compareTo(b) < 0, true);
1123         assertEquals(b.compareTo(a) > 0, true);
1124         assertEquals(a.compareTo(a) == 0, true);
1125         assertEquals(b.compareTo(b) == 0, true);
1126         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1127     }
1128 
1129     @Test(groups={"tck"})
1130     public void test_compareTo_timeSecs() {
1131         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 2, 0, OFFSET_PONE);
1132         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 29, 3, 0, OFFSET_PONE);  // a is before b due to time
1133         assertEquals(a.compareTo(b) < 0, true);
1134         assertEquals(b.compareTo(a) > 0, true);
1135         assertEquals(a.compareTo(a) == 0, true);
1136         assertEquals(b.compareTo(b) == 0, true);
1137         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1138     }
1139 
1140     @Test(groups={"tck"})
1141     public void test_compareTo_timeNanos() {
1142         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 40, 4, OFFSET_PONE);
1143         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 29, 40, 5, OFFSET_PONE);  // a is before b due to time
1144         assertEquals(a.compareTo(b) < 0, true);
1145         assertEquals(b.compareTo(a) > 0, true);
1146         assertEquals(a.compareTo(a) == 0, true);
1147         assertEquals(b.compareTo(b) == 0, true);
1148         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1149     }
1150 
1151     @Test(groups={"tck"})
1152     public void test_compareTo_offset() {
1153         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PTWO);
1154         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE);  // a is before b due to offset
1155         assertEquals(a.compareTo(b) < 0, true);
1156         assertEquals(b.compareTo(a) > 0, true);
1157         assertEquals(a.compareTo(a) == 0, true);
1158         assertEquals(b.compareTo(b) == 0, true);
1159         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1160     }
1161 
1162     @Test(groups={"tck"})
1163     public void test_compareTo_offsetNanos() {
1164         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 40, 6, OFFSET_PTWO);
1165         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 40, 5, OFFSET_PONE);  // a is before b due to offset
1166         assertEquals(a.compareTo(b) < 0, true);
1167         assertEquals(b.compareTo(a) > 0, true);
1168         assertEquals(a.compareTo(a) == 0, true);
1169         assertEquals(b.compareTo(b) == 0, true);
1170         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1171     }
1172 
1173     @Test(groups={"tck"})
1174     public void test_compareTo_both() {
1175         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 50, 0, 0, OFFSET_PTWO);
1176         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 20, 0, 0, OFFSET_PONE);  // a is before b on instant scale
1177         assertEquals(a.compareTo(b) < 0, true);
1178         assertEquals(b.compareTo(a) > 0, true);
1179         assertEquals(a.compareTo(a) == 0, true);
1180         assertEquals(b.compareTo(b) == 0, true);
1181         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1182     }
1183 
1184     @Test(groups={"tck"})
1185     public void test_compareTo_bothNanos() {
1186         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 20, 40, 4, OFFSET_PTWO);
1187         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 10, 20, 40, 5, OFFSET_PONE);  // a is before b on instant scale
1188         assertEquals(a.compareTo(b) < 0, true);
1189         assertEquals(b.compareTo(a) > 0, true);
1190         assertEquals(a.compareTo(a) == 0, true);
1191         assertEquals(b.compareTo(b) == 0, true);
1192         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1193     }
1194 
1195     @Test(groups={"tck"})
1196     public void test_compareTo_hourDifference() {
1197         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 10, 0, 0, 0, OFFSET_PONE);
1198         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 0, 0, 0, OFFSET_PTWO);  // a is before b despite being same time-line time
1199         assertEquals(a.compareTo(b) < 0, true);
1200         assertEquals(b.compareTo(a) > 0, true);
1201         assertEquals(a.compareTo(a) == 0, true);
1202         assertEquals(b.compareTo(b) == 0, true);
1203         assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true);
1204     }
1205 
1206     @Test(groups={"tck"})
1207     public void test_compareTo_max() {
1208         OffsetDateTime a = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MONE);
1209         OffsetDateTime b = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MTWO);  // a is before b due to offset
1210         assertEquals(a.compareTo(b) < 0, true);
1211         assertEquals(b.compareTo(a) > 0, true);
1212         assertEquals(a.compareTo(a) == 0, true);
1213         assertEquals(b.compareTo(b) == 0, true);
1214     }
1215 
1216     @Test(groups={"tck"})
1217     public void test_compareTo_min() {
1218         OffsetDateTime a = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PTWO);
1219         OffsetDateTime b = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PONE);  // a is before b due to offset
1220         assertEquals(a.compareTo(b) < 0, true);
1221         assertEquals(b.compareTo(a) > 0, true);
1222         assertEquals(a.compareTo(a) == 0, true);
1223         assertEquals(b.compareTo(b) == 0, true);
1224     }
1225 
1226     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1227     public void test_compareTo_null() {
1228         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1229         a.compareTo(null);
1230     }
1231 
1232     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
1233     @SuppressWarnings({"unchecked", "rawtypes"})
1234     public void compareToNonOffsetDateTime() {
1235        Comparable c = TEST_2008_6_30_11_30_59_000000500;
1236        c.compareTo(new Object());
1237     }
1238 
1239     //-----------------------------------------------------------------------
1240     // isAfter() / isBefore() / isEqual()
1241     //-----------------------------------------------------------------------
1242     @Test(groups={"tck"})
1243     public void test_isBeforeIsAfterIsEqual1() {
1244         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 58, 3, OFFSET_PONE);
1245         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 2, OFFSET_PONE);  // a is before b due to time
1246         assertEquals(a.isBefore(b), true);
1247         assertEquals(a.isEqual(b), false);
1248         assertEquals(a.isAfter(b), false);
1249 
1250         assertEquals(b.isBefore(a), false);
1251         assertEquals(b.isEqual(a), false);
1252         assertEquals(b.isAfter(a), true);
1253 
1254         assertEquals(a.isBefore(a), false);
1255         assertEquals(b.isBefore(b), false);
1256 
1257         assertEquals(a.isEqual(a), true);
1258         assertEquals(b.isEqual(b), true);
1259 
1260         assertEquals(a.isAfter(a), false);
1261         assertEquals(b.isAfter(b), false);
1262     }
1263 
1264     @Test(groups={"tck"})
1265     public void test_isBeforeIsAfterIsEqual2() {
1266         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 2, OFFSET_PONE);
1267         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 3, OFFSET_PONE);  // a is before b due to time
1268         assertEquals(a.isBefore(b), true);
1269         assertEquals(a.isEqual(b), false);
1270         assertEquals(a.isAfter(b), false);
1271 
1272         assertEquals(b.isBefore(a), false);
1273         assertEquals(b.isEqual(a), false);
1274         assertEquals(b.isAfter(a), true);
1275 
1276         assertEquals(a.isBefore(a), false);
1277         assertEquals(b.isBefore(b), false);
1278 
1279         assertEquals(a.isEqual(a), true);
1280         assertEquals(b.isEqual(b), true);
1281 
1282         assertEquals(a.isAfter(a), false);
1283         assertEquals(b.isAfter(b), false);
1284     }
1285 
1286     @Test(groups={"tck"})
1287     public void test_isBeforeIsAfterIsEqual_instantComparison() {
1288         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 10, 0, 0, 0, OFFSET_PONE);
1289         OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 0, 0, 0, OFFSET_PTWO);  // a is same instant as b
1290         assertEquals(a.isBefore(b), false);
1291         assertEquals(a.isEqual(b), true);
1292         assertEquals(a.isAfter(b), false);
1293 
1294         assertEquals(b.isBefore(a), false);
1295         assertEquals(b.isEqual(a), true);
1296         assertEquals(b.isAfter(a), false);
1297 
1298         assertEquals(a.isBefore(a), false);
1299         assertEquals(b.isBefore(b), false);
1300 
1301         assertEquals(a.isEqual(a), true);
1302         assertEquals(b.isEqual(b), true);
1303 
1304         assertEquals(a.isAfter(a), false);
1305         assertEquals(b.isAfter(b), false);
1306     }
1307 
1308     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1309     public void test_isBefore_null() {
1310         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1311         a.isBefore(null);
1312     }
1313 
1314     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1315     public void test_isEqual_null() {
1316         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1317         a.isEqual(null);
1318     }
1319 
1320     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1321     public void test_isAfter_null() {
1322         OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE);
1323         a.isAfter(null);
1324     }
1325 
1326     //-----------------------------------------------------------------------
1327     // equals() / hashCode()
1328     //-----------------------------------------------------------------------
1329     @Test(dataProvider="sampleTimes", groups={"tck"})
1330     public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1331         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1332         OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1333         assertEquals(a.equals(b), true);
1334         assertEquals(a.hashCode() == b.hashCode(), true);
1335     }
1336     @Test(dataProvider="sampleTimes", groups={"tck"})
1337     public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1338         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1339         OffsetDateTime b = OffsetDateTime.of(y + 1, o, d, h, m, s, n, OFFSET_PONE);
1340         assertEquals(a.equals(b), false);
1341     }
1342     @Test(dataProvider="sampleTimes", groups={"tck"})
1343     public void test_equals_false_hour_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1344         h = (h == 23 ? 22 : h);
1345         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1346         OffsetDateTime b = OffsetDateTime.of(y, o, d, h + 1, m, s, n, OFFSET_PONE);
1347         assertEquals(a.equals(b), false);
1348     }
1349     @Test(dataProvider="sampleTimes", groups={"tck"})
1350     public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1351         m = (m == 59 ? 58 : m);
1352         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1353         OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m + 1, s, n, OFFSET_PONE);
1354         assertEquals(a.equals(b), false);
1355     }
1356     @Test(dataProvider="sampleTimes", groups={"tck"})
1357     public void test_equals_false_second_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1358         s = (s == 59 ? 58 : s);
1359         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1360         OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s + 1, n, OFFSET_PONE);
1361         assertEquals(a.equals(b), false);
1362     }
1363     @Test(dataProvider="sampleTimes", groups={"tck"})
1364     public void test_equals_false_nano_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1365         n = (n == 999999999 ? 999999998 : n);
1366         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1367         OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n + 1, OFFSET_PONE);
1368         assertEquals(a.equals(b), false);
1369     }
1370     @Test(dataProvider="sampleTimes", groups={"tck"})
1371     public void test_equals_false_offset_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1372         OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE);
1373         OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PTWO);
1374         assertEquals(a.equals(b), false);
1375     }
1376 
1377     @Test(groups={"tck"})
1378     public void test_equals_itself_true() {
1379         assertEquals(TEST_2008_6_30_11_30_59_000000500.equals(TEST_2008_6_30_11_30_59_000000500), true);
1380     }
1381 
1382     @Test(groups={"tck"})
1383     public void test_equals_string_false() {
1384         assertEquals(TEST_2008_6_30_11_30_59_000000500.equals("2007-07-15"), false);
1385     }
1386 
1387     @Test(groups={"tck"})
1388     public void test_equals_null_false() {
1389         assertEquals(TEST_2008_6_30_11_30_59_000000500.equals(null), false);
1390     }
1391 
1392     //-----------------------------------------------------------------------
1393     // toString()
1394     //-----------------------------------------------------------------------
1395     @DataProvider(name="sampleToString")
1396     Object[][] provider_sampleToString() {
1397         return new Object[][] {
1398             {2008, 6, 30, 11, 30, 59, 0, "Z", "2008-06-30T11:30:59Z"},
1399             {2008, 6, 30, 11, 30, 59, 0, "+01:00", "2008-06-30T11:30:59+01:00"},
1400             {2008, 6, 30, 11, 30, 59, 999000000, "Z", "2008-06-30T11:30:59.999Z"},
1401             {2008, 6, 30, 11, 30, 59, 999000000, "+01:00", "2008-06-30T11:30:59.999+01:00"},
1402             {2008, 6, 30, 11, 30, 59, 999000, "Z", "2008-06-30T11:30:59.000999Z"},
1403             {2008, 6, 30, 11, 30, 59, 999000, "+01:00", "2008-06-30T11:30:59.000999+01:00"},
1404             {2008, 6, 30, 11, 30, 59, 999, "Z", "2008-06-30T11:30:59.000000999Z"},
1405             {2008, 6, 30, 11, 30, 59, 999, "+01:00", "2008-06-30T11:30:59.000000999+01:00"},
1406         };
1407     }
1408 
1409     @Test(dataProvider="sampleToString", groups={"tck"})
1410     public void test_toString(int y, int o, int d, int h, int m, int s, int n, String offsetId, String expected) {
1411         OffsetDateTime t = OffsetDateTime.of(y, o, d, h, m, s, n, ZoneOffset.of(offsetId));
1412         String str = t.toString();
1413         assertEquals(str, expected);
1414     }
1415 
1416     //-----------------------------------------------------------------------
1417     // toString(DateTimeFormatter)
1418     //-----------------------------------------------------------------------
1419     @Test(groups={"tck"})
1420     public void test_toString_formatter() {
1421         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
1422         String t = OffsetDateTime.of(2010, 12, 3, 11, 30, 0, 0, OFFSET_PONE).toString(f);
1423         assertEquals(t, "2010 12 3 11 30 0");
1424     }
1425 
1426     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1427     public void test_toString_formatter_null() {
1428         OffsetDateTime.of(2010, 12, 3, 11, 30, 0, 0, OFFSET_PONE).toString(null);
1429     }
1430 
1431 }