test/java/time/tck/java/time/TCKOffsetDateTime.java

Print this page




  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.temporal;
  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.io.IOException;
 102 import java.lang.reflect.Constructor;
 103 import java.lang.reflect.InvocationTargetException;
 104 import java.util.ArrayList;
 105 import java.util.Arrays;
 106 import java.util.List;
 107 
 108 import java.time.Clock;
 109 import java.time.DateTimeException;
 110 import java.time.Duration;
 111 import java.time.Instant;
 112 import java.time.LocalDate;
 113 import java.time.LocalDateTime;
 114 import java.time.LocalTime;
 115 import java.time.Month;



 116 import java.time.ZoneId;
 117 import java.time.ZoneOffset;
 118 import java.time.ZonedDateTime;

 119 import java.time.format.DateTimeFormatter;
 120 import java.time.format.DateTimeFormatters;
 121 import java.time.format.DateTimeParseException;
 122 import java.time.temporal.ChronoField;
 123 import java.time.temporal.ChronoUnit;
 124 import java.time.temporal.ISOChrono;
 125 import java.time.temporal.JulianFields;
 126 import java.time.temporal.OffsetDate;
 127 import java.time.temporal.OffsetDateTime;
 128 import java.time.temporal.OffsetTime;
 129 import java.time.temporal.Queries;
 130 import java.time.temporal.Temporal;
 131 import java.time.temporal.TemporalAccessor;
 132 import java.time.temporal.TemporalAdjuster;
 133 import java.time.temporal.TemporalField;
 134 import java.time.temporal.TemporalQuery;
 135 import java.time.temporal.Year;


 136 
 137 import org.testng.annotations.BeforeMethod;
 138 import org.testng.annotations.DataProvider;
 139 import org.testng.annotations.Test;
 140 import tck.java.time.AbstractDateTimeTest;
 141 import test.java.time.MockSimplePeriod;
 142 
 143 /**
 144  * Test OffsetDateTime.
 145  */
 146 @Test
 147 public class TCKOffsetDateTime extends AbstractDateTimeTest {
 148 
 149     private static final ZoneId ZONE_PARIS = ZoneId.of("Europe/Paris");
 150     private static final ZoneId ZONE_GAZA = ZoneId.of("Asia/Gaza");
 151     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 152     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 153     private static final ZoneOffset OFFSET_MONE = ZoneOffset.ofHours(-1);
 154     private static final ZoneOffset OFFSET_MTWO = ZoneOffset.ofHours(-2);
 155     private OffsetDateTime TEST_2008_6_30_11_30_59_000000500;
 156 
 157     @BeforeMethod(groups={"tck","implementation"})
 158     public void setUp() {
 159         TEST_2008_6_30_11_30_59_000000500 = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE);
 160     }


 208 
 209     @Override
 210     protected List<TemporalField> invalidFields() {
 211         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 212         list.removeAll(validFields());
 213         return list;
 214     }
 215 
 216     //-----------------------------------------------------------------------
 217     @Test
 218     public void test_serialization() throws Exception {
 219         assertSerializable(TEST_2008_6_30_11_30_59_000000500);
 220         assertSerializable(OffsetDateTime.MIN);
 221         assertSerializable(OffsetDateTime.MAX);
 222     }
 223 
 224     @Test
 225     public void test_serialization_format() throws Exception {
 226         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 227         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 228             dos.writeByte(3);
 229         }
 230         byte[] bytes = baos.toByteArray();
 231         ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream();
 232         try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) {
 233             dos.writeByte(5);
 234             dos.writeInt(2012);
 235             dos.writeByte(9);
 236             dos.writeByte(16);
 237             dos.writeByte(22);
 238             dos.writeByte(17);
 239             dos.writeByte(59);
 240             dos.writeInt(464_000_000);
 241         }
 242         byte[] bytesDateTime = baosDateTime.toByteArray();
 243         ByteArrayOutputStream baosOffset = new ByteArrayOutputStream();
 244         try (DataOutputStream dos = new DataOutputStream(baosOffset) ) {
 245             dos.writeByte(8);
 246             dos.writeByte(4);  // quarter hours stored: 3600 / 900
 247         }
 248         byte[] bytesOffset = baosOffset.toByteArray();


 253     //-----------------------------------------------------------------------
 254     // constants
 255     //-----------------------------------------------------------------------
 256     @Test
 257     public void constant_MIN() {
 258         check(OffsetDateTime.MIN, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, ZoneOffset.MAX);
 259     }
 260 
 261     @Test
 262     public void constant_MAX() {
 263         check(OffsetDateTime.MAX, Year.MAX_VALUE, 12, 31, 23, 59, 59, 999999999, ZoneOffset.MIN);
 264     }
 265 
 266     //-----------------------------------------------------------------------
 267     // now()
 268     //-----------------------------------------------------------------------
 269     @Test(groups={"tck"})
 270     public void now() {
 271         OffsetDateTime expected = OffsetDateTime.now(Clock.systemDefaultZone());
 272         OffsetDateTime test = OffsetDateTime.now();
 273         long diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 274         if (diff >= 100000000) {
 275             // may be date change
 276             expected = OffsetDateTime.now(Clock.systemDefaultZone());
 277             test = OffsetDateTime.now();
 278             diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 279         }
 280         assertTrue(diff < 100000000);  // less than 0.1 secs
 281     }
 282 
 283     //-----------------------------------------------------------------------
 284     // now(Clock)
 285     //-----------------------------------------------------------------------
 286     @Test(groups={"tck"})
 287     public void now_Clock_allSecsInDay_utc() {
 288         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 289             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 290             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 291             OffsetDateTime test = OffsetDateTime.now(clock);
 292             assertEquals(test.getYear(), 1970);
 293             assertEquals(test.getMonth(), Month.JANUARY);
 294             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
 295             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 296             assertEquals(test.getMinute(), (i / 60) % 60);
 297             assertEquals(test.getSecond(), i % 60);
 298             assertEquals(test.getNano(), 123456789);


 311             assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
 312             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 313             assertEquals(test.getMinute(), (i / 60) % 60);
 314             assertEquals(test.getSecond(), i % 60);
 315             assertEquals(test.getNano(), 123456789);
 316             assertEquals(test.getOffset(), OFFSET_PONE);
 317         }
 318     }
 319 
 320     @Test(groups={"tck"})
 321     public void now_Clock_allSecsInDay_beforeEpoch() {
 322         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 323         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 324             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 325             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 326             OffsetDateTime test = OffsetDateTime.now(clock);
 327             assertEquals(test.getYear(), 1969);
 328             assertEquals(test.getMonth(), Month.DECEMBER);
 329             assertEquals(test.getDayOfMonth(), 31);
 330             expected = expected.minusSeconds(1);
 331             assertEquals(test.getTime(), expected);
 332             assertEquals(test.getOffset(), ZoneOffset.UTC);
 333         }
 334     }
 335 
 336     @Test(groups={"tck"})
 337     public void now_Clock_offsets() {
 338         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(12, 0), ZoneOffset.UTC);
 339         for (int i = -9; i < 15; i++) {
 340             ZoneOffset offset = ZoneOffset.ofHours(i);
 341             Clock clock = Clock.fixed(base.toInstant(), offset);
 342             OffsetDateTime test = OffsetDateTime.now(clock);
 343             assertEquals(test.getHour(), (12 + i) % 24);
 344             assertEquals(test.getMinute(), 0);
 345             assertEquals(test.getSecond(), 0);
 346             assertEquals(test.getNano(), 0);
 347             assertEquals(test.getOffset(), offset);
 348         }
 349     }
 350 
 351     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 352     public void now_Clock_nullZoneId() {
 353         OffsetDateTime.now((ZoneId) null);
 354     }
 355 
 356     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 357     public void now_Clock_nullClock() {
 358         OffsetDateTime.now((Clock) null);
 359     }
 360 
 361     //-----------------------------------------------------------------------
 362     private void check(OffsetDateTime test, int y, int mo, int d, int h, int m, int s, int n, ZoneOffset offset) {
 363         assertEquals(test.getYear(), y);
 364         assertEquals(test.getMonth().getValue(), mo);
 365         assertEquals(test.getDayOfMonth(), d);
 366         assertEquals(test.getHour(), h);
 367         assertEquals(test.getMinute(), m);
 368         assertEquals(test.getSecond(), s);
 369         assertEquals(test.getNano(), n);
 370         assertEquals(test.getOffset(), offset);
 371         assertEquals(test, test);
 372         assertEquals(test.hashCode(), test.hashCode());
 373         assertEquals(OffsetDateTime.of(LocalDateTime.of(y, mo, d, h, m, s, n), offset), test);
 374     }
 375 
 376     //-----------------------------------------------------------------------
 377     // dateTime factories
 378     //-----------------------------------------------------------------------
 379     @Test(groups={"tck"})
 380     public void factory_of_intMonthIntHM() {
 381         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, Month.JUNE, 30),
 382                 LocalTime.of(11, 30), OFFSET_PONE);
 383         check(test, 2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE);
 384     }
 385 
 386     //-----------------------------------------------------------------------
 387     @Test(groups={"tck"})
 388     public void factory_of_intMonthIntHMS() {
 389         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, Month.JUNE, 30),
 390                 LocalTime.of(11, 30, 10), OFFSET_PONE);
 391         check(test, 2008, 6, 30, 11, 30, 10, 0, OFFSET_PONE);
 392     }
 393 
 394     //-----------------------------------------------------------------------
 395     @Test(groups={"tck"})
 396     public void factory_of_intMonthIntHMSN() {
 397         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, Month.JUNE, 30),
 398                 LocalTime.of(11, 30, 10, 500), OFFSET_PONE);
 399         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 400     }
 401 
 402     //-----------------------------------------------------------------------
 403     @Test(groups={"tck"})
 404     public void factory_of_intsHM() {
 405         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PONE);
 406         check(test, 2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE);
 407     }
 408 
 409     //-----------------------------------------------------------------------
 410     @Test(groups={"tck"})
 411     public void factory_of_intsHMS() {
 412         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10), OFFSET_PONE);
 413         check(test, 2008, 6, 30, 11, 30, 10, 0, OFFSET_PONE);
 414     }
 415 
 416     //-----------------------------------------------------------------------
 417     @Test(groups={"tck"})
 418     public void factory_of_intsHMSN() {
 419         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), OFFSET_PONE);
 420         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 421     }
 422 
 423     //-----------------------------------------------------------------------
 424     @Test(groups={"tck"})
 425     public void factory_of_LocalDateLocalTimeZoneOffset() {
 426         LocalDate date = LocalDate.of(2008, 6, 30);
 427         LocalTime time = LocalTime.of(11, 30, 10, 500);
 428         OffsetDateTime test = OffsetDateTime.of(date, time, OFFSET_PONE);
 429         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
 430     }
 431 
 432     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 433     public void factory_of_LocalDateLocalTimeZoneOffset_nullLocalDate() {
 434         LocalTime time = LocalTime.of(11, 30, 10, 500);
 435         OffsetDateTime.of((LocalDate) null, time, OFFSET_PONE);
 436     }
 437 
 438     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 439     public void factory_of_LocalDateLocalTimeZoneOffset_nullLocalTime() {


 506     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 507     public void factory_parse_illegalValue() {
 508         OffsetDateTime.parse("2008-06-32T11:15+01:00");
 509     }
 510 
 511     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 512     public void factory_parse_invalidValue() {
 513         OffsetDateTime.parse("2008-06-31T11:15+01:00");
 514     }
 515 
 516     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 517     public void factory_parse_nullText() {
 518         OffsetDateTime.parse((String) null);
 519     }
 520 
 521     //-----------------------------------------------------------------------
 522     // parse(DateTimeFormatter)
 523     //-----------------------------------------------------------------------
 524     @Test(groups={"tck"})
 525     public void factory_parse_formatter() {
 526         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s XXX");
 527         OffsetDateTime test = OffsetDateTime.parse("2010 12 3 11 30 0 +01:00", f);
 528         assertEquals(test, OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), ZoneOffset.ofHours(1)));
 529     }
 530 
 531     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 532     public void factory_parse_formatter_nullText() {
 533         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
 534         OffsetDateTime.parse((String) null, f);
 535     }
 536 
 537     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 538     public void factory_parse_formatter_nullFormatter() {
 539         OffsetDateTime.parse("ANY", null);
 540     }
 541 
 542     //-----------------------------------------------------------------------
 543     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 544     public void constructor_nullTime() throws Throwable  {
 545         Constructor<OffsetDateTime> con = OffsetDateTime.class.getDeclaredConstructor(LocalDateTime.class, ZoneOffset.class);
 546         con.setAccessible(true);
 547         try {
 548             con.newInstance(null, OFFSET_PONE);
 549         } catch (InvocationTargetException ex) {
 550             throw ex.getCause();
 551         }
 552     }
 553 


 576     }
 577 
 578     @Test(dataProvider="sampleTimes", groups={"tck"})
 579     public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneOffset offset) {
 580         LocalDate localDate = LocalDate.of(y, o, d);
 581         LocalTime localTime = LocalTime.of(h, m, s, n);
 582         LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
 583         OffsetDateTime a = OffsetDateTime.of(localDateTime, offset);
 584 
 585         assertEquals(a.getYear(), localDate.getYear());
 586         assertEquals(a.getMonth(), localDate.getMonth());
 587         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 588         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 589         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 590 
 591         assertEquals(a.getHour(), localDateTime.getHour());
 592         assertEquals(a.getMinute(), localDateTime.getMinute());
 593         assertEquals(a.getSecond(), localDateTime.getSecond());
 594         assertEquals(a.getNano(), localDateTime.getNano());
 595 
 596         assertEquals(a.toOffsetDate(), OffsetDate.of(localDate, offset));
 597         assertEquals(a.toOffsetTime(), OffsetTime.of(localTime, offset));
 598         assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 599     }
 600 
 601     //-----------------------------------------------------------------------
 602     // get(TemporalField)
 603     //-----------------------------------------------------------------------
 604     @Test
 605     public void test_get_TemporalField() {
 606         OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
 607         assertEquals(test.get(ChronoField.YEAR), 2008);
 608         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 609         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 610         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 611         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 612 
 613         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 614         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 615         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 616         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);


 626         assertEquals(test.getLong(ChronoField.YEAR), 2008);
 627         assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
 628         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 629         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 630         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 631 
 632         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 633         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 634         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 635         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 636         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 637         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 638 
 639         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
 640         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 641     }
 642 
 643     //-----------------------------------------------------------------------
 644     // query(TemporalQuery)
 645     //-----------------------------------------------------------------------
 646     @Test
 647     public void test_query_chrono() {
 648         assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.chrono()), ISOChrono.INSTANCE);
 649         assertEquals(Queries.chrono().queryFrom(TEST_2008_6_30_11_30_59_000000500), ISOChrono.INSTANCE);
 650     }
 651 
 652     @Test
 653     public void test_query_zoneId() {
 654         assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.zoneId()), null);
 655         assertEquals(Queries.zoneId().queryFrom(TEST_2008_6_30_11_30_59_000000500), null);
 656     }
 657 
 658     @Test
 659     public void test_query_precision() {
 660         assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.precision()), NANOS);
 661         assertEquals(Queries.precision().queryFrom(TEST_2008_6_30_11_30_59_000000500), NANOS);
 662     }
 663 
 664     @Test
 665     public void test_query_offset() {
 666         assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.offset()), OFFSET_PONE);
 667         assertEquals(Queries.offset().queryFrom(TEST_2008_6_30_11_30_59_000000500), OFFSET_PONE);
 668     }
 669 
 670     @Test
 671     public void test_query_zone() {
 672         assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.zone()), OFFSET_PONE);
 673         assertEquals(Queries.zone().queryFrom(TEST_2008_6_30_11_30_59_000000500), OFFSET_PONE);
 674     }
 675 
 676     @Test(expectedExceptions=NullPointerException.class)
 677     public void test_query_null() {
 678         TEST_2008_6_30_11_30_59_000000500.query(null);
 679     }
 680 
 681     //-----------------------------------------------------------------------
 682     // with(WithAdjuster)
 683     //-----------------------------------------------------------------------
 684     @Test(groups={"tck"})
 685     public void test_with_adjustment() {
 686         final OffsetDateTime sample = OffsetDateTime.of(LocalDate.of(2012, 3, 4), LocalTime.of(23, 5), OFFSET_PONE);
 687         TemporalAdjuster adjuster = new TemporalAdjuster() {
 688             @Override
 689             public Temporal adjustInto(Temporal dateTime) {
 690                 return sample;
 691             }
 692         };
 693         assertEquals(TEST_2008_6_30_11_30_59_000000500.with(adjuster), sample);


 695 
 696     @Test(groups={"tck"})
 697     public void test_with_adjustment_LocalDate() {
 698         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalDate.of(2012, 9, 3));
 699         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 700     }
 701 
 702     @Test(groups={"tck"})
 703     public void test_with_adjustment_LocalTime() {
 704         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalTime.of(19, 15));
 705         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(19, 15), OFFSET_PONE));
 706     }
 707 
 708     @Test(groups={"tck"})
 709     public void test_with_adjustment_LocalDateTime() {
 710         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15)));
 711         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PONE));
 712     }
 713 
 714     @Test(groups={"tck"})
 715     public void test_with_adjustment_OffsetDate() {
 716         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetDate.of(LocalDate.of(2012, 9, 3), OFFSET_PTWO));
 717         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(11, 30, 59, 500), OFFSET_PTWO));
 718     }
 719 
 720     @Test(groups={"tck"})
 721     public void test_with_adjustment_OffsetTime() {
 722         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetTime.of(LocalTime.of(19, 15), OFFSET_PTWO));
 723         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(19, 15), OFFSET_PTWO));
 724     }
 725 
 726     @Test(groups={"tck"})
 727     public void test_with_adjustment_OffsetDateTime() {
 728         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PTWO));
 729         assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PTWO));
 730     }
 731 
 732     @Test(groups={"tck"})
 733     public void test_with_adjustment_Month() {
 734         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(DECEMBER);
 735         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 12, 30),LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 736     }
 737 
 738     @Test(groups={"tck"})
 739     public void test_with_adjustment_ZoneOffset() {
 740         OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OFFSET_PTWO);


 863     //-----------------------------------------------------------------------
 864     @Test(groups={"tck"})
 865     public void test_truncatedTo_normal() {
 866         assertEquals(TEST_2008_6_30_11_30_59_000000500.truncatedTo(NANOS), TEST_2008_6_30_11_30_59_000000500);
 867         assertEquals(TEST_2008_6_30_11_30_59_000000500.truncatedTo(SECONDS), TEST_2008_6_30_11_30_59_000000500.withNano(0));
 868         assertEquals(TEST_2008_6_30_11_30_59_000000500.truncatedTo(DAYS), TEST_2008_6_30_11_30_59_000000500.with(LocalTime.MIDNIGHT));
 869     }
 870 
 871     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 872     public void test_truncatedTo_null() {
 873         TEST_2008_6_30_11_30_59_000000500.truncatedTo(null);
 874     }
 875 
 876     //-----------------------------------------------------------------------
 877     // plus(Period)
 878     //-----------------------------------------------------------------------
 879     @Test(groups={"tck"})
 880     public void test_plus_Period() {
 881         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
 882         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(period);
 883         assertEquals(t, OffsetDateTime.of(LocalDate.of(2009, 1, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 884     }
 885 
 886     //-----------------------------------------------------------------------
 887     // plus(Duration)
 888     //-----------------------------------------------------------------------
 889     @Test(groups={"tck"})
 890     public void test_plus_Duration() {
 891         Duration dur = Duration.ofSeconds(62, 3);
 892         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(dur);
 893         assertEquals(t, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 32, 1, 503), OFFSET_PONE));
 894     }
 895 
 896     @Test(groups={"tck"})
 897     public void test_plus_Duration_zero() {
 898         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(Duration.ZERO);
 899         assertEquals(t, TEST_2008_6_30_11_30_59_000000500);
 900     }
 901 
 902     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 903     public void test_plus_Duration_null() {
 904         TEST_2008_6_30_11_30_59_000000500.plus((Duration) null);
 905     }
 906 
 907     //-----------------------------------------------------------------------
 908     // plusYears()
 909     //-----------------------------------------------------------------------
 910     @Test(groups={"tck"})
 911     public void test_plusYears() {
 912         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 913         OffsetDateTime test = base.plusYears(1);
 914         assertEquals(test, OffsetDateTime.of(LocalDate.of(2009, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
 915     }
 916 
 917     //-----------------------------------------------------------------------
 918     // plusMonths()
 919     //-----------------------------------------------------------------------
 920     @Test(groups={"tck"})
 921     public void test_plusMonths() {
 922         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 923         OffsetDateTime test = base.plusMonths(1);
 924         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
 925     }
 926 
 927     //-----------------------------------------------------------------------
 928     // plusWeeks()
 929     //-----------------------------------------------------------------------
 930     @Test(groups={"tck"})
 931     public void test_plusWeeks() {
 932         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 933         OffsetDateTime test = base.plusWeeks(1);
 934         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 7), LocalTime.of(11, 30, 59), OFFSET_PONE));
 935     }
 936 
 937     //-----------------------------------------------------------------------
 938     // plusDays()
 939     //-----------------------------------------------------------------------
 940     @Test(groups={"tck"})
 941     public void test_plusDays() {
 942         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 943         OffsetDateTime test = base.plusDays(1);
 944         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 1), LocalTime.of(11, 30, 59), OFFSET_PONE));
 945     }
 946 
 947     //-----------------------------------------------------------------------
 948     // plusHours()
 949     //-----------------------------------------------------------------------
 950     @Test(groups={"tck"})
 951     public void test_plusHours() {
 952         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 953         OffsetDateTime test = base.plusHours(13);
 954         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 1), LocalTime.of(0, 30, 59), OFFSET_PONE));
 955     }
 956 
 957     //-----------------------------------------------------------------------
 958     // plusMinutes()
 959     //-----------------------------------------------------------------------
 960     @Test(groups={"tck"})
 961     public void test_plusMinutes() {
 962         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 963         OffsetDateTime test = base.plusMinutes(30);
 964         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 0, 59), OFFSET_PONE));
 965     }
 966 
 967     //-----------------------------------------------------------------------
 968     // plusSeconds()
 969     //-----------------------------------------------------------------------
 970     @Test(groups={"tck"})
 971     public void test_plusSeconds() {
 972         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 973         OffsetDateTime test = base.plusSeconds(1);
 974         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 31, 0), OFFSET_PONE));
 975     }
 976 
 977     //-----------------------------------------------------------------------
 978     // plusNanos()
 979     //-----------------------------------------------------------------------
 980     @Test(groups={"tck"})
 981     public void test_plusNanos() {
 982         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 0), OFFSET_PONE);
 983         OffsetDateTime test = base.plusNanos(1);
 984         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 1), OFFSET_PONE));
 985     }
 986 
 987     //-----------------------------------------------------------------------
 988     // minus(Period)
 989     //-----------------------------------------------------------------------
 990     @Test(groups={"tck"})
 991     public void test_minus_Period() {
 992         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
 993         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(period);
 994         assertEquals(t, OffsetDateTime.of(LocalDate.of(2007, 11, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE));
 995     }
 996 
 997     //-----------------------------------------------------------------------
 998     // minus(Duration)
 999     //-----------------------------------------------------------------------
1000     @Test(groups={"tck"})
1001     public void test_minus_Duration() {
1002         Duration dur = Duration.ofSeconds(62, 3);
1003         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(dur);
1004         assertEquals(t, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 57, 497), OFFSET_PONE));
1005     }
1006 
1007     @Test(groups={"tck"})
1008     public void test_minus_Duration_zero() {
1009         OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(Duration.ZERO);
1010         assertEquals(t, TEST_2008_6_30_11_30_59_000000500);
1011     }
1012 
1013     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1014     public void test_minus_Duration_null() {
1015         TEST_2008_6_30_11_30_59_000000500.minus((Duration) null);
1016     }
1017 
1018     //-----------------------------------------------------------------------
1019     // minusYears()
1020     //-----------------------------------------------------------------------
1021     @Test(groups={"tck"})
1022     public void test_minusYears() {
1023         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1024         OffsetDateTime test = base.minusYears(1);
1025         assertEquals(test, OffsetDateTime.of(LocalDate.of(2007, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
1026     }
1027 
1028     //-----------------------------------------------------------------------
1029     // minusMonths()
1030     //-----------------------------------------------------------------------
1031     @Test(groups={"tck"})
1032     public void test_minusMonths() {
1033         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1034         OffsetDateTime test = base.minusMonths(1);
1035         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 5, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
1036     }
1037 
1038     //-----------------------------------------------------------------------
1039     // minusWeeks()
1040     //-----------------------------------------------------------------------
1041     @Test(groups={"tck"})
1042     public void test_minusWeeks() {
1043         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1044         OffsetDateTime test = base.minusWeeks(1);
1045         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 23), LocalTime.of(11, 30, 59), OFFSET_PONE));
1046     }
1047 
1048     //-----------------------------------------------------------------------
1049     // minusDays()
1050     //-----------------------------------------------------------------------
1051     @Test(groups={"tck"})
1052     public void test_minusDays() {
1053         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1054         OffsetDateTime test = base.minusDays(1);
1055         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 29), LocalTime.of(11, 30, 59), OFFSET_PONE));
1056     }
1057 
1058     //-----------------------------------------------------------------------
1059     // minusHours()
1060     //-----------------------------------------------------------------------
1061     @Test(groups={"tck"})
1062     public void test_minusHours() {
1063         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1064         OffsetDateTime test = base.minusHours(13);
1065         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 29), LocalTime.of(22, 30, 59), OFFSET_PONE));
1066     }
1067 
1068     //-----------------------------------------------------------------------
1069     // minusMinutes()
1070     //-----------------------------------------------------------------------
1071     @Test(groups={"tck"})
1072     public void test_minusMinutes() {
1073         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1074         OffsetDateTime test = base.minusMinutes(30);
1075         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 0, 59), OFFSET_PONE));
1076     }
1077 
1078     //-----------------------------------------------------------------------
1079     // minusSeconds()
1080     //-----------------------------------------------------------------------
1081     @Test(groups={"tck"})
1082     public void test_minusSeconds() {
1083         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1084         OffsetDateTime test = base.minusSeconds(1);
1085         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 58), OFFSET_PONE));
1086     }
1087 
1088     //-----------------------------------------------------------------------
1089     // minusNanos()
1090     //-----------------------------------------------------------------------
1091     @Test(groups={"tck"})
1092     public void test_minusNanos() {
1093         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 0), OFFSET_PONE);
1094         OffsetDateTime test = base.minusNanos(1);
1095         assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 58, 999999999), OFFSET_PONE));
1096     }
1097 
1098     //-----------------------------------------------------------------------
1099     // atZoneSameInstant()
1100     //-----------------------------------------------------------------------
1101     @Test(groups={"tck"})
1102     public void test_atZone() {
1103         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_MTWO);
1104         assertEquals(t.atZoneSameInstant(ZONE_PARIS),
1105                 ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(15, 30)), ZONE_PARIS));
1106     }
1107 
1108     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1109     public void test_atZone_nullTimeZone() {
1110         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO);
1111         t.atZoneSameInstant((ZoneId) null);
1112     }
1113 
1114     //-----------------------------------------------------------------------
1115     // atZoneSimilarLocal()
1116     //-----------------------------------------------------------------------
1117     @Test(groups={"tck"})
1118     public void test_atZoneSimilarLocal() {
1119         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_MTWO);
1120         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS),
1121                 ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30)), ZONE_PARIS));
1122     }
1123 
1124     @Test(groups={"tck"})
1125     public void test_atZoneSimilarLocal_dstGap() {
1126         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2007, 4, 1), LocalTime.of(0, 0), OFFSET_MTWO);
1127         assertEquals(t.atZoneSimilarLocal(ZONE_GAZA),
1128                 ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2007, 4, 1), LocalTime.of(1, 0)), ZONE_GAZA));
1129     }
1130 
1131     @Test(groups={"tck"})
1132     public void test_atZone_dstOverlapSummer() {
1133         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2007, 10, 28), LocalTime.of(2, 30), OFFSET_PTWO);
1134         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getDateTime(), t.getDateTime());
1135         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PTWO);
1136         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS);
1137     }
1138 
1139     @Test(groups={"tck"})
1140     public void test_atZone_dstOverlapWinter() {
1141         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2007, 10, 28), LocalTime.of(2, 30), OFFSET_PONE);
1142         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getDateTime(), t.getDateTime());
1143         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PONE);
1144         assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS);
1145     }
1146 
1147     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1148     public void test_atZoneSimilarLocal_nullTimeZone() {
1149         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO);
1150         t.atZoneSimilarLocal((ZoneId) null);
1151     }
1152 
1153     //-----------------------------------------------------------------------
1154     // toEpochSecond()
1155     //-----------------------------------------------------------------------
1156     @Test(groups={"tck"})
1157     public void test_toEpochSecond_afterEpoch() {
1158         for (int i = 0; i < 100000; i++) {
1159             OffsetDateTime a = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0), ZoneOffset.UTC).plusSeconds(i);
1160             assertEquals(a.toEpochSecond(), i);
1161         }
1162     }
1163 
1164     @Test(groups={"tck"})
1165     public void test_toEpochSecond_beforeEpoch() {
1166         for (int i = 0; i < 100000; i++) {
1167             OffsetDateTime a = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0), ZoneOffset.UTC).minusSeconds(i);
1168             assertEquals(a.toEpochSecond(), -i);
1169         }
1170     }
1171 
1172     //-----------------------------------------------------------------------
1173     // compareTo()
1174     //-----------------------------------------------------------------------
1175     @Test(groups={"tck"})
1176     public void test_compareTo_timeMins() {
1177         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 3), OFFSET_PONE);
1178         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 2), OFFSET_PONE);  // a is before b due to time
1179         assertEquals(a.compareTo(b) < 0, true);
1180         assertEquals(b.compareTo(a) > 0, true);
1181         assertEquals(a.compareTo(a) == 0, true);
1182         assertEquals(b.compareTo(b) == 0, true);
1183         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1184     }
1185 
1186     @Test(groups={"tck"})
1187     public void test_compareTo_timeSecs() {
1188         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 2), OFFSET_PONE);
1189         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 3), OFFSET_PONE);  // a is before b due to time
1190         assertEquals(a.compareTo(b) < 0, true);
1191         assertEquals(b.compareTo(a) > 0, true);
1192         assertEquals(a.compareTo(a) == 0, true);
1193         assertEquals(b.compareTo(b) == 0, true);
1194         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1195     }
1196 
1197     @Test(groups={"tck"})
1198     public void test_compareTo_timeNanos() {
1199         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 40, 4), OFFSET_PONE);
1200         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 40, 5), OFFSET_PONE);  // a is before b due to time
1201         assertEquals(a.compareTo(b) < 0, true);
1202         assertEquals(b.compareTo(a) > 0, true);
1203         assertEquals(a.compareTo(a) == 0, true);
1204         assertEquals(b.compareTo(b) == 0, true);
1205         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1206     }
1207 
1208     @Test(groups={"tck"})
1209     public void test_compareTo_offset() {
1210         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO);
1211         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PONE);  // a is before b due to offset
1212         assertEquals(a.compareTo(b) < 0, true);
1213         assertEquals(b.compareTo(a) > 0, true);
1214         assertEquals(a.compareTo(a) == 0, true);
1215         assertEquals(b.compareTo(b) == 0, true);
1216         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1217     }
1218 
1219     @Test(groups={"tck"})
1220     public void test_compareTo_offsetNanos() {
1221         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 40, 6), OFFSET_PTWO);
1222         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 40, 5), OFFSET_PONE);  // a is before b due to offset
1223         assertEquals(a.compareTo(b) < 0, true);
1224         assertEquals(b.compareTo(a) > 0, true);
1225         assertEquals(a.compareTo(a) == 0, true);
1226         assertEquals(b.compareTo(b) == 0, true);
1227         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1228     }
1229 
1230     @Test(groups={"tck"})
1231     public void test_compareTo_both() {
1232         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 50), OFFSET_PTWO);
1233         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 20), OFFSET_PONE);  // a is before b on instant scale
1234         assertEquals(a.compareTo(b) < 0, true);
1235         assertEquals(b.compareTo(a) > 0, true);
1236         assertEquals(a.compareTo(a) == 0, true);
1237         assertEquals(b.compareTo(b) == 0, true);
1238         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1239     }
1240 
1241     @Test(groups={"tck"})
1242     public void test_compareTo_bothNanos() {
1243         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 20, 40, 4), OFFSET_PTWO);
1244         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(10, 20, 40, 5), OFFSET_PONE);  // a is before b on instant scale
1245         assertEquals(a.compareTo(b) < 0, true);
1246         assertEquals(b.compareTo(a) > 0, true);
1247         assertEquals(a.compareTo(a) == 0, true);
1248         assertEquals(b.compareTo(b) == 0, true);
1249         assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
1250     }
1251 
1252     @Test(groups={"tck"})
1253     public void test_compareTo_hourDifference() {
1254         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(10, 0), OFFSET_PONE);
1255         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 0), OFFSET_PTWO);  // a is before b despite being same time-line time
1256         assertEquals(a.compareTo(b) < 0, true);
1257         assertEquals(b.compareTo(a) > 0, true);
1258         assertEquals(a.compareTo(a) == 0, true);
1259         assertEquals(b.compareTo(b) == 0, true);
1260         assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true);
1261     }
1262 
1263     @Test(groups={"tck"})
1264     public void test_compareTo_max() {
1265         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(Year.MAX_VALUE, 12, 31), LocalTime.of(23, 59), OFFSET_MONE);
1266         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(Year.MAX_VALUE, 12, 31), LocalTime.of(23, 59), OFFSET_MTWO);  // a is before b due to offset
1267         assertEquals(a.compareTo(b) < 0, true);
1268         assertEquals(b.compareTo(a) > 0, true);
1269         assertEquals(a.compareTo(a) == 0, true);
1270         assertEquals(b.compareTo(b) == 0, true);
1271     }
1272 
1273     @Test(groups={"tck"})
1274     public void test_compareTo_min() {
1275         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(Year.MIN_VALUE, 1, 1), LocalTime.of(0, 0), OFFSET_PTWO);
1276         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(Year.MIN_VALUE, 1, 1), LocalTime.of(0, 0), OFFSET_PONE);  // a is before b due to offset
1277         assertEquals(a.compareTo(b) < 0, true);
1278         assertEquals(b.compareTo(a) > 0, true);
1279         assertEquals(a.compareTo(a) == 0, true);
1280         assertEquals(b.compareTo(b) == 0, true);
1281     }
1282 
1283     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1284     public void test_compareTo_null() {
1285         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1286         a.compareTo(null);
1287     }
1288 
1289     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
1290     @SuppressWarnings({"unchecked", "rawtypes"})
1291     public void compareToNonOffsetDateTime() {
1292        Comparable c = TEST_2008_6_30_11_30_59_000000500;
1293        c.compareTo(new Object());
1294     }
1295 
1296     //-----------------------------------------------------------------------
1297     // isAfter() / isBefore() / isEqual()
1298     //-----------------------------------------------------------------------
1299     @Test(groups={"tck"})
1300     public void test_isBeforeIsAfterIsEqual1() {
1301         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 58, 3), OFFSET_PONE);
1302         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 2), OFFSET_PONE);  // a is before b due to time
1303         assertEquals(a.isBefore(b), true);
1304         assertEquals(a.isEqual(b), false);
1305         assertEquals(a.isAfter(b), false);
1306 
1307         assertEquals(b.isBefore(a), false);
1308         assertEquals(b.isEqual(a), false);
1309         assertEquals(b.isAfter(a), true);
1310 
1311         assertEquals(a.isBefore(a), false);
1312         assertEquals(b.isBefore(b), false);
1313 
1314         assertEquals(a.isEqual(a), true);
1315         assertEquals(b.isEqual(b), true);
1316 
1317         assertEquals(a.isAfter(a), false);
1318         assertEquals(b.isAfter(b), false);
1319     }
1320 
1321     @Test(groups={"tck"})
1322     public void test_isBeforeIsAfterIsEqual2() {
1323         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 2), OFFSET_PONE);
1324         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 3), OFFSET_PONE);  // a is before b due to time
1325         assertEquals(a.isBefore(b), true);
1326         assertEquals(a.isEqual(b), false);
1327         assertEquals(a.isAfter(b), false);
1328 
1329         assertEquals(b.isBefore(a), false);
1330         assertEquals(b.isEqual(a), false);
1331         assertEquals(b.isAfter(a), true);
1332 
1333         assertEquals(a.isBefore(a), false);
1334         assertEquals(b.isBefore(b), false);
1335 
1336         assertEquals(a.isEqual(a), true);
1337         assertEquals(b.isEqual(b), true);
1338 
1339         assertEquals(a.isAfter(a), false);
1340         assertEquals(b.isAfter(b), false);
1341     }
1342 
1343     @Test(groups={"tck"})
1344     public void test_isBeforeIsAfterIsEqual_instantComparison() {
1345         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(10, 0), OFFSET_PONE);
1346         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 0), OFFSET_PTWO);  // a is same instant as b
1347         assertEquals(a.isBefore(b), false);
1348         assertEquals(a.isEqual(b), true);
1349         assertEquals(a.isAfter(b), false);
1350 
1351         assertEquals(b.isBefore(a), false);
1352         assertEquals(b.isEqual(a), true);
1353         assertEquals(b.isAfter(a), false);
1354 
1355         assertEquals(a.isBefore(a), false);
1356         assertEquals(b.isBefore(b), false);
1357 
1358         assertEquals(a.isEqual(a), true);
1359         assertEquals(b.isEqual(b), true);
1360 
1361         assertEquals(a.isAfter(a), false);
1362         assertEquals(b.isAfter(b), false);
1363     }
1364 
1365     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1366     public void test_isBefore_null() {
1367         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1368         a.isBefore(null);
1369     }
1370 
1371     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1372     public void test_isEqual_null() {
1373         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1374         a.isEqual(null);
1375     }
1376 
1377     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1378     public void test_isAfter_null() {
1379         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
1380         a.isAfter(null);
1381     }
1382 
1383     //-----------------------------------------------------------------------
1384     // equals() / hashCode()
1385     //-----------------------------------------------------------------------
1386     @Test(dataProvider="sampleTimes", groups={"tck"})
1387     public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1388         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1389         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1390         assertEquals(a.equals(b), true);
1391         assertEquals(a.hashCode() == b.hashCode(), true);
1392     }
1393     @Test(dataProvider="sampleTimes", groups={"tck"})
1394     public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1395         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1396         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y + 1, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1397         assertEquals(a.equals(b), false);
1398     }
1399     @Test(dataProvider="sampleTimes", groups={"tck"})
1400     public void test_equals_false_hour_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1401         h = (h == 23 ? 22 : h);
1402         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1403         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h + 1, m, s, n), OFFSET_PONE);
1404         assertEquals(a.equals(b), false);
1405     }
1406     @Test(dataProvider="sampleTimes", groups={"tck"})
1407     public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1408         m = (m == 59 ? 58 : m);
1409         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1410         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m + 1, s, n), OFFSET_PONE);
1411         assertEquals(a.equals(b), false);
1412     }
1413     @Test(dataProvider="sampleTimes", groups={"tck"})
1414     public void test_equals_false_second_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1415         s = (s == 59 ? 58 : s);
1416         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1417         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s + 1, n), OFFSET_PONE);
1418         assertEquals(a.equals(b), false);
1419     }
1420     @Test(dataProvider="sampleTimes", groups={"tck"})
1421     public void test_equals_false_nano_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1422         n = (n == 999999999 ? 999999998 : n);
1423         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1424         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n + 1), OFFSET_PONE);
1425         assertEquals(a.equals(b), false);
1426     }
1427     @Test(dataProvider="sampleTimes", groups={"tck"})
1428     public void test_equals_false_offset_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) {
1429         OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE);
1430         OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PTWO);
1431         assertEquals(a.equals(b), false);
1432     }
1433 
1434     @Test(groups={"tck"})
1435     public void test_equals_itself_true() {
1436         assertEquals(TEST_2008_6_30_11_30_59_000000500.equals(TEST_2008_6_30_11_30_59_000000500), true);
1437     }
1438 
1439     @Test(groups={"tck"})
1440     public void test_equals_string_false() {
1441         assertEquals(TEST_2008_6_30_11_30_59_000000500.equals("2007-07-15"), false);
1442     }
1443 
1444     @Test(groups={"tck"})
1445     public void test_equals_null_false() {
1446         assertEquals(TEST_2008_6_30_11_30_59_000000500.equals(null), false);
1447     }
1448 
1449     //-----------------------------------------------------------------------
1450     // toString()
1451     //-----------------------------------------------------------------------
1452     @DataProvider(name="sampleToString")
1453     Object[][] provider_sampleToString() {
1454         return new Object[][] {
1455             {2008, 6, 30, 11, 30, 59, 0, "Z", "2008-06-30T11:30:59Z"},
1456             {2008, 6, 30, 11, 30, 59, 0, "+01:00", "2008-06-30T11:30:59+01:00"},
1457             {2008, 6, 30, 11, 30, 59, 999000000, "Z", "2008-06-30T11:30:59.999Z"},
1458             {2008, 6, 30, 11, 30, 59, 999000000, "+01:00", "2008-06-30T11:30:59.999+01:00"},
1459             {2008, 6, 30, 11, 30, 59, 999000, "Z", "2008-06-30T11:30:59.000999Z"},
1460             {2008, 6, 30, 11, 30, 59, 999000, "+01:00", "2008-06-30T11:30:59.000999+01:00"},
1461             {2008, 6, 30, 11, 30, 59, 999, "Z", "2008-06-30T11:30:59.000000999Z"},
1462             {2008, 6, 30, 11, 30, 59, 999, "+01:00", "2008-06-30T11:30:59.000000999+01:00"},
1463         };
1464     }
1465 
1466     @Test(dataProvider="sampleToString", groups={"tck"})
1467     public void test_toString(int y, int o, int d, int h, int m, int s, int n, String offsetId, String expected) {
1468         OffsetDateTime t = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), ZoneOffset.of(offsetId));
1469         String str = t.toString();
1470         assertEquals(str, expected);
1471     }
1472 
1473     //-----------------------------------------------------------------------
1474     // toString(DateTimeFormatter)
1475     //-----------------------------------------------------------------------
1476     @Test(groups={"tck"})
1477     public void test_toString_formatter() {
1478         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
1479         String t = OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), OFFSET_PONE).toString(f);
1480         assertEquals(t, "2010 12 3 11 30 0");
1481     }
1482 
1483     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1484     public void test_toString_formatter_null() {
1485         OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), OFFSET_PONE).toString(null);
1486     }
1487 
1488 }


  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     }


 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();


 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);


 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() {


 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 


 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);


 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);


 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);


 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 }