test/java/time/tck/java/time/TCKZonedDateTime.java

Print this page




  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import java.time.*;
  63 import test.java.time.MockSimplePeriod;
  64 
  65 import static java.time.Month.JANUARY;
  66 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
  67 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
  68 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
  69 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
  70 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  71 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  72 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  73 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  74 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  75 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  76 import static java.time.temporal.ChronoField.EPOCH_DAY;
  77 import static java.time.temporal.ChronoField.EPOCH_MONTH;
  78 import static java.time.temporal.ChronoField.ERA;
  79 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  80 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  81 import static java.time.temporal.ChronoField.INSTANT_SECONDS;
  82 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  83 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;


  94 import static java.time.temporal.ChronoField.YEAR;
  95 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  96 import static java.time.temporal.ChronoUnit.DAYS;
  97 import static java.time.temporal.ChronoUnit.HOURS;
  98 import static java.time.temporal.ChronoUnit.MINUTES;
  99 import static java.time.temporal.ChronoUnit.NANOS;
 100 import static java.time.temporal.ChronoUnit.SECONDS;
 101 import static org.testng.Assert.assertEquals;
 102 import static org.testng.Assert.assertTrue;
 103 
 104 import java.io.ByteArrayOutputStream;
 105 import java.io.DataOutputStream;
 106 import java.io.IOException;
 107 import java.util.ArrayList;
 108 import java.util.Arrays;
 109 import java.util.List;
 110 
 111 import java.time.temporal.ChronoField;
 112 import java.time.temporal.ChronoUnit;
 113 import java.time.temporal.Queries;
 114 import java.time.temporal.TemporalSubtractor;
 115 import java.time.temporal.TemporalAdder;
 116 import java.time.temporal.TemporalAdjuster;
 117 import java.time.temporal.TemporalAccessor;
 118 import java.time.temporal.TemporalQuery;
 119 import java.time.temporal.TemporalField;
 120 import java.time.temporal.ISOChrono;
 121 import java.time.temporal.JulianFields;
 122 import test.java.time.temporal.MockFieldNoValue;
 123 
 124 import java.time.format.DateTimeFormatter;
 125 import java.time.format.DateTimeFormatters;
 126 import java.time.format.DateTimeParseException;
 127 import java.time.temporal.OffsetDateTime;
 128 import java.time.temporal.Year;
 129 
 130 import org.testng.annotations.BeforeMethod;
 131 import org.testng.annotations.DataProvider;
 132 import org.testng.annotations.Test;
 133 
 134 /**
 135  * Test ZonedDateTime.
 136  */
 137 @Test
 138 public class TCKZonedDateTime extends AbstractDateTimeTest {
 139 
 140     private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1);
 141     private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2);
 142     private static final ZoneOffset OFFSET_0130 = ZoneOffset.of("+01:30");
 143     private static final ZoneOffset OFFSET_MAX = ZoneOffset.MAX;
 144     private static final ZoneOffset OFFSET_MIN = ZoneOffset.MIN;
 145 
 146     private static final ZoneId ZONE_0100 = OFFSET_0100;
 147     private static final ZoneId ZONE_0200 = OFFSET_0200;
 148     private static final ZoneId ZONE_M0100 = ZoneOffset.ofHours(-1);


 255             dos.writeByte(22);  // time
 256             dos.writeByte(17);
 257             dos.writeByte(59);
 258             dos.writeInt(470_000_000);
 259             dos.writeByte(4);  // offset
 260             dos.writeByte(8);  // zoneId
 261             dos.writeByte(4);
 262         }
 263         byte[] bytes = baos.toByteArray();
 264         ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneOffset.ofHours(1));
 265         assertSerializedBySer(zdt, bytes);
 266     }
 267 
 268     //-----------------------------------------------------------------------
 269     // now()
 270     //-----------------------------------------------------------------------
 271     @Test(groups={"tck"})
 272     public void now() {
 273         ZonedDateTime expected = ZonedDateTime.now(Clock.systemDefaultZone());
 274         ZonedDateTime test = ZonedDateTime.now();
 275         long diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 276         if (diff >= 100000000) {
 277             // may be date change
 278             expected = ZonedDateTime.now(Clock.systemDefaultZone());
 279             test = ZonedDateTime.now();
 280             diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 281         }
 282         assertTrue(diff < 100000000);  // less than 0.1 secs
 283     }
 284 
 285     //-----------------------------------------------------------------------
 286     // now(ZoneId)
 287     //-----------------------------------------------------------------------
 288     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 289     public void now_ZoneId_nullZoneId() {
 290         ZonedDateTime.now((ZoneId) null);
 291     }
 292 
 293     @Test(groups={"tck"})
 294     public void now_ZoneId() {
 295         ZoneId zone = ZoneId.of("UTC+01:02:03");
 296         ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone));
 297         ZonedDateTime test = ZonedDateTime.now(zone);
 298         for (int i = 0; i < 100; i++) {
 299             if (expected.equals(test)) {
 300                 return;


 337         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 338             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 339             ZonedDateTime expected = ZonedDateTime.ofInstant(instant, zone);
 340             Clock clock = Clock.fixed(expected.toInstant(), zone);
 341             ZonedDateTime test = ZonedDateTime.now(clock);
 342             assertEquals(test, expected);
 343         }
 344     }
 345 
 346     @Test(groups={"tck"})
 347     public void now_Clock_allSecsInDay_beforeEpoch() {
 348         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 349         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 350             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 351             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 352             ZonedDateTime test = ZonedDateTime.now(clock);
 353             assertEquals(test.getYear(), 1969);
 354             assertEquals(test.getMonth(), Month.DECEMBER);
 355             assertEquals(test.getDayOfMonth(), 31);
 356             expected = expected.minusSeconds(1);
 357             assertEquals(test.getTime(), expected);
 358             assertEquals(test.getOffset(), ZoneOffset.UTC);
 359             assertEquals(test.getZone(), ZoneOffset.UTC);
 360         }
 361     }
 362 
 363     @Test(groups={"tck"})
 364     public void now_Clock_offsets() {
 365         ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(1970, 1, 1, 12, 0), ZoneOffset.UTC);
 366         for (int i = -9; i < 15; i++) {
 367             ZoneOffset offset = ZoneOffset.ofHours(i);
 368             Clock clock = Clock.fixed(base.toInstant(), offset);
 369             ZonedDateTime test = ZonedDateTime.now(clock);
 370             assertEquals(test.getHour(), (12 + i) % 24);
 371             assertEquals(test.getMinute(), 0);
 372             assertEquals(test.getSecond(), 0);
 373             assertEquals(test.getNano(), 0);
 374             assertEquals(test.getOffset(), offset);
 375             assertEquals(test.getZone(), offset);
 376         }
 377     }
 378 
 379     //-----------------------------------------------------------------------
 380     // dateTime factories
 381     //-----------------------------------------------------------------------
 382     void check(ZonedDateTime test, int y, int m, int d, int h, int min, int s, int n, ZoneOffset offset, ZoneId zone) {
 383         assertEquals(test.getYear(), y);
 384         assertEquals(test.getMonth().getValue(), m);
 385         assertEquals(test.getDayOfMonth(), d);
 386         assertEquals(test.getHour(), h);
 387         assertEquals(test.getMinute(), min);
 388         assertEquals(test.getSecond(), s);
 389         assertEquals(test.getNano(), n);
 390         assertEquals(test.getOffset(), offset);
 391         assertEquals(test.getZone(), zone);
 392     }
 393 
 394     //-----------------------------------------------------------------------
 395     // of(LocalDateTime, ZoneId)
 396     //-----------------------------------------------------------------------
 397     // TODO: tests of overlap/gap































 398 



 399     @Test(groups={"tck"})
 400     public void factory_of_LocalDateTime() {
 401         LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 402         ZonedDateTime test = ZonedDateTime.of(base, ZONE_PARIS);
 403         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 404     }
 405 












 406     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 407     public void factory_of_LocalDateTime_nullDateTime() {
 408         ZonedDateTime.of((LocalDateTime) null, ZONE_PARIS);
 409     }
 410 
 411     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 412     public void factory_of_LocalDateTime_nullZone() {
 413         LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 414         ZonedDateTime.of(base, null);
 415     }
 416 
 417     //-----------------------------------------------------------------------









 418     // ofInstant(Instant, ZoneId)
 419     //-----------------------------------------------------------------------
 420     @Test(groups={"tck"})
 421     public void factory_ofInstant_Instant_ZR() {
 422         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 35).toInstant(OFFSET_0200);
 423         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 424         check(test, 2008, 6, 30, 11, 30, 10, 35, OFFSET_0200, ZONE_PARIS);
 425     }
 426 
 427     @Test(groups={"tck"})
 428     public void factory_ofInstant_Instant_ZO() {
 429         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 45).toInstant(OFFSET_0200);
 430         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_0200);
 431         check(test, 2008, 6, 30, 11, 30, 10, 45, OFFSET_0200, OFFSET_0200);
 432     }
 433 
 434     @Test(groups={"tck"})
 435     public void factory_ofInstant_Instant_inGap() {
 436         Instant instant = TEST_PARIS_GAP_2008_03_30_02_30.toInstant(OFFSET_0100);
 437         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);


 645     }
 646 
 647     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 648     public void factory_ofStrict_LDT_ZI_ZO_nullZI() {
 649         ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0100, null);
 650     }
 651 
 652     //-----------------------------------------------------------------------
 653     // from(TemporalAccessor)
 654     //-----------------------------------------------------------------------
 655     @Test(groups={"tck"})
 656     public void factory_from_TemporalAccessor_ZDT() {
 657         assertEquals(ZonedDateTime.from(TEST_DATE_TIME_PARIS), TEST_DATE_TIME_PARIS);
 658     }
 659 
 660     @Test(groups={"tck"})
 661     public void factory_from_TemporalAccessor_LDT_ZoneId() {
 662         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 663             @Override
 664             public boolean isSupported(TemporalField field) {
 665                 return TEST_DATE_TIME_PARIS.getDateTime().isSupported(field);
 666             }
 667             @Override
 668             public long getLong(TemporalField field) {
 669                 return TEST_DATE_TIME_PARIS.getDateTime().getLong(field);
 670             }
 671             @SuppressWarnings("unchecked")
 672             @Override
 673             public <R> R query(TemporalQuery<R> query) {
 674                 if (query == Queries.zoneId()) {
 675                     return (R) TEST_DATE_TIME_PARIS.getZone();
 676                 }
 677                 return TemporalAccessor.super.query(query);
 678             }
 679         }), TEST_DATE_TIME_PARIS);
 680     }
 681 
 682     @Test(groups={"tck"})
 683     public void factory_from_TemporalAccessor_Instant_ZoneId() {
 684         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 685             @Override
 686             public boolean isSupported(TemporalField field) {
 687                 return field == INSTANT_SECONDS || field == NANO_OF_SECOND;
 688             }
 689 


 699                     return (R) TEST_DATE_TIME_PARIS.getZone();
 700                 }
 701                 return TemporalAccessor.super.query(query);
 702             }
 703         }), TEST_DATE_TIME_PARIS);
 704     }
 705 
 706     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 707     public void factory_from_TemporalAccessor_invalid_noDerive() {
 708         ZonedDateTime.from(LocalTime.of(12, 30));
 709     }
 710 
 711     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 712     public void factory_from_TemporalAccessor_null() {
 713         ZonedDateTime.from((TemporalAccessor) null);
 714     }
 715 
 716     //-----------------------------------------------------------------------
 717     // parse()
 718     //-----------------------------------------------------------------------
 719     @Test(dataProvider="sampleToString", groups={"tck"})
 720     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String zoneId, String text) {
 721         ZonedDateTime t = ZonedDateTime.parse(text);
 722         assertEquals(t.getYear(), y);
 723         assertEquals(t.getMonth().getValue(), month);
 724         assertEquals(t.getDayOfMonth(), d);
 725         assertEquals(t.getHour(), h);
 726         assertEquals(t.getMinute(), m);
 727         assertEquals(t.getSecond(), s);
 728         assertEquals(t.getNano(), n);
 729         assertEquals(t.getZone().getId(), zoneId);
 730     }
 731 































 732     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 733     public void factory_parse_illegalValue() {
 734         ZonedDateTime.parse("2008-06-32T11:15+01:00[Europe/Paris]");
 735     }
 736 
 737     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 738     public void factory_parse_invalidValue() {
 739         ZonedDateTime.parse("2008-06-31T11:15+01:00[Europe/Paris]");
 740     }
 741 
 742     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 743     public void factory_parse_nullText() {
 744         ZonedDateTime.parse((String) null);
 745     }
 746 
 747     //-----------------------------------------------------------------------
 748     // parse(DateTimeFormatter)
 749     //-----------------------------------------------------------------------
 750     @Test(groups={"tck"})
 751     public void factory_parse_formatter() {
 752         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s I");
 753         ZonedDateTime test = ZonedDateTime.parse("2010 12 3 11 30 0 Europe/London", f);
 754         assertEquals(test, ZonedDateTime.of(LocalDateTime.of(2010, 12, 3, 11, 30), ZoneId.of("Europe/London")));
 755     }
 756 
 757     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 758     public void factory_parse_formatter_nullText() {
 759         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
 760         ZonedDateTime.parse((String) null, f);
 761     }
 762 
 763     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 764     public void factory_parse_formatter_nullFormatter() {
 765         ZonedDateTime.parse("ANY", null);
 766     }
 767 
 768     //-----------------------------------------------------------------------
 769     // basics
 770     //-----------------------------------------------------------------------
 771     @DataProvider(name="sampleTimes")
 772     Object[][] provider_sampleTimes() {
 773         return new Object[][] {
 774             {2008, 6, 30, 11, 30, 20, 500, ZONE_0100},
 775             {2008, 6, 30, 11, 0, 0, 0, ZONE_0100},
 776             {2008, 6, 30, 11, 30, 20, 500, ZONE_PARIS},
 777             {2008, 6, 30, 11, 0, 0, 0, ZONE_PARIS},
 778             {2008, 6, 30, 23, 59, 59, 999999999, ZONE_0100},
 779             {-1, 1, 1, 0, 0, 0, 0, ZONE_0100},


 782 
 783     @Test(dataProvider="sampleTimes", groups={"tck"})
 784     public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) {
 785         LocalDate localDate = LocalDate.of(y, o, d);
 786         LocalTime localTime = LocalTime.of(h, m, s, n);
 787         LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
 788         ZoneOffset offset = zone.getRules().getOffset(localDateTime);
 789         ZonedDateTime a = ZonedDateTime.of(localDateTime, zone);
 790 
 791         assertEquals(a.getYear(), localDate.getYear());
 792         assertEquals(a.getMonth(), localDate.getMonth());
 793         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 794         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 795         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 796 
 797         assertEquals(a.getHour(), localTime.getHour());
 798         assertEquals(a.getMinute(), localTime.getMinute());
 799         assertEquals(a.getSecond(), localTime.getSecond());
 800         assertEquals(a.getNano(), localTime.getNano());
 801 
 802         assertEquals(a.getDate(), localDate);
 803         assertEquals(a.getTime(), localTime);
 804         assertEquals(a.getDateTime(), localDateTime);
 805         if (zone instanceof ZoneOffset) {
 806             assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 807         } else {
 808             assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
 809         }
 810     }
 811 
 812     //-----------------------------------------------------------------------
 813     // get(TemporalField)
 814     //-----------------------------------------------------------------------
 815     @Test
 816     public void test_get_TemporalField() {
 817         ZonedDateTime test = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321), ZONE_0100);
 818         assertEquals(test.get(ChronoField.YEAR), 2008);
 819         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 820         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 821         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 822         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 823 
 824         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);


 839         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 840         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 841         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 842 
 843         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 844         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 845         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 846         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 847         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 848         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 849 
 850         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 851         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
 852     }
 853 
 854     //-----------------------------------------------------------------------
 855     // query(TemporalQuery)
 856     //-----------------------------------------------------------------------
 857     @Test
 858     public void test_query_chrono() {
 859         assertEquals(TEST_DATE_TIME.query(Queries.chrono()), ISOChrono.INSTANCE);
 860         assertEquals(Queries.chrono().queryFrom(TEST_DATE_TIME), ISOChrono.INSTANCE);
 861     }
 862 
 863     @Test
 864     public void test_query_zoneId() {
 865         assertEquals(TEST_DATE_TIME.query(Queries.zoneId()), TEST_DATE_TIME.getZone());
 866         assertEquals(Queries.zoneId().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
 867     }
 868 
 869     @Test
 870     public void test_query_precision() {
 871         assertEquals(TEST_DATE_TIME.query(Queries.precision()), NANOS);
 872         assertEquals(Queries.precision().queryFrom(TEST_DATE_TIME), NANOS);
 873     }
 874 
 875     @Test
 876     public void test_query_offset() {
 877         assertEquals(TEST_DATE_TIME.query(Queries.offset()), TEST_DATE_TIME.getOffset());
 878         assertEquals(Queries.offset().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getOffset());
 879     }
 880 


 887     @Test(expectedExceptions=NullPointerException.class)
 888     public void test_query_null() {
 889         TEST_DATE_TIME.query(null);
 890     }
 891 
 892     //-----------------------------------------------------------------------
 893     // withEarlierOffsetAtOverlap()
 894     //-----------------------------------------------------------------------
 895     @Test(groups={"tck"})
 896     public void test_withEarlierOffsetAtOverlap_notAtOverlap() {
 897         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
 898         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 899         assertEquals(test, base);  // not changed
 900     }
 901 
 902     @Test(groups={"tck"})
 903     public void test_withEarlierOffsetAtOverlap_atOverlap() {
 904         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0100, ZONE_PARIS);
 905         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 906         assertEquals(test.getOffset(), OFFSET_0200);  // offset changed to earlier
 907         assertEquals(test.getDateTime(), base.getDateTime());  // date-time not changed
 908     }
 909 
 910     @Test(groups={"tck"})
 911     public void test_withEarlierOffsetAtOverlap_atOverlap_noChange() {
 912         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0200, ZONE_PARIS);
 913         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 914         assertEquals(test, base);  // not changed
 915     }
 916 
 917     //-----------------------------------------------------------------------
 918     // withLaterOffsetAtOverlap()
 919     //-----------------------------------------------------------------------
 920     @Test(groups={"tck"})
 921     public void test_withLaterOffsetAtOverlap_notAtOverlap() {
 922         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
 923         ZonedDateTime test = base.withLaterOffsetAtOverlap();
 924         assertEquals(test, base);  // not changed
 925     }
 926 
 927     @Test(groups={"tck"})
 928     public void test_withLaterOffsetAtOverlap_atOverlap() {
 929         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0200, ZONE_PARIS);
 930         ZonedDateTime test = base.withLaterOffsetAtOverlap();
 931         assertEquals(test.getOffset(), OFFSET_0100);  // offset changed to later
 932         assertEquals(test.getDateTime(), base.getDateTime());  // date-time not changed
 933     }
 934 
 935     @Test(groups={"tck"})
 936     public void test_withLaterOffsetAtOverlap_atOverlap_noChange() {
 937         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0100, ZONE_PARIS);
 938         ZonedDateTime test = base.withLaterOffsetAtOverlap();
 939         assertEquals(test, base);  // not changed
 940     }
 941 
 942     //-----------------------------------------------------------------------
 943     // withZoneSameLocal(ZoneId)
 944     //-----------------------------------------------------------------------
 945     @Test(groups={"tck"})
 946     public void test_withZoneSameLocal() {
 947         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
 948         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
 949         ZonedDateTime test = base.withZoneSameLocal(ZONE_0200);
 950         assertEquals(test.getDateTime(), base.getDateTime());
 951     }
 952 
 953     @Test(groups={"implementation"})
 954     public void test_withZoneSameLocal_noChange() {
 955         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
 956         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
 957         ZonedDateTime test = base.withZoneSameLocal(ZONE_0100);
 958         assertEquals(test, base);
 959     }
 960 
 961     @Test(groups={"tck"})
 962     public void test_withZoneSameLocal_retainOffset1() {
 963         LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
 964         ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-04:00") );
 965         ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
 966         assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
 967         assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
 968     }
 969 
 970     @Test(groups={"tck"})
 971     public void test_withZoneSameLocal_retainOffset2() {
 972         LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
 973         ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );


1340     @DataProvider(name="plusTime")
1341     Object[][] data_plusTime() {
1342         return new Object[][] {
1343             // normal
1344             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 0, dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1345             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 1, dateTime(2008, 7, 1, 0, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1346             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), -1, dateTime(2008, 6, 30, 22, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1347             // gap
1348             {dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS), 1, dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1349             {dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS), -1, dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1350             // overlap
1351             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1352             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 2, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1353             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 3, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1354             {dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1355             {dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 2, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1356         };
1357     }
1358 
1359     //-----------------------------------------------------------------------
1360     // plus(adjuster)
1361     //-----------------------------------------------------------------------
1362     @Test(groups={"tck"}, dataProvider="plusDays")
1363     public void test_plus_adjuster_Period_days(ZonedDateTime base, long amount, ZonedDateTime expected) {
1364         assertEquals(base.plus(Period.of(amount, DAYS)), expected);
1365     }
1366 
1367     @Test(groups={"tck"}, dataProvider="plusTime")
1368     public void test_plus_adjuster_Period_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1369         assertEquals(base.plus(Period.of(amount, HOURS)), expected);
1370     }
1371 
1372     @Test(groups={"tck"}, dataProvider="plusTime")
1373     public void test_plus_adjuster_Duration_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1374         assertEquals(base.plus(Duration.ofHours(amount)), expected);
1375     }
1376 
1377     @Test(groups={"tck"})
1378     public void test_plus_adjuster() {
1379         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1380         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1381         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2009, 1, 1, 12, 30, 59, 500), ZONE_0100);
1382         assertEquals(t.plus(period), expected);
1383     }
1384 
1385     @Test(groups={"tck"})
1386     public void test_plus_adjuster_Duration() {
1387         Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
1388         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1389         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 16, 36, 5, 500), ZONE_0100);
1390         assertEquals(t.plus(duration), expected);
1391     }
1392 
1393     @Test(groups={"tck"})
1394     public void test_plus_adjuster_Period_zero() {
1395         ZonedDateTime t = TEST_DATE_TIME.plus(MockSimplePeriod.ZERO_DAYS);
1396         assertEquals(t, TEST_DATE_TIME);
1397     }
1398 
1399     @Test(groups={"tck"})
1400     public void test_plus_adjuster_Duration_zero() {
1401         ZonedDateTime t = TEST_DATE_TIME.plus(Duration.ZERO);
1402         assertEquals(t, TEST_DATE_TIME);
1403     }
1404 
1405     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1406     public void test_plus_adjuster_null() {
1407         TEST_DATE_TIME.plus((TemporalAdder) null);
1408     }
1409 
1410     //-----------------------------------------------------------------------
1411     // plus(long,TemporalUnit)
1412     //-----------------------------------------------------------------------
1413     @Test(groups={"tck"}, dataProvider="plusDays")
1414     public void test_plus_longUnit_days(ZonedDateTime base, long amount, ZonedDateTime expected) {
1415         assertEquals(base.plus(amount, DAYS), expected);
1416     }
1417 
1418     @Test(groups={"tck"}, dataProvider="plusTime")
1419     public void test_plus_longUnit_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1420         assertEquals(base.plus(amount, HOURS), expected);
1421     }
1422 
1423     @Test(groups={"tck"}, dataProvider="plusTime")
1424     public void test_plus_longUnit_minutes(ZonedDateTime base, long amount, ZonedDateTime expected) {
1425         assertEquals(base.plus(amount * 60, MINUTES), expected);
1426     }
1427 


1545         assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
1546     }
1547 
1548     //-----------------------------------------------------------------------
1549     // plusNanos()
1550     //-----------------------------------------------------------------------
1551     @Test(groups={"tck"}, dataProvider="plusTime")
1552     public void test_plusNanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
1553         assertEquals(base.plusNanos(amount * 3600_000_000_000L), expected);
1554     }
1555 
1556     @Test(groups={"tck"})
1557     public void test_plusNanos_nanos() {
1558         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1559         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1560         ZonedDateTime test = base.plusNanos(1);
1561         assertEquals(test, ZonedDateTime.of(ldt.plusNanos(1), ZONE_0100));
1562     }
1563 
1564     //-----------------------------------------------------------------------
1565     // minus(adjuster)
1566     //-----------------------------------------------------------------------
1567     @Test(groups={"tck"}, dataProvider="plusDays")
1568     public void test_minus_adjuster_Period_days(ZonedDateTime base, long amount, ZonedDateTime expected) {
1569         assertEquals(base.minus(Period.of(-amount, DAYS)), expected);
1570     }
1571 
1572     @Test(groups={"tck"}, dataProvider="plusTime")
1573     public void test_minus_adjuster_Period_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1574         assertEquals(base.minus(Period.of(-amount, HOURS)), expected);
1575     }
1576 
1577     @Test(groups={"tck"}, dataProvider="plusTime")
1578     public void test_minus_adjuster_Duration_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1579         assertEquals(base.minus(Duration.ofHours(-amount)), expected);
1580     }
1581 
1582     @Test(groups={"tck"})
1583     public void test_minus_adjuster() {
1584         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1585         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1586         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2007, 11, 1, 12, 30, 59, 500), ZONE_0100);
1587         assertEquals(t.minus(period), expected);
1588     }
1589 
1590     @Test(groups={"tck"})
1591     public void test_minus_adjuster_Duration() {
1592         Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
1593         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1594         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 8, 25, 53, 500), ZONE_0100);
1595         assertEquals(t.minus(duration), expected);
1596     }
1597 
1598     @Test(groups={"tck"})
1599     public void test_minus_adjuster_Period_zero() {
1600         ZonedDateTime t = TEST_DATE_TIME.minus(MockSimplePeriod.ZERO_DAYS);
1601         assertEquals(t, TEST_DATE_TIME);
1602     }
1603 
1604     @Test(groups={"tck"})
1605     public void test_minus_adjuster_Duration_zero() {
1606         ZonedDateTime t = TEST_DATE_TIME.minus(Duration.ZERO);
1607         assertEquals(t, TEST_DATE_TIME);
1608     }
1609 
1610     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1611     public void test_minus_adjuster_null() {
1612         TEST_DATE_TIME.minus((TemporalSubtractor) null);
1613     }
1614 
1615     //-----------------------------------------------------------------------
1616     // minusYears()
1617     //-----------------------------------------------------------------------
1618     @Test(groups={"tck"})
1619     public void test_minusYears() {
1620         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1621         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1622         ZonedDateTime test = base.minusYears(1);
1623         assertEquals(test, ZonedDateTime.of(ldt.minusYears(1), ZONE_0100));
1624     }
1625 
1626     @Test(groups={"tck"})
1627     public void test_minusYears_zero() {
1628         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1629         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1630         ZonedDateTime test = base.minusYears(0);
1631         assertEquals(test, base);
1632     }


1801     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
1802     public void test_periodUntil_differentType() {
1803         TEST_DATE_TIME_PARIS.periodUntil(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
1804     }
1805 
1806     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1807     public void test_periodUntil_nullTemporal() {
1808         TEST_DATE_TIME_PARIS.periodUntil(null, DAYS);
1809     }
1810 
1811     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1812     public void test_periodUntil_nullUnit() {
1813         TEST_DATE_TIME_PARIS.periodUntil(TEST_DATE_TIME_PARIS, null);
1814     }
1815 
1816     //-----------------------------------------------------------------------
1817     // toOffsetDateTime()
1818     //-----------------------------------------------------------------------
1819     @Test(groups={"tck"})
1820     public void test_toOffsetDateTime() {
1821         assertEquals(TEST_DATE_TIME.toOffsetDateTime(), OffsetDateTime.of(TEST_DATE_TIME.getDateTime(), TEST_DATE_TIME.getOffset()));
1822     }
1823 
1824     //-----------------------------------------------------------------------
1825     // toInstant()
1826     //-----------------------------------------------------------------------
1827     @DataProvider(name="toInstant")
1828     Object[][] data_toInstant() {
1829         return new Object[][] {
1830             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0), 0L, 0},
1831             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 1), 0L, 1},
1832             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 999_999_999), 0L, 999_999_999},
1833             {LocalDateTime.of(1970, 1, 1, 0, 0, 1, 0), 1L, 0},
1834             {LocalDateTime.of(1970, 1, 1, 0, 0, 1, 1), 1L, 1},
1835             {LocalDateTime.of(1969, 12, 31, 23, 59, 59, 999999999), -1L, 999_999_999},
1836             {LocalDateTime.of(1970, 1, 2, 0, 0), 24L * 60L * 60L, 0},
1837             {LocalDateTime.of(1969, 12, 31, 0, 0), -24L * 60L * 60L, 0},
1838         };
1839     }
1840 
1841     @Test(groups={"tck"}, dataProvider="toInstant")


1891         assertEquals(dt.toEpochSecond(), expectedEpSec);
1892     }
1893 
1894     @Test(groups={"tck"}, dataProvider="toInstant")
1895     public void test_toEpochSecond_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1896         ZonedDateTime dt = ldt.atZone(ZONE_0100);
1897         assertEquals(dt.toEpochSecond(), expectedEpSec - 3600);
1898     }
1899 
1900     @Test(groups={"tck"}, dataProvider="toInstant")
1901     public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1902         ZonedDateTime dt = ldt.atZone(ZONE_M0100);
1903         assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
1904     }
1905 
1906     //-----------------------------------------------------------------------
1907     // compareTo()
1908     //-----------------------------------------------------------------------
1909     @Test(groups={"tck"})
1910     public void test_compareTo_time1() {
1911         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 39), ZONE_0100);
1912         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 41), ZONE_0100);  // a is before b due to time
1913         assertEquals(a.compareTo(b) < 0, true);
1914         assertEquals(b.compareTo(a) > 0, true);
1915         assertEquals(a.compareTo(a) == 0, true);
1916         assertEquals(b.compareTo(b) == 0, true);
1917     }
1918 
1919     @Test(groups={"tck"})
1920     public void test_compareTo_time2() {
1921         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 40, 4), ZONE_0100);
1922         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 40, 5), ZONE_0100);  // a is before b due to time
1923         assertEquals(a.compareTo(b) < 0, true);
1924         assertEquals(b.compareTo(a) > 0, true);
1925         assertEquals(a.compareTo(a) == 0, true);
1926         assertEquals(b.compareTo(b) == 0, true);
1927     }
1928 
1929     @Test(groups={"tck"})
1930     public void test_compareTo_offset1() {
1931         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 41), ZONE_0200);
1932         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 39), ZONE_0100);  // a is before b due to offset
1933         assertEquals(a.compareTo(b) < 0, true);
1934         assertEquals(b.compareTo(a) > 0, true);
1935         assertEquals(a.compareTo(a) == 0, true);
1936         assertEquals(b.compareTo(b) == 0, true);
1937     }
1938 
1939     @Test(groups={"tck"})
1940     public void test_compareTo_offset2() {
1941         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 40, 5), ZoneId.of("UTC+01:01"));
1942         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30, 40, 4), ZONE_0100);  // a is before b due to offset
1943         assertEquals(a.compareTo(b) < 0, true);
1944         assertEquals(b.compareTo(a) > 0, true);
1945         assertEquals(a.compareTo(a) == 0, true);
1946         assertEquals(b.compareTo(b) == 0, true);
1947     }
1948 
1949     @Test(groups={"tck"})
1950     public void test_compareTo_both() {
1951         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 50), ZONE_0200);
1952         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 20), ZONE_0100);  // a is before b on instant scale
1953         assertEquals(a.compareTo(b) < 0, true);
1954         assertEquals(b.compareTo(a) > 0, true);
1955         assertEquals(a.compareTo(a) == 0, true);
1956         assertEquals(b.compareTo(b) == 0, true);
1957     }
1958 
1959     @Test(groups={"tck"})
1960     public void test_compareTo_bothNanos() {
1961         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 20, 40, 5), ZONE_0200);
1962         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 10, 20, 40, 6), ZONE_0100);  // a is before b on instant scale
1963         assertEquals(a.compareTo(b) < 0, true);
1964         assertEquals(b.compareTo(a) > 0, true);
1965         assertEquals(a.compareTo(a) == 0, true);
1966         assertEquals(b.compareTo(b) == 0, true);
1967     }
1968 
1969     @Test(groups={"tck"})
1970     public void test_compareTo_hourDifference() {
1971         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 10, 0), ZONE_0100);
1972         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 0), ZONE_0200);  // a is before b despite being same time-line time
1973         assertEquals(a.compareTo(b) < 0, true);
1974         assertEquals(b.compareTo(a) > 0, true);
1975         assertEquals(a.compareTo(a) == 0, true);
1976         assertEquals(b.compareTo(b) == 0, true);
1977     }
1978 
1979     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1980     public void test_compareTo_null() {
1981         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1982         ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_0100);
1983         a.compareTo(null);
1984     }
1985 
1986     //-----------------------------------------------------------------------
1987     // isBefore()
1988     //-----------------------------------------------------------------------
1989     @DataProvider(name="IsBefore")
1990     Object[][] data_isBefore() {
1991         return new Object[][] {
1992             {11, 30, ZONE_0100, 11, 31, ZONE_0100, true}, // a is before b due to time
1993             {11, 30, ZONE_0200, 11, 30, ZONE_0100, true}, // a is before b due to offset
1994             {11, 30, ZONE_0200, 10, 30, ZONE_0100, false}, // a is equal b due to same instant
1995         };
1996     }
1997 
1998     @Test(dataProvider="IsBefore", groups={"tck"})
1999     public void test_isBefore(int hour1, int minute1, ZoneId zone1, int hour2, int minute2, ZoneId zone2, boolean expected) {
2000         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, hour1, minute1), zone1);
2001         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, hour2, minute2), zone2);
2002         assertEquals(a.isBefore(b), expected);
2003         assertEquals(b.isBefore(a), false);
2004         assertEquals(a.isBefore(a), false);
2005         assertEquals(b.isBefore(b), false);
2006     }
2007 
2008     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2009     public void test_isBefore_null() {
2010         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
2011         ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_0100);
2012         a.isBefore(null);
2013     }
2014 
2015     //-----------------------------------------------------------------------
2016     // isAfter()
2017     //-----------------------------------------------------------------------
2018     @DataProvider(name="IsAfter")
2019     Object[][] data_isAfter() {
2020         return new Object[][] {
2021             {11, 31, ZONE_0100, 11, 30, ZONE_0100, true}, // a is after b due to time
2022             {11, 30, ZONE_0100, 11, 30, ZONE_0200, true}, // a is after b due to offset
2023             {11, 30, ZONE_0200, 10, 30, ZONE_0100, false}, // a is equal b due to same instant
2024         };
2025     }
2026 
2027     @Test(dataProvider="IsAfter", groups={"tck"})
2028     public void test_isAfter(int hour1, int minute1, ZoneId zone1, int hour2, int minute2, ZoneId zone2, boolean expected) {
2029         ZonedDateTime a = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, hour1, minute1), zone1);
2030         ZonedDateTime b = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, hour2, minute2), zone2);
2031         assertEquals(a.isAfter(b), expected);
2032         assertEquals(b.isAfter(a), false);
2033         assertEquals(a.isAfter(a), false);
2034         assertEquals(b.isAfter(b), false);
2035     }
2036 
2037     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2038     public void test_isAfter_null() {
2039         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
2040         ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_0100);
2041         a.isAfter(null);
2042     }
2043 
2044     //-----------------------------------------------------------------------
2045     // equals() / hashCode()
2046     //-----------------------------------------------------------------------
2047     @Test(dataProvider="sampleTimes", groups={"tck"})
2048     public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2049         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2050         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2051         assertEquals(a.equals(b), true);
2052         assertEquals(a.hashCode() == b.hashCode(), true);
2053     }
2054     @Test(dataProvider="sampleTimes", groups={"tck"})
2055     public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2056         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2057         ZonedDateTime b = ZonedDateTime.of(dateTime(y + 1, o, d, h, m, s, n), ZONE_0100);
2058         assertEquals(a.equals(b), false);
2059     }
2060     @Test(dataProvider="sampleTimes", groups={"tck"})


2117             {2008, 6, 30, 11, 30, 59, 999, "Z", "2008-06-30T11:30:59.000000999Z"},
2118             {2008, 6, 30, 11, 30, 59, 999, "+01:00", "2008-06-30T11:30:59.000000999+01:00"},
2119 
2120             {2008, 6, 30, 11, 30, 59, 999, "Europe/London", "2008-06-30T11:30:59.000000999+01:00[Europe/London]"},
2121             {2008, 6, 30, 11, 30, 59, 999, "Europe/Paris", "2008-06-30T11:30:59.000000999+02:00[Europe/Paris]"},
2122         };
2123     }
2124 
2125     @Test(dataProvider="sampleToString", groups={"tck"})
2126     public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
2127         ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
2128         String str = t.toString();
2129         assertEquals(str, expected);
2130     }
2131 
2132     //-----------------------------------------------------------------------
2133     // toString(DateTimeFormatter)
2134     //-----------------------------------------------------------------------
2135     @Test(groups={"tck"})
2136     public void test_toString_formatter() {
2137         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
2138         String t = ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).toString(f);
2139         assertEquals(t, "2010 12 3 11 30 0");
2140     }
2141 
2142     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2143     public void test_toString_formatter_null() {
2144         ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).toString(null);
2145     }
2146 
2147     //-------------------------------------------------------------------------
2148     private static LocalDateTime dateTime(
2149             int year, int month, int dayOfMonth,
2150             int hour, int minute) {
2151         return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
2152     }
2153 
2154     private static LocalDateTime dateTime(
2155                     int year, int month, int dayOfMonth,
2156                     int hour, int minute, int second, int nanoOfSecond) {
2157                 return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);


  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import java.time.*;

  63 
  64 import static java.time.Month.JANUARY;
  65 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
  66 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
  67 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
  68 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
  69 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  70 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  71 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  72 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  73 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  74 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  75 import static java.time.temporal.ChronoField.EPOCH_DAY;
  76 import static java.time.temporal.ChronoField.EPOCH_MONTH;
  77 import static java.time.temporal.ChronoField.ERA;
  78 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  79 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  80 import static java.time.temporal.ChronoField.INSTANT_SECONDS;
  81 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  82 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;


  93 import static java.time.temporal.ChronoField.YEAR;
  94 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  95 import static java.time.temporal.ChronoUnit.DAYS;
  96 import static java.time.temporal.ChronoUnit.HOURS;
  97 import static java.time.temporal.ChronoUnit.MINUTES;
  98 import static java.time.temporal.ChronoUnit.NANOS;
  99 import static java.time.temporal.ChronoUnit.SECONDS;
 100 import static org.testng.Assert.assertEquals;
 101 import static org.testng.Assert.assertTrue;
 102 
 103 import java.io.ByteArrayOutputStream;
 104 import java.io.DataOutputStream;
 105 import java.io.IOException;
 106 import java.util.ArrayList;
 107 import java.util.Arrays;
 108 import java.util.List;
 109 
 110 import java.time.temporal.ChronoField;
 111 import java.time.temporal.ChronoUnit;
 112 import java.time.temporal.Queries;
 113 import java.time.temporal.TemporalAmount;
 114 import java.time.temporal.TemporalAmount;
 115 import java.time.temporal.TemporalAdjuster;
 116 import java.time.temporal.TemporalAccessor;
 117 import java.time.temporal.TemporalQuery;
 118 import java.time.temporal.TemporalField;
 119 import java.time.chrono.IsoChronology;
 120 import java.time.temporal.JulianFields;
 121 import test.java.time.temporal.MockFieldNoValue;
 122 
 123 import java.time.format.DateTimeFormatter;
 124 import java.time.format.DateTimeFormatter;
 125 import java.time.format.DateTimeParseException;
 126 import java.time.OffsetDateTime;
 127 import java.time.Year;
 128 
 129 import org.testng.annotations.BeforeMethod;
 130 import org.testng.annotations.DataProvider;
 131 import org.testng.annotations.Test;
 132 
 133 /**
 134  * Test ZonedDateTime.
 135  */
 136 @Test
 137 public class TCKZonedDateTime extends AbstractDateTimeTest {
 138 
 139     private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1);
 140     private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2);
 141     private static final ZoneOffset OFFSET_0130 = ZoneOffset.of("+01:30");
 142     private static final ZoneOffset OFFSET_MAX = ZoneOffset.MAX;
 143     private static final ZoneOffset OFFSET_MIN = ZoneOffset.MIN;
 144 
 145     private static final ZoneId ZONE_0100 = OFFSET_0100;
 146     private static final ZoneId ZONE_0200 = OFFSET_0200;
 147     private static final ZoneId ZONE_M0100 = ZoneOffset.ofHours(-1);


 254             dos.writeByte(22);  // time
 255             dos.writeByte(17);
 256             dos.writeByte(59);
 257             dos.writeInt(470_000_000);
 258             dos.writeByte(4);  // offset
 259             dos.writeByte(8);  // zoneId
 260             dos.writeByte(4);
 261         }
 262         byte[] bytes = baos.toByteArray();
 263         ZonedDateTime zdt = LocalDateTime.of(2012, 9, 16, 22, 17, 59, 470_000_000).atZone(ZoneOffset.ofHours(1));
 264         assertSerializedBySer(zdt, bytes);
 265     }
 266 
 267     //-----------------------------------------------------------------------
 268     // now()
 269     //-----------------------------------------------------------------------
 270     @Test(groups={"tck"})
 271     public void now() {
 272         ZonedDateTime expected = ZonedDateTime.now(Clock.systemDefaultZone());
 273         ZonedDateTime test = ZonedDateTime.now();
 274         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 275         if (diff >= 100000000) {
 276             // may be date change
 277             expected = ZonedDateTime.now(Clock.systemDefaultZone());
 278             test = ZonedDateTime.now();
 279             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 280         }
 281         assertTrue(diff < 100000000);  // less than 0.1 secs
 282     }
 283 
 284     //-----------------------------------------------------------------------
 285     // now(ZoneId)
 286     //-----------------------------------------------------------------------
 287     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 288     public void now_ZoneId_nullZoneId() {
 289         ZonedDateTime.now((ZoneId) null);
 290     }
 291 
 292     @Test(groups={"tck"})
 293     public void now_ZoneId() {
 294         ZoneId zone = ZoneId.of("UTC+01:02:03");
 295         ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone));
 296         ZonedDateTime test = ZonedDateTime.now(zone);
 297         for (int i = 0; i < 100; i++) {
 298             if (expected.equals(test)) {
 299                 return;


 336         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 337             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 338             ZonedDateTime expected = ZonedDateTime.ofInstant(instant, zone);
 339             Clock clock = Clock.fixed(expected.toInstant(), zone);
 340             ZonedDateTime test = ZonedDateTime.now(clock);
 341             assertEquals(test, expected);
 342         }
 343     }
 344 
 345     @Test(groups={"tck"})
 346     public void now_Clock_allSecsInDay_beforeEpoch() {
 347         LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
 348         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 349             Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
 350             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 351             ZonedDateTime test = ZonedDateTime.now(clock);
 352             assertEquals(test.getYear(), 1969);
 353             assertEquals(test.getMonth(), Month.DECEMBER);
 354             assertEquals(test.getDayOfMonth(), 31);
 355             expected = expected.minusSeconds(1);
 356             assertEquals(test.toLocalTime(), expected);
 357             assertEquals(test.getOffset(), ZoneOffset.UTC);
 358             assertEquals(test.getZone(), ZoneOffset.UTC);
 359         }
 360     }
 361 
 362     @Test(groups={"tck"})
 363     public void now_Clock_offsets() {
 364         ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(1970, 1, 1, 12, 0), ZoneOffset.UTC);
 365         for (int i = -9; i < 15; i++) {
 366             ZoneOffset offset = ZoneOffset.ofHours(i);
 367             Clock clock = Clock.fixed(base.toInstant(), offset);
 368             ZonedDateTime test = ZonedDateTime.now(clock);
 369             assertEquals(test.getHour(), (12 + i) % 24);
 370             assertEquals(test.getMinute(), 0);
 371             assertEquals(test.getSecond(), 0);
 372             assertEquals(test.getNano(), 0);
 373             assertEquals(test.getOffset(), offset);
 374             assertEquals(test.getZone(), offset);
 375         }
 376     }
 377 
 378     //-----------------------------------------------------------------------
 379     // dateTime factories
 380     //-----------------------------------------------------------------------
 381     void check(ZonedDateTime test, int y, int m, int d, int h, int min, int s, int n, ZoneOffset offset, ZoneId zone) {
 382         assertEquals(test.getYear(), y);
 383         assertEquals(test.getMonth().getValue(), m);
 384         assertEquals(test.getDayOfMonth(), d);
 385         assertEquals(test.getHour(), h);
 386         assertEquals(test.getMinute(), min);
 387         assertEquals(test.getSecond(), s);
 388         assertEquals(test.getNano(), n);
 389         assertEquals(test.getOffset(), offset);
 390         assertEquals(test.getZone(), zone);
 391     }
 392 
 393     //-----------------------------------------------------------------------
 394     // of(LocalDate, LocalTime, ZoneId)
 395     //-----------------------------------------------------------------------
 396     @Test(groups={"tck"})
 397     public void factory_of_LocalDateLocalTime() {
 398         ZonedDateTime test = ZonedDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), ZONE_PARIS);
 399         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 400     }
 401 
 402     @Test(groups={"tck"})
 403     public void factory_of_LocalDateLocalTime_inGap() {
 404         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_GAP_2008_03_30_02_30.toLocalDate(), TEST_PARIS_GAP_2008_03_30_02_30.toLocalTime(), ZONE_PARIS);
 405         check(test, 2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // one hour later in summer offset
 406     }
 407 
 408     @Test(groups={"tck"})
 409     public void factory_of_LocalDateLocalTime_inOverlap() {
 410         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_OVERLAP_2008_10_26_02_30.toLocalDate(), TEST_PARIS_OVERLAP_2008_10_26_02_30.toLocalTime(), ZONE_PARIS);
 411         check(test, 2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // same time in summer offset
 412     }
 413 
 414     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 415     public void factory_of_LocalDateLocalTime_nullDate() {
 416         ZonedDateTime.of((LocalDate) null, LocalTime.of(11, 30, 10, 500), ZONE_PARIS);
 417     }
 418 
 419     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 420     public void factory_of_LocalDateLocalTime_nullTime() {
 421         ZonedDateTime.of(LocalDate.of(2008, 6, 30), (LocalTime) null, ZONE_PARIS);
 422     }
 423 
 424     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 425     public void factory_of_LocalDateLocalTime_nullZone() {
 426         ZonedDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), null);
 427     }
 428 
 429     //-----------------------------------------------------------------------
 430     // of(LocalDateTime, ZoneId)
 431     //-----------------------------------------------------------------------
 432     @Test(groups={"tck"})
 433     public void factory_of_LocalDateTime() {
 434         LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 435         ZonedDateTime test = ZonedDateTime.of(base, ZONE_PARIS);
 436         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 437     }
 438 
 439     @Test(groups={"tck"})
 440     public void factory_of_LocalDateTime_inGap() {
 441         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_GAP_2008_03_30_02_30, ZONE_PARIS);
 442         check(test, 2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // one hour later in summer offset
 443     }
 444 
 445     @Test(groups={"tck"})
 446     public void factory_of_LocalDateTime_inOverlap() {
 447         ZonedDateTime test = ZonedDateTime.of(TEST_PARIS_OVERLAP_2008_10_26_02_30, ZONE_PARIS);
 448         check(test, 2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // same time in summer offset
 449     }
 450 
 451     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 452     public void factory_of_LocalDateTime_nullDateTime() {
 453         ZonedDateTime.of((LocalDateTime) null, ZONE_PARIS);
 454     }
 455 
 456     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 457     public void factory_of_LocalDateTime_nullZone() {
 458         LocalDateTime base = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500);
 459         ZonedDateTime.of(base, null);
 460     }
 461 
 462     //-----------------------------------------------------------------------
 463     // of(int..., ZoneId)
 464     //-----------------------------------------------------------------------
 465     @Test(groups={"tck"})
 466     public void factory_of_ints() {
 467         ZonedDateTime test = ZonedDateTime.of(2008, 6, 30, 11, 30, 10, 500, ZONE_PARIS);
 468         check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_0200, ZONE_PARIS);
 469     }
 470 
 471     //-----------------------------------------------------------------------
 472     // ofInstant(Instant, ZoneId)
 473     //-----------------------------------------------------------------------
 474     @Test(groups={"tck"})
 475     public void factory_ofInstant_Instant_ZR() {
 476         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 35).toInstant(OFFSET_0200);
 477         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
 478         check(test, 2008, 6, 30, 11, 30, 10, 35, OFFSET_0200, ZONE_PARIS);
 479     }
 480 
 481     @Test(groups={"tck"})
 482     public void factory_ofInstant_Instant_ZO() {
 483         Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 45).toInstant(OFFSET_0200);
 484         ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_0200);
 485         check(test, 2008, 6, 30, 11, 30, 10, 45, OFFSET_0200, OFFSET_0200);
 486     }
 487 
 488     @Test(groups={"tck"})
 489     public void factory_ofInstant_Instant_inGap() {
 490         Instant instant = TEST_PARIS_GAP_2008_03_30_02_30.toInstant(OFFSET_0100);
 491         ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);


 699     }
 700 
 701     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 702     public void factory_ofStrict_LDT_ZI_ZO_nullZI() {
 703         ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0100, null);
 704     }
 705 
 706     //-----------------------------------------------------------------------
 707     // from(TemporalAccessor)
 708     //-----------------------------------------------------------------------
 709     @Test(groups={"tck"})
 710     public void factory_from_TemporalAccessor_ZDT() {
 711         assertEquals(ZonedDateTime.from(TEST_DATE_TIME_PARIS), TEST_DATE_TIME_PARIS);
 712     }
 713 
 714     @Test(groups={"tck"})
 715     public void factory_from_TemporalAccessor_LDT_ZoneId() {
 716         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 717             @Override
 718             public boolean isSupported(TemporalField field) {
 719                 return TEST_DATE_TIME_PARIS.toLocalDateTime().isSupported(field);
 720             }
 721             @Override
 722             public long getLong(TemporalField field) {
 723                 return TEST_DATE_TIME_PARIS.toLocalDateTime().getLong(field);
 724             }
 725             @SuppressWarnings("unchecked")
 726             @Override
 727             public <R> R query(TemporalQuery<R> query) {
 728                 if (query == Queries.zoneId()) {
 729                     return (R) TEST_DATE_TIME_PARIS.getZone();
 730                 }
 731                 return TemporalAccessor.super.query(query);
 732             }
 733         }), TEST_DATE_TIME_PARIS);
 734     }
 735 
 736     @Test(groups={"tck"})
 737     public void factory_from_TemporalAccessor_Instant_ZoneId() {
 738         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 739             @Override
 740             public boolean isSupported(TemporalField field) {
 741                 return field == INSTANT_SECONDS || field == NANO_OF_SECOND;
 742             }
 743 


 753                     return (R) TEST_DATE_TIME_PARIS.getZone();
 754                 }
 755                 return TemporalAccessor.super.query(query);
 756             }
 757         }), TEST_DATE_TIME_PARIS);
 758     }
 759 
 760     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 761     public void factory_from_TemporalAccessor_invalid_noDerive() {
 762         ZonedDateTime.from(LocalTime.of(12, 30));
 763     }
 764 
 765     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 766     public void factory_from_TemporalAccessor_null() {
 767         ZonedDateTime.from((TemporalAccessor) null);
 768     }
 769 
 770     //-----------------------------------------------------------------------
 771     // parse()
 772     //-----------------------------------------------------------------------
 773     @Test(dataProvider="sampleToString")
 774     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String zoneId, String text) {
 775         ZonedDateTime t = ZonedDateTime.parse(text);
 776         assertEquals(t.getYear(), y);
 777         assertEquals(t.getMonth().getValue(), month);
 778         assertEquals(t.getDayOfMonth(), d);
 779         assertEquals(t.getHour(), h);
 780         assertEquals(t.getMinute(), m);
 781         assertEquals(t.getSecond(), s);
 782         assertEquals(t.getNano(), n);
 783         assertEquals(t.getZone().getId(), zoneId);
 784     }
 785 
 786     @DataProvider(name="parseAdditional")
 787     Object[][] data_parseAdditional() {
 788         return new Object[][] {
 789                 {"2012-06-30T12:30:40Z[GMT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 790                 {"2012-06-30T12:30:40Z[UT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 791                 {"2012-06-30T12:30:40Z[UTC]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 792                 {"2012-06-30T12:30:40+01:00[+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 793                 {"2012-06-30T12:30:40+01:00[GMT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 794                 {"2012-06-30T12:30:40+01:00[UT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 795                 {"2012-06-30T12:30:40+01:00[UTC+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 796                 {"2012-06-30T12:30:40-01:00[-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 797                 {"2012-06-30T12:30:40-01:00[GMT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 798                 {"2012-06-30T12:30:40-01:00[UT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 799                 {"2012-06-30T12:30:40-01:00[UTC-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 800                 {"2012-06-30T12:30:40+01:00[Europe/London]", 2012, 6, 30, 12, 30, 40, 0, "Europe/London"},
 801         };
 802     }
 803 
 804     @Test(dataProvider="parseAdditional")
 805     public void test_parseAdditional(String text, int y, int month, int d, int h, int m, int s, int n, String zoneId) {
 806         ZonedDateTime t = ZonedDateTime.parse(text);
 807         assertEquals(t.getYear(), y);
 808         assertEquals(t.getMonth().getValue(), month);
 809         assertEquals(t.getDayOfMonth(), d);
 810         assertEquals(t.getHour(), h);
 811         assertEquals(t.getMinute(), m);
 812         assertEquals(t.getSecond(), s);
 813         assertEquals(t.getNano(), n);
 814         assertEquals(t.getZone().getId(), zoneId);
 815     }
 816 
 817     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 818     public void factory_parse_illegalValue() {
 819         ZonedDateTime.parse("2008-06-32T11:15+01:00[Europe/Paris]");
 820     }
 821 
 822     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 823     public void factory_parse_invalidValue() {
 824         ZonedDateTime.parse("2008-06-31T11:15+01:00[Europe/Paris]");
 825     }
 826 
 827     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 828     public void factory_parse_nullText() {
 829         ZonedDateTime.parse((String) null);
 830     }
 831 
 832     //-----------------------------------------------------------------------
 833     // parse(DateTimeFormatter)
 834     //-----------------------------------------------------------------------
 835     @Test(groups={"tck"})
 836     public void factory_parse_formatter() {
 837         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s VV");
 838         ZonedDateTime test = ZonedDateTime.parse("2010 12 3 11 30 0 Europe/London", f);
 839         assertEquals(test, ZonedDateTime.of(LocalDateTime.of(2010, 12, 3, 11, 30), ZoneId.of("Europe/London")));
 840     }
 841 
 842     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 843     public void factory_parse_formatter_nullText() {
 844         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 845         ZonedDateTime.parse((String) null, f);
 846     }
 847 
 848     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 849     public void factory_parse_formatter_nullFormatter() {
 850         ZonedDateTime.parse("ANY", null);
 851     }
 852 
 853     //-----------------------------------------------------------------------
 854     // basics
 855     //-----------------------------------------------------------------------
 856     @DataProvider(name="sampleTimes")
 857     Object[][] provider_sampleTimes() {
 858         return new Object[][] {
 859             {2008, 6, 30, 11, 30, 20, 500, ZONE_0100},
 860             {2008, 6, 30, 11, 0, 0, 0, ZONE_0100},
 861             {2008, 6, 30, 11, 30, 20, 500, ZONE_PARIS},
 862             {2008, 6, 30, 11, 0, 0, 0, ZONE_PARIS},
 863             {2008, 6, 30, 23, 59, 59, 999999999, ZONE_0100},
 864             {-1, 1, 1, 0, 0, 0, 0, ZONE_0100},


 867 
 868     @Test(dataProvider="sampleTimes", groups={"tck"})
 869     public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) {
 870         LocalDate localDate = LocalDate.of(y, o, d);
 871         LocalTime localTime = LocalTime.of(h, m, s, n);
 872         LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
 873         ZoneOffset offset = zone.getRules().getOffset(localDateTime);
 874         ZonedDateTime a = ZonedDateTime.of(localDateTime, zone);
 875 
 876         assertEquals(a.getYear(), localDate.getYear());
 877         assertEquals(a.getMonth(), localDate.getMonth());
 878         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 879         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 880         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 881 
 882         assertEquals(a.getHour(), localTime.getHour());
 883         assertEquals(a.getMinute(), localTime.getMinute());
 884         assertEquals(a.getSecond(), localTime.getSecond());
 885         assertEquals(a.getNano(), localTime.getNano());
 886 
 887         assertEquals(a.toLocalDate(), localDate);
 888         assertEquals(a.toLocalTime(), localTime);
 889         assertEquals(a.toLocalDateTime(), localDateTime);
 890         if (zone instanceof ZoneOffset) {
 891             assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 892         } else {
 893             assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
 894         }
 895     }
 896 
 897     //-----------------------------------------------------------------------
 898     // get(TemporalField)
 899     //-----------------------------------------------------------------------
 900     @Test
 901     public void test_get_TemporalField() {
 902         ZonedDateTime test = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321), ZONE_0100);
 903         assertEquals(test.get(ChronoField.YEAR), 2008);
 904         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 905         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 906         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 907         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 908 
 909         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);


 924         assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
 925         assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
 926         assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
 927 
 928         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 929         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 930         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 931         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 932         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 933         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 934 
 935         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 936         assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
 937     }
 938 
 939     //-----------------------------------------------------------------------
 940     // query(TemporalQuery)
 941     //-----------------------------------------------------------------------
 942     @Test
 943     public void test_query_chrono() {
 944         assertEquals(TEST_DATE_TIME.query(Queries.chronology()), IsoChronology.INSTANCE);
 945         assertEquals(Queries.chronology().queryFrom(TEST_DATE_TIME), IsoChronology.INSTANCE);
 946     }
 947 
 948     @Test
 949     public void test_query_zoneId() {
 950         assertEquals(TEST_DATE_TIME.query(Queries.zoneId()), TEST_DATE_TIME.getZone());
 951         assertEquals(Queries.zoneId().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
 952     }
 953 
 954     @Test
 955     public void test_query_precision() {
 956         assertEquals(TEST_DATE_TIME.query(Queries.precision()), NANOS);
 957         assertEquals(Queries.precision().queryFrom(TEST_DATE_TIME), NANOS);
 958     }
 959 
 960     @Test
 961     public void test_query_offset() {
 962         assertEquals(TEST_DATE_TIME.query(Queries.offset()), TEST_DATE_TIME.getOffset());
 963         assertEquals(Queries.offset().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getOffset());
 964     }
 965 


 972     @Test(expectedExceptions=NullPointerException.class)
 973     public void test_query_null() {
 974         TEST_DATE_TIME.query(null);
 975     }
 976 
 977     //-----------------------------------------------------------------------
 978     // withEarlierOffsetAtOverlap()
 979     //-----------------------------------------------------------------------
 980     @Test(groups={"tck"})
 981     public void test_withEarlierOffsetAtOverlap_notAtOverlap() {
 982         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
 983         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 984         assertEquals(test, base);  // not changed
 985     }
 986 
 987     @Test(groups={"tck"})
 988     public void test_withEarlierOffsetAtOverlap_atOverlap() {
 989         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0100, ZONE_PARIS);
 990         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 991         assertEquals(test.getOffset(), OFFSET_0200);  // offset changed to earlier
 992         assertEquals(test.toLocalDateTime(), base.toLocalDateTime());  // date-time not changed
 993     }
 994 
 995     @Test(groups={"tck"})
 996     public void test_withEarlierOffsetAtOverlap_atOverlap_noChange() {
 997         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0200, ZONE_PARIS);
 998         ZonedDateTime test = base.withEarlierOffsetAtOverlap();
 999         assertEquals(test, base);  // not changed
1000     }
1001 
1002     //-----------------------------------------------------------------------
1003     // withLaterOffsetAtOverlap()
1004     //-----------------------------------------------------------------------
1005     @Test(groups={"tck"})
1006     public void test_withLaterOffsetAtOverlap_notAtOverlap() {
1007         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
1008         ZonedDateTime test = base.withLaterOffsetAtOverlap();
1009         assertEquals(test, base);  // not changed
1010     }
1011 
1012     @Test(groups={"tck"})
1013     public void test_withLaterOffsetAtOverlap_atOverlap() {
1014         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0200, ZONE_PARIS);
1015         ZonedDateTime test = base.withLaterOffsetAtOverlap();
1016         assertEquals(test.getOffset(), OFFSET_0100);  // offset changed to later
1017         assertEquals(test.toLocalDateTime(), base.toLocalDateTime());  // date-time not changed
1018     }
1019 
1020     @Test(groups={"tck"})
1021     public void test_withLaterOffsetAtOverlap_atOverlap_noChange() {
1022         ZonedDateTime base = ZonedDateTime.ofStrict(TEST_PARIS_OVERLAP_2008_10_26_02_30, OFFSET_0100, ZONE_PARIS);
1023         ZonedDateTime test = base.withLaterOffsetAtOverlap();
1024         assertEquals(test, base);  // not changed
1025     }
1026 
1027     //-----------------------------------------------------------------------
1028     // withZoneSameLocal(ZoneId)
1029     //-----------------------------------------------------------------------
1030     @Test(groups={"tck"})
1031     public void test_withZoneSameLocal() {
1032         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1033         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1034         ZonedDateTime test = base.withZoneSameLocal(ZONE_0200);
1035         assertEquals(test.toLocalDateTime(), base.toLocalDateTime());
1036     }
1037 
1038     @Test(groups={"tck","implementation"})
1039     public void test_withZoneSameLocal_noChange() {
1040         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1041         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1042         ZonedDateTime test = base.withZoneSameLocal(ZONE_0100);
1043         assertEquals(test, base);
1044     }
1045 
1046     @Test(groups={"tck"})
1047     public void test_withZoneSameLocal_retainOffset1() {
1048         LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
1049         ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-04:00") );
1050         ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
1051         assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
1052         assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
1053     }
1054 
1055     @Test(groups={"tck"})
1056     public void test_withZoneSameLocal_retainOffset2() {
1057         LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
1058         ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );


1425     @DataProvider(name="plusTime")
1426     Object[][] data_plusTime() {
1427         return new Object[][] {
1428             // normal
1429             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 0, dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1430             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), 1, dateTime(2008, 7, 1, 0, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1431             {dateTime(2008, 6, 30, 23, 30, 59, 0, OFFSET_0100, ZONE_0100), -1, dateTime(2008, 6, 30, 22, 30, 59, 0, OFFSET_0100, ZONE_0100)},
1432             // gap
1433             {dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS), 1, dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1434             {dateTime(2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS), -1, dateTime(2008, 3, 30, 1, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1435             // overlap
1436             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS)},
1437             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 2, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1438             {dateTime(2008, 10, 26, 1, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 3, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1439             {dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 1, dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1440             {dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS), 2, dateTime(2008, 10, 26, 3, 30, 0, 0, OFFSET_0100, ZONE_PARIS)},
1441         };
1442     }
1443 
1444     //-----------------------------------------------------------------------
1445     // plus(TemporalAmount)
1446     //-----------------------------------------------------------------------
1447     @Test(groups={"tck"}, dataProvider="plusDays")
1448     public void test_plus_TemporalAmount_Period_days(ZonedDateTime base, int amount, ZonedDateTime expected) {
1449         assertEquals(base.plus(Period.ofDays(amount)), expected);
1450     }
1451 
1452     @Test(groups={"tck"}, dataProvider="plusTime")
1453     public void test_plus_TemporalAmount_Period_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1454         assertEquals(base.plus(MockSimplePeriod.of(amount, HOURS)), expected);
1455     }
1456 
1457     @Test(groups={"tck"}, dataProvider="plusTime")
1458     public void test_plus_TemporalAmount_Duration_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1459         assertEquals(base.plus(Duration.ofHours(amount)), expected);
1460     }
1461 
1462     @Test(groups={"tck"})
1463     public void test_plus_TemporalAmount() {
1464         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1465         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1466         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2009, 1, 1, 12, 30, 59, 500), ZONE_0100);
1467         assertEquals(t.plus(period), expected);
1468     }
1469 
1470     @Test(groups={"tck"})
1471     public void test_plus_TemporalAmount_Duration() {
1472         Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
1473         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1474         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 16, 36, 5, 500), ZONE_0100);
1475         assertEquals(t.plus(duration), expected);
1476     }
1477 
1478     @Test(groups={"tck"})
1479     public void test_plus_TemporalAmount_Period_zero() {
1480         ZonedDateTime t = TEST_DATE_TIME.plus(MockSimplePeriod.ZERO_DAYS);
1481         assertEquals(t, TEST_DATE_TIME);
1482     }
1483 
1484     @Test(groups={"tck"})
1485     public void test_plus_TemporalAmount_Duration_zero() {
1486         ZonedDateTime t = TEST_DATE_TIME.plus(Duration.ZERO);
1487         assertEquals(t, TEST_DATE_TIME);
1488     }
1489 
1490     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1491     public void test_plus_TemporalAmount_null() {
1492         TEST_DATE_TIME.plus((TemporalAmount) null);
1493     }
1494 
1495     //-----------------------------------------------------------------------
1496     // plus(long,TemporalUnit)
1497     //-----------------------------------------------------------------------
1498     @Test(groups={"tck"}, dataProvider="plusDays")
1499     public void test_plus_longUnit_days(ZonedDateTime base, long amount, ZonedDateTime expected) {
1500         assertEquals(base.plus(amount, DAYS), expected);
1501     }
1502 
1503     @Test(groups={"tck"}, dataProvider="plusTime")
1504     public void test_plus_longUnit_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1505         assertEquals(base.plus(amount, HOURS), expected);
1506     }
1507 
1508     @Test(groups={"tck"}, dataProvider="plusTime")
1509     public void test_plus_longUnit_minutes(ZonedDateTime base, long amount, ZonedDateTime expected) {
1510         assertEquals(base.plus(amount * 60, MINUTES), expected);
1511     }
1512 


1630         assertEquals(test, ZonedDateTime.of(ldt.plusSeconds(1), ZONE_0100));
1631     }
1632 
1633     //-----------------------------------------------------------------------
1634     // plusNanos()
1635     //-----------------------------------------------------------------------
1636     @Test(groups={"tck"}, dataProvider="plusTime")
1637     public void test_plusNanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
1638         assertEquals(base.plusNanos(amount * 3600_000_000_000L), expected);
1639     }
1640 
1641     @Test(groups={"tck"})
1642     public void test_plusNanos_nanos() {
1643         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1644         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1645         ZonedDateTime test = base.plusNanos(1);
1646         assertEquals(test, ZonedDateTime.of(ldt.plusNanos(1), ZONE_0100));
1647     }
1648 
1649     //-----------------------------------------------------------------------
1650     // minus(TemporalAmount)
1651     //-----------------------------------------------------------------------
1652     @Test(groups={"tck"}, dataProvider="plusDays")
1653     public void test_minus_TemporalAmount_Period_days(ZonedDateTime base, int amount, ZonedDateTime expected) {
1654         assertEquals(base.minus(Period.ofDays(-amount)), expected);
1655     }
1656 
1657     @Test(groups={"tck"}, dataProvider="plusTime")
1658     public void test_minus_TemporalAmount_Period_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1659         assertEquals(base.minus(MockSimplePeriod.of(-amount, HOURS)), expected);
1660     }
1661 
1662     @Test(groups={"tck"}, dataProvider="plusTime")
1663     public void test_minus_TemporalAmount_Duration_hours(ZonedDateTime base, long amount, ZonedDateTime expected) {
1664         assertEquals(base.minus(Duration.ofHours(-amount)), expected);
1665     }
1666 
1667     @Test(groups={"tck"})
1668     public void test_minus_TemporalAmount() {
1669         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1670         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1671         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2007, 11, 1, 12, 30, 59, 500), ZONE_0100);
1672         assertEquals(t.minus(period), expected);
1673     }
1674 
1675     @Test(groups={"tck"})
1676     public void test_minus_TemporalAmount_Duration() {
1677         Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
1678         ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
1679         ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 8, 25, 53, 500), ZONE_0100);
1680         assertEquals(t.minus(duration), expected);
1681     }
1682 
1683     @Test(groups={"tck"})
1684     public void test_minus_TemporalAmount_Period_zero() {
1685         ZonedDateTime t = TEST_DATE_TIME.minus(MockSimplePeriod.ZERO_DAYS);
1686         assertEquals(t, TEST_DATE_TIME);
1687     }
1688 
1689     @Test(groups={"tck"})
1690     public void test_minus_TemporalAmount_Duration_zero() {
1691         ZonedDateTime t = TEST_DATE_TIME.minus(Duration.ZERO);
1692         assertEquals(t, TEST_DATE_TIME);
1693     }
1694 
1695     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1696     public void test_minus_TemporalAmount_null() {
1697         TEST_DATE_TIME.minus((TemporalAmount) null);
1698     }
1699 
1700     //-----------------------------------------------------------------------
1701     // minusYears()
1702     //-----------------------------------------------------------------------
1703     @Test(groups={"tck"})
1704     public void test_minusYears() {
1705         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1706         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1707         ZonedDateTime test = base.minusYears(1);
1708         assertEquals(test, ZonedDateTime.of(ldt.minusYears(1), ZONE_0100));
1709     }
1710 
1711     @Test(groups={"tck"})
1712     public void test_minusYears_zero() {
1713         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1714         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1715         ZonedDateTime test = base.minusYears(0);
1716         assertEquals(test, base);
1717     }


1886     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
1887     public void test_periodUntil_differentType() {
1888         TEST_DATE_TIME_PARIS.periodUntil(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
1889     }
1890 
1891     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1892     public void test_periodUntil_nullTemporal() {
1893         TEST_DATE_TIME_PARIS.periodUntil(null, DAYS);
1894     }
1895 
1896     @Test(groups={"tck"}, expectedExceptions=NullPointerException.class)
1897     public void test_periodUntil_nullUnit() {
1898         TEST_DATE_TIME_PARIS.periodUntil(TEST_DATE_TIME_PARIS, null);
1899     }
1900 
1901     //-----------------------------------------------------------------------
1902     // toOffsetDateTime()
1903     //-----------------------------------------------------------------------
1904     @Test(groups={"tck"})
1905     public void test_toOffsetDateTime() {
1906         assertEquals(TEST_DATE_TIME.toOffsetDateTime(), OffsetDateTime.of(TEST_DATE_TIME.toLocalDateTime(), TEST_DATE_TIME.getOffset()));
1907     }
1908 
1909     //-----------------------------------------------------------------------
1910     // toInstant()
1911     //-----------------------------------------------------------------------
1912     @DataProvider(name="toInstant")
1913     Object[][] data_toInstant() {
1914         return new Object[][] {
1915             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0), 0L, 0},
1916             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 1), 0L, 1},
1917             {LocalDateTime.of(1970, 1, 1, 0, 0, 0, 999_999_999), 0L, 999_999_999},
1918             {LocalDateTime.of(1970, 1, 1, 0, 0, 1, 0), 1L, 0},
1919             {LocalDateTime.of(1970, 1, 1, 0, 0, 1, 1), 1L, 1},
1920             {LocalDateTime.of(1969, 12, 31, 23, 59, 59, 999999999), -1L, 999_999_999},
1921             {LocalDateTime.of(1970, 1, 2, 0, 0), 24L * 60L * 60L, 0},
1922             {LocalDateTime.of(1969, 12, 31, 0, 0), -24L * 60L * 60L, 0},
1923         };
1924     }
1925 
1926     @Test(groups={"tck"}, dataProvider="toInstant")


1976         assertEquals(dt.toEpochSecond(), expectedEpSec);
1977     }
1978 
1979     @Test(groups={"tck"}, dataProvider="toInstant")
1980     public void test_toEpochSecond_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1981         ZonedDateTime dt = ldt.atZone(ZONE_0100);
1982         assertEquals(dt.toEpochSecond(), expectedEpSec - 3600);
1983     }
1984 
1985     @Test(groups={"tck"}, dataProvider="toInstant")
1986     public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
1987         ZonedDateTime dt = ldt.atZone(ZONE_M0100);
1988         assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
1989     }
1990 
1991     //-----------------------------------------------------------------------
1992     // compareTo()
1993     //-----------------------------------------------------------------------
1994     @Test(groups={"tck"})
1995     public void test_compareTo_time1() {
1996         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 39, 0, ZONE_0100);
1997         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 41, 0, ZONE_0100);  // a is before b due to time
1998         assertEquals(a.compareTo(b) < 0, true);
1999         assertEquals(b.compareTo(a) > 0, true);
2000         assertEquals(a.compareTo(a) == 0, true);
2001         assertEquals(b.compareTo(b) == 0, true);
2002     }
2003 
2004     @Test(groups={"tck"})
2005     public void test_compareTo_time2() {
2006         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 4, ZONE_0100);
2007         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 5, ZONE_0100);  // a is before b due to time
2008         assertEquals(a.compareTo(b) < 0, true);
2009         assertEquals(b.compareTo(a) > 0, true);
2010         assertEquals(a.compareTo(a) == 0, true);
2011         assertEquals(b.compareTo(b) == 0, true);
2012     }
2013 
2014     @Test(groups={"tck"})
2015     public void test_compareTo_offset1() {
2016         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 41, 0, ZONE_0200);
2017         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 39, 0, ZONE_0100);  // a is before b due to offset
2018         assertEquals(a.compareTo(b) < 0, true);
2019         assertEquals(b.compareTo(a) > 0, true);
2020         assertEquals(a.compareTo(a) == 0, true);
2021         assertEquals(b.compareTo(b) == 0, true);
2022     }
2023 
2024     @Test(groups={"tck"})
2025     public void test_compareTo_offset2() {
2026         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 5, ZoneId.of("UTC+01:01"));
2027         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 30, 40, 4, ZONE_0100);  // a is before b due to offset
2028         assertEquals(a.compareTo(b) < 0, true);
2029         assertEquals(b.compareTo(a) > 0, true);
2030         assertEquals(a.compareTo(a) == 0, true);
2031         assertEquals(b.compareTo(b) == 0, true);
2032     }
2033 
2034     @Test(groups={"tck"})
2035     public void test_compareTo_both() {
2036         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 50, 0, 0, ZONE_0200);
2037         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 20, 0, 0, ZONE_0100);  // a is before b on instant scale
2038         assertEquals(a.compareTo(b) < 0, true);
2039         assertEquals(b.compareTo(a) > 0, true);
2040         assertEquals(a.compareTo(a) == 0, true);
2041         assertEquals(b.compareTo(b) == 0, true);
2042     }
2043 
2044     @Test(groups={"tck"})
2045     public void test_compareTo_bothNanos() {
2046         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 11, 20, 40, 5, ZONE_0200);
2047         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 10, 20, 40, 6, ZONE_0100);  // a is before b on instant scale
2048         assertEquals(a.compareTo(b) < 0, true);
2049         assertEquals(b.compareTo(a) > 0, true);
2050         assertEquals(a.compareTo(a) == 0, true);
2051         assertEquals(b.compareTo(b) == 0, true);
2052     }
2053 
2054     @Test(groups={"tck"})
2055     public void test_compareTo_hourDifference() {
2056         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 10, 0, 0, 0, ZONE_0100);
2057         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, 11, 0, 0, 0, ZONE_0200);  // a is before b despite being same time-line time
2058         assertEquals(a.compareTo(b) < 0, true);
2059         assertEquals(b.compareTo(a) > 0, true);
2060         assertEquals(a.compareTo(a) == 0, true);
2061         assertEquals(b.compareTo(b) == 0, true);
2062     }
2063 
2064     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2065     public void test_compareTo_null() {
2066         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);

2067         a.compareTo(null);
2068     }
2069 
2070     //-----------------------------------------------------------------------
2071     // isBefore()
2072     //-----------------------------------------------------------------------
2073     @DataProvider(name="IsBefore")
2074     Object[][] data_isBefore() {
2075         return new Object[][] {
2076             {11, 30, ZONE_0100, 11, 31, ZONE_0100, true}, // a is before b due to time
2077             {11, 30, ZONE_0200, 11, 30, ZONE_0100, true}, // a is before b due to offset
2078             {11, 30, ZONE_0200, 10, 30, ZONE_0100, false}, // a is equal b due to same instant
2079         };
2080     }
2081 
2082     @Test(dataProvider="IsBefore", groups={"tck"})
2083     public void test_isBefore(int hour1, int minute1, ZoneId zone1, int hour2, int minute2, ZoneId zone2, boolean expected) {
2084         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, hour1, minute1, 0, 0, zone1);
2085         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, hour2, minute2, 0, 0, zone2);
2086         assertEquals(a.isBefore(b), expected);
2087         assertEquals(b.isBefore(a), false);
2088         assertEquals(a.isBefore(a), false);
2089         assertEquals(b.isBefore(b), false);
2090     }
2091 
2092     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2093     public void test_isBefore_null() {
2094         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);

2095         a.isBefore(null);
2096     }
2097 
2098     //-----------------------------------------------------------------------
2099     // isAfter()
2100     //-----------------------------------------------------------------------
2101     @DataProvider(name="IsAfter")
2102     Object[][] data_isAfter() {
2103         return new Object[][] {
2104             {11, 31, ZONE_0100, 11, 30, ZONE_0100, true}, // a is after b due to time
2105             {11, 30, ZONE_0100, 11, 30, ZONE_0200, true}, // a is after b due to offset
2106             {11, 30, ZONE_0200, 10, 30, ZONE_0100, false}, // a is equal b due to same instant
2107         };
2108     }
2109 
2110     @Test(dataProvider="IsAfter", groups={"tck"})
2111     public void test_isAfter(int hour1, int minute1, ZoneId zone1, int hour2, int minute2, ZoneId zone2, boolean expected) {
2112         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, hour1, minute1, 0, 0, zone1);
2113         ZonedDateTime b = ZonedDateTime.of(2008, 6, 30, hour2, minute2, 0, 0, zone2);
2114         assertEquals(a.isAfter(b), expected);
2115         assertEquals(b.isAfter(a), false);
2116         assertEquals(a.isAfter(a), false);
2117         assertEquals(b.isAfter(b), false);
2118     }
2119 
2120     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2121     public void test_isAfter_null() {
2122         ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);

2123         a.isAfter(null);
2124     }
2125 
2126     //-----------------------------------------------------------------------
2127     // equals() / hashCode()
2128     //-----------------------------------------------------------------------
2129     @Test(dataProvider="sampleTimes", groups={"tck"})
2130     public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2131         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2132         ZonedDateTime b = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2133         assertEquals(a.equals(b), true);
2134         assertEquals(a.hashCode() == b.hashCode(), true);
2135     }
2136     @Test(dataProvider="sampleTimes", groups={"tck"})
2137     public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneId ignored) {
2138         ZonedDateTime a = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZONE_0100);
2139         ZonedDateTime b = ZonedDateTime.of(dateTime(y + 1, o, d, h, m, s, n), ZONE_0100);
2140         assertEquals(a.equals(b), false);
2141     }
2142     @Test(dataProvider="sampleTimes", groups={"tck"})


2199             {2008, 6, 30, 11, 30, 59, 999, "Z", "2008-06-30T11:30:59.000000999Z"},
2200             {2008, 6, 30, 11, 30, 59, 999, "+01:00", "2008-06-30T11:30:59.000000999+01:00"},
2201 
2202             {2008, 6, 30, 11, 30, 59, 999, "Europe/London", "2008-06-30T11:30:59.000000999+01:00[Europe/London]"},
2203             {2008, 6, 30, 11, 30, 59, 999, "Europe/Paris", "2008-06-30T11:30:59.000000999+02:00[Europe/Paris]"},
2204         };
2205     }
2206 
2207     @Test(dataProvider="sampleToString", groups={"tck"})
2208     public void test_toString(int y, int o, int d, int h, int m, int s, int n, String zoneId, String expected) {
2209         ZonedDateTime t = ZonedDateTime.of(dateTime(y, o, d, h, m, s, n), ZoneId.of(zoneId));
2210         String str = t.toString();
2211         assertEquals(str, expected);
2212     }
2213 
2214     //-----------------------------------------------------------------------
2215     // toString(DateTimeFormatter)
2216     //-----------------------------------------------------------------------
2217     @Test(groups={"tck"})
2218     public void test_toString_formatter() {
2219         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
2220         String t = ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).toString(f);
2221         assertEquals(t, "2010 12 3 11 30 0");
2222     }
2223 
2224     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2225     public void test_toString_formatter_null() {
2226         ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).toString(null);
2227     }
2228 
2229     //-------------------------------------------------------------------------
2230     private static LocalDateTime dateTime(
2231             int year, int month, int dayOfMonth,
2232             int hour, int minute) {
2233         return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
2234     }
2235 
2236     private static LocalDateTime dateTime(
2237                     int year, int month, int dayOfMonth,
2238                     int hour, int minute, int second, int nanoOfSecond) {
2239                 return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);