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

Print this page




 110 import java.time.LocalTime;
 111 import java.time.Month;
 112 import java.time.OffsetDateTime;
 113 import java.time.OffsetTime;
 114 import java.time.Period;
 115 import java.time.Year;
 116 import java.time.ZoneId;
 117 import java.time.ZoneOffset;
 118 import java.time.ZonedDateTime;
 119 import java.time.chrono.IsoChronology;
 120 import java.time.format.DateTimeFormatter;
 121 import java.time.format.DateTimeParseException;
 122 import java.time.temporal.ChronoField;
 123 import java.time.temporal.ChronoUnit;
 124 import java.time.temporal.JulianFields;
 125 import java.time.temporal.TemporalAccessor;
 126 import java.time.temporal.TemporalAdjuster;
 127 import java.time.temporal.TemporalAmount;
 128 import java.time.temporal.TemporalField;
 129 import java.time.temporal.TemporalQuery;

 130 import java.util.ArrayList;
 131 import java.util.Arrays;
 132 import java.util.List;
 133 
 134 import org.testng.annotations.BeforeMethod;
 135 import org.testng.annotations.DataProvider;
 136 import org.testng.annotations.Test;
 137 
 138 /**
 139  * Test ZonedDateTime.
 140  */
 141 @Test
 142 public class TCKZonedDateTime extends AbstractDateTimeTest {
 143 
 144     private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1);
 145     private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2);
 146     private static final ZoneOffset OFFSET_0130 = ZoneOffset.of("+01:30");
 147     private static final ZoneOffset OFFSET_MAX = ZoneOffset.MAX;
 148     private static final ZoneOffset OFFSET_MIN = ZoneOffset.MIN;
 149 


 706     @Test(expectedExceptions=NullPointerException.class)
 707     public void factory_ofStrict_LDT_ZI_ZO_nullZI() {
 708         ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0100, null);
 709     }
 710 
 711     //-----------------------------------------------------------------------
 712     // from(TemporalAccessor)
 713     //-----------------------------------------------------------------------
 714     @Test
 715     public void factory_from_TemporalAccessor_ZDT() {
 716         assertEquals(ZonedDateTime.from(TEST_DATE_TIME_PARIS), TEST_DATE_TIME_PARIS);
 717     }
 718 
 719     @Test
 720     public void factory_from_TemporalAccessor_LDT_ZoneId() {
 721         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 722             @Override
 723             public boolean isSupported(TemporalField field) {
 724                 return TEST_DATE_TIME_PARIS.toLocalDateTime().isSupported(field);
 725             }

 726             @Override
 727             public long getLong(TemporalField field) {
 728                 return TEST_DATE_TIME_PARIS.toLocalDateTime().getLong(field);
 729             }

 730             @SuppressWarnings("unchecked")
 731             @Override
 732             public <R> R query(TemporalQuery<R> query) {
 733                 if (query == TemporalQuery.zoneId()) {
 734                     return (R) TEST_DATE_TIME_PARIS.getZone();
 735                 }
 736                 return TemporalAccessor.super.query(query);
 737             }
 738         }), TEST_DATE_TIME_PARIS);
 739     }
 740 
 741     @Test
 742     public void factory_from_TemporalAccessor_Instant_ZoneId() {
 743         assertEquals(ZonedDateTime.from(new TemporalAccessor() {
 744             @Override
 745             public boolean isSupported(TemporalField field) {
 746                 return field == INSTANT_SECONDS || field == NANO_OF_SECOND;
 747             }
 748 
 749             @Override


 774 
 775     //-----------------------------------------------------------------------
 776     // parse()
 777     //-----------------------------------------------------------------------
 778     @Test(dataProvider="sampleToString")
 779     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String zoneId, String text) {
 780         ZonedDateTime t = ZonedDateTime.parse(text);
 781         assertEquals(t.getYear(), y);
 782         assertEquals(t.getMonth().getValue(), month);
 783         assertEquals(t.getDayOfMonth(), d);
 784         assertEquals(t.getHour(), h);
 785         assertEquals(t.getMinute(), m);
 786         assertEquals(t.getSecond(), s);
 787         assertEquals(t.getNano(), n);
 788         assertEquals(t.getZone().getId(), zoneId);
 789     }
 790 
 791     @DataProvider(name="parseAdditional")
 792     Object[][] data_parseAdditional() {
 793         return new Object[][] {
 794                 {"2012-06-30T12:30:40Z[GMT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 795                 {"2012-06-30T12:30:40Z[UT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 796                 {"2012-06-30T12:30:40Z[UTC]", 2012, 6, 30, 12, 30, 40, 0, "Z"},

 797                 {"2012-06-30T12:30:40+01:00[+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 798                 {"2012-06-30T12:30:40+01:00[GMT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 799                 {"2012-06-30T12:30:40+01:00[UT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 800                 {"2012-06-30T12:30:40+01:00[UTC+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 801                 {"2012-06-30T12:30:40-01:00[-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 802                 {"2012-06-30T12:30:40-01:00[GMT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 803                 {"2012-06-30T12:30:40-01:00[UT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 804                 {"2012-06-30T12:30:40-01:00[UTC-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 805                 {"2012-06-30T12:30:40+01:00[Europe/London]", 2012, 6, 30, 12, 30, 40, 0, "Europe/London"},
 806         };
 807     }
 808 
 809     @Test(dataProvider="parseAdditional")
 810     public void test_parseAdditional(String text, int y, int month, int d, int h, int m, int s, int n, String zoneId) {
 811         ZonedDateTime t = ZonedDateTime.parse(text);
 812         assertEquals(t.getYear(), y);
 813         assertEquals(t.getMonth().getValue(), month);
 814         assertEquals(t.getDayOfMonth(), d);
 815         assertEquals(t.getHour(), h);
 816         assertEquals(t.getMinute(), m);
 817         assertEquals(t.getSecond(), s);
 818         assertEquals(t.getNano(), n);
 819         assertEquals(t.getZone().getId(), zoneId);
 820     }
 821 
 822     @Test(expectedExceptions=DateTimeParseException.class)
 823     public void factory_parse_illegalValue() {
 824         ZonedDateTime.parse("2008-06-32T11:15+01:00[Europe/Paris]");


 883         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 884         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 885         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 886 
 887         assertEquals(a.getHour(), localTime.getHour());
 888         assertEquals(a.getMinute(), localTime.getMinute());
 889         assertEquals(a.getSecond(), localTime.getSecond());
 890         assertEquals(a.getNano(), localTime.getNano());
 891 
 892         assertEquals(a.toLocalDate(), localDate);
 893         assertEquals(a.toLocalTime(), localTime);
 894         assertEquals(a.toLocalDateTime(), localDateTime);
 895         if (zone instanceof ZoneOffset) {
 896             assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 897         } else {
 898             assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
 899         }
 900     }
 901 
 902     //-----------------------------------------------------------------------






























































 903     // get(TemporalField)
 904     //-----------------------------------------------------------------------
 905     @Test
 906     public void test_get_TemporalField() {
 907         ZonedDateTime test = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321), ZONE_0100);
 908         assertEquals(test.get(ChronoField.YEAR), 2008);
 909         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 910         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 911         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 912         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 913 
 914         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 915         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 916         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 917         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 918         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 919         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 920 
 921         assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600);
 922     }


1960         assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
1961     }
1962 
1963     //-----------------------------------------------------------------------
1964     // minusNanos()
1965     //-----------------------------------------------------------------------
1966     @Test(dataProvider="plusTime")
1967     public void test_minusNanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
1968         assertEquals(base.minusNanos(-amount * 3600_000_000_000L), expected);
1969     }
1970 
1971     @Test
1972     public void test_minusNanos_nanos() {
1973         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
1974         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
1975         ZonedDateTime test = base.minusNanos(1);
1976         assertEquals(test, ZonedDateTime.of(ldt.minusNanos(1), ZONE_0100));
1977     }
1978 
1979     //-----------------------------------------------------------------------
1980     // periodUntil(Temporal,TemporalUnit)
1981     //-----------------------------------------------------------------------
1982     // TODO: more tests for period between two different zones
1983     // compare results to OffsetDateTime.periodUntil, especially wrt dates
1984 
1985     @Test(dataProvider="plusDays")
1986     public void test_periodUntil_days(ZonedDateTime base, long expected, ZonedDateTime end) {
1987         if (base.toLocalTime().equals(end.toLocalTime()) == false) {
1988             return;  // avoid DST gap input values
1989         }
1990         assertEquals(base.periodUntil(end, DAYS), expected);
1991     }
1992 
1993     @Test(dataProvider="plusTime")
1994     public void test_periodUntil_hours(ZonedDateTime base, long expected, ZonedDateTime end) {
1995         assertEquals(base.periodUntil(end, HOURS), expected);
1996     }
1997 
1998     @Test(dataProvider="plusTime")
1999     public void test_periodUntil_minutes(ZonedDateTime base, long expected, ZonedDateTime end) {
2000         assertEquals(base.periodUntil(end, MINUTES), expected * 60);
2001     }
2002 
2003     @Test(dataProvider="plusTime")
2004     public void test_periodUntil_seconds(ZonedDateTime base, long expected, ZonedDateTime end) {
2005         assertEquals(base.periodUntil(end, SECONDS), expected * 3600);
2006     }
2007 
2008     @Test(dataProvider="plusTime")
2009     public void test_periodUntil_nanos(ZonedDateTime base, long expected, ZonedDateTime end) {
2010         assertEquals(base.periodUntil(end, NANOS), expected * 3600_000_000_000L);
2011     }
2012 
2013     @Test
2014     public void test_periodUntil_parisLondon() {
2015         ZonedDateTime midnightLondon = LocalDate.of(2012, 6, 28).atStartOfDay(ZONE_LONDON);
2016         ZonedDateTime midnightParis1 = LocalDate.of(2012, 6, 29).atStartOfDay(ZONE_PARIS);
2017         ZonedDateTime oneAm1 = LocalDateTime.of(2012, 6, 29, 1, 0).atZone(ZONE_PARIS);
2018         ZonedDateTime midnightParis2 = LocalDate.of(2012, 6, 30).atStartOfDay(ZONE_PARIS);
2019 
2020         assertEquals(midnightLondon.periodUntil(midnightParis1, HOURS), 23);
2021         assertEquals(midnightLondon.periodUntil(oneAm1, HOURS), 24);
2022         assertEquals(midnightLondon.periodUntil(midnightParis2, HOURS), 23 + 24);
2023 
2024         assertEquals(midnightLondon.periodUntil(midnightParis1, DAYS), 0);
2025         assertEquals(midnightLondon.periodUntil(oneAm1, DAYS), 1);
2026         assertEquals(midnightLondon.periodUntil(midnightParis2, DAYS), 1);
2027     }
2028 
2029     @Test
2030     public void test_periodUntil_gap() {
2031         ZonedDateTime before = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
2032         ZonedDateTime after = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
2033 
2034         assertEquals(before.periodUntil(after, HOURS), 23);
2035         assertEquals(before.periodUntil(after, DAYS), 1);
2036     }
2037 
2038     @Test
2039     public void test_periodUntil_overlap() {
2040         ZonedDateTime before = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
2041         ZonedDateTime after = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
2042 
2043         assertEquals(before.periodUntil(after, HOURS), 25);
2044         assertEquals(before.periodUntil(after, DAYS), 1);
2045     }
2046 
2047     @Test(expectedExceptions=DateTimeException.class)
2048     public void test_periodUntil_differentType() {
2049         TEST_DATE_TIME_PARIS.periodUntil(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
2050     }
2051 
2052     @Test(expectedExceptions=NullPointerException.class)
2053     public void test_periodUntil_nullTemporal() {
2054         TEST_DATE_TIME_PARIS.periodUntil(null, DAYS);
2055     }
2056 
2057     @Test(expectedExceptions=NullPointerException.class)
2058     public void test_periodUntil_nullUnit() {
2059         TEST_DATE_TIME_PARIS.periodUntil(TEST_DATE_TIME_PARIS, null);
2060     }
2061 
2062     //-----------------------------------------------------------------------
2063     // format(DateTimeFormatter)
2064     //-----------------------------------------------------------------------
2065     @Test
2066     public void test_format_formatter() {
2067         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
2068         String t = ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).format(f);
2069         assertEquals(t, "2010 12 3 11 30 0");
2070     }
2071 
2072     @Test(expectedExceptions=NullPointerException.class)
2073     public void test_format_formatter_null() {
2074         ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).format(null);
2075     }
2076 
2077     //-----------------------------------------------------------------------
2078     // toOffsetDateTime()
2079     //-----------------------------------------------------------------------




 110 import java.time.LocalTime;
 111 import java.time.Month;
 112 import java.time.OffsetDateTime;
 113 import java.time.OffsetTime;
 114 import java.time.Period;
 115 import java.time.Year;
 116 import java.time.ZoneId;
 117 import java.time.ZoneOffset;
 118 import java.time.ZonedDateTime;
 119 import java.time.chrono.IsoChronology;
 120 import java.time.format.DateTimeFormatter;
 121 import java.time.format.DateTimeParseException;
 122 import java.time.temporal.ChronoField;
 123 import java.time.temporal.ChronoUnit;
 124 import java.time.temporal.JulianFields;
 125 import java.time.temporal.TemporalAccessor;
 126 import java.time.temporal.TemporalAdjuster;
 127 import java.time.temporal.TemporalAmount;
 128 import java.time.temporal.TemporalField;
 129 import java.time.temporal.TemporalQuery;
 130 import java.time.temporal.TemporalUnit;
 131 import java.util.ArrayList;
 132 import java.util.Arrays;
 133 import java.util.List;
 134 
 135 import org.testng.annotations.BeforeMethod;
 136 import org.testng.annotations.DataProvider;
 137 import org.testng.annotations.Test;
 138 
 139 /**
 140  * Test ZonedDateTime.
 141  */
 142 @Test
 143 public class TCKZonedDateTime extends AbstractDateTimeTest {
 144 
 145     private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1);
 146     private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2);
 147     private static final ZoneOffset OFFSET_0130 = ZoneOffset.of("+01:30");
 148     private static final ZoneOffset OFFSET_MAX = ZoneOffset.MAX;
 149     private static final ZoneOffset OFFSET_MIN = ZoneOffset.MIN;
 150 


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


 777 
 778     //-----------------------------------------------------------------------
 779     // parse()
 780     //-----------------------------------------------------------------------
 781     @Test(dataProvider="sampleToString")
 782     public void test_parse(int y, int month, int d, int h, int m, int s, int n, String zoneId, String text) {
 783         ZonedDateTime t = ZonedDateTime.parse(text);
 784         assertEquals(t.getYear(), y);
 785         assertEquals(t.getMonth().getValue(), month);
 786         assertEquals(t.getDayOfMonth(), d);
 787         assertEquals(t.getHour(), h);
 788         assertEquals(t.getMinute(), m);
 789         assertEquals(t.getSecond(), s);
 790         assertEquals(t.getNano(), n);
 791         assertEquals(t.getZone().getId(), zoneId);
 792     }
 793 
 794     @DataProvider(name="parseAdditional")
 795     Object[][] data_parseAdditional() {
 796         return new Object[][] {
 797                 {"2012-06-30T12:30:40Z[GMT]", 2012, 6, 30, 12, 30, 40, 0, "GMT"},
 798                 {"2012-06-30T12:30:40Z[UT]", 2012, 6, 30, 12, 30, 40, 0, "UT"},
 799                 {"2012-06-30T12:30:40Z[UTC]", 2012, 6, 30, 12, 30, 40, 0, "UTC"},
 800                 {"2012-06-30T12:30:40+01:00[Z]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
 801                 {"2012-06-30T12:30:40+01:00[+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
 802                 {"2012-06-30T12:30:40+01:00[GMT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "GMT+01:00"},
 803                 {"2012-06-30T12:30:40+01:00[UT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "UT+01:00"},
 804                 {"2012-06-30T12:30:40+01:00[UTC+01:00]", 2012, 6, 30, 12, 30, 40, 0, "UTC+01:00"},
 805                 {"2012-06-30T12:30:40-01:00[-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
 806                 {"2012-06-30T12:30:40-01:00[GMT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "GMT-01:00"},
 807                 {"2012-06-30T12:30:40-01:00[UT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "UT-01:00"},
 808                 {"2012-06-30T12:30:40-01:00[UTC-01:00]", 2012, 6, 30, 12, 30, 40, 0, "UTC-01:00"},
 809                 {"2012-06-30T12:30:40+01:00[Europe/London]", 2012, 6, 30, 12, 30, 40, 0, "Europe/London"},
 810         };
 811     }
 812 
 813     @Test(dataProvider="parseAdditional")
 814     public void test_parseAdditional(String text, int y, int month, int d, int h, int m, int s, int n, String zoneId) {
 815         ZonedDateTime t = ZonedDateTime.parse(text);
 816         assertEquals(t.getYear(), y);
 817         assertEquals(t.getMonth().getValue(), month);
 818         assertEquals(t.getDayOfMonth(), d);
 819         assertEquals(t.getHour(), h);
 820         assertEquals(t.getMinute(), m);
 821         assertEquals(t.getSecond(), s);
 822         assertEquals(t.getNano(), n);
 823         assertEquals(t.getZone().getId(), zoneId);
 824     }
 825 
 826     @Test(expectedExceptions=DateTimeParseException.class)
 827     public void factory_parse_illegalValue() {
 828         ZonedDateTime.parse("2008-06-32T11:15+01:00[Europe/Paris]");


 887         assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
 888         assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
 889         assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
 890 
 891         assertEquals(a.getHour(), localTime.getHour());
 892         assertEquals(a.getMinute(), localTime.getMinute());
 893         assertEquals(a.getSecond(), localTime.getSecond());
 894         assertEquals(a.getNano(), localTime.getNano());
 895 
 896         assertEquals(a.toLocalDate(), localDate);
 897         assertEquals(a.toLocalTime(), localTime);
 898         assertEquals(a.toLocalDateTime(), localDateTime);
 899         if (zone instanceof ZoneOffset) {
 900             assertEquals(a.toString(), localDateTime.toString() + offset.toString());
 901         } else {
 902             assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
 903         }
 904     }
 905 
 906     //-----------------------------------------------------------------------
 907     // isSupported(TemporalField)
 908     //-----------------------------------------------------------------------
 909     @Test
 910     public void test_isSupported_TemporalField() {
 911         assertEquals(TEST_DATE_TIME.isSupported((TemporalField) null), false);
 912         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.NANO_OF_SECOND), true);
 913         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.NANO_OF_DAY), true);
 914         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MICRO_OF_SECOND), true);
 915         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MICRO_OF_DAY), true);
 916         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MILLI_OF_SECOND), true);
 917         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MILLI_OF_DAY), true);
 918         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.SECOND_OF_MINUTE), true);
 919         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.SECOND_OF_DAY), true);
 920         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MINUTE_OF_HOUR), true);
 921         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MINUTE_OF_DAY), true);
 922         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.HOUR_OF_AMPM), true);
 923         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
 924         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.HOUR_OF_DAY), true);
 925         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
 926         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.AMPM_OF_DAY), true);
 927         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_WEEK), true);
 928         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
 929         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
 930         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_MONTH), true);
 931         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_YEAR), true);
 932         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.EPOCH_DAY), true);
 933         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
 934         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
 935         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MONTH_OF_YEAR), true);
 936         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.PROLEPTIC_MONTH), true);
 937         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.YEAR), true);
 938         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.YEAR_OF_ERA), true);
 939         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ERA), true);
 940         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.INSTANT_SECONDS), true);
 941         assertEquals(TEST_DATE_TIME.isSupported(ChronoField.OFFSET_SECONDS), true);
 942     }
 943 
 944     //-----------------------------------------------------------------------
 945     // isSupported(TemporalUnit)
 946     //-----------------------------------------------------------------------
 947     @Test
 948     public void test_isSupported_TemporalUnit() {
 949         assertEquals(TEST_DATE_TIME.isSupported((TemporalUnit) null), false);
 950         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.NANOS), true);
 951         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MICROS), true);
 952         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MILLIS), true);
 953         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.SECONDS), true);
 954         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MINUTES), true);
 955         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.HOURS), true);
 956         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.HALF_DAYS), true);
 957         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.DAYS), true);
 958         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.WEEKS), true);
 959         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MONTHS), true);
 960         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.YEARS), true);
 961         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.DECADES), true);
 962         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.CENTURIES), true);
 963         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MILLENNIA), true);
 964         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.ERAS), true);
 965         assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.FOREVER), false);
 966     }
 967 
 968     //-----------------------------------------------------------------------
 969     // get(TemporalField)
 970     //-----------------------------------------------------------------------
 971     @Test
 972     public void test_get_TemporalField() {
 973         ZonedDateTime test = ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321), ZONE_0100);
 974         assertEquals(test.get(ChronoField.YEAR), 2008);
 975         assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
 976         assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
 977         assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
 978         assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);
 979 
 980         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 981         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 982         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 983         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 984         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 985         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 986 
 987         assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600);
 988     }


2026         assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
2027     }
2028 
2029     //-----------------------------------------------------------------------
2030     // minusNanos()
2031     //-----------------------------------------------------------------------
2032     @Test(dataProvider="plusTime")
2033     public void test_minusNanos(ZonedDateTime base, long amount, ZonedDateTime expected) {
2034         assertEquals(base.minusNanos(-amount * 3600_000_000_000L), expected);
2035     }
2036 
2037     @Test
2038     public void test_minusNanos_nanos() {
2039         LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
2040         ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
2041         ZonedDateTime test = base.minusNanos(1);
2042         assertEquals(test, ZonedDateTime.of(ldt.minusNanos(1), ZONE_0100));
2043     }
2044 
2045     //-----------------------------------------------------------------------
2046     // until(Temporal,TemporalUnit)
2047     //-----------------------------------------------------------------------
2048     // TODO: more tests for period between two different zones
2049     // compare results to OffsetDateTime.until, especially wrt dates
2050 
2051     @Test(dataProvider="plusDays")
2052     public void test_periodUntil_days(ZonedDateTime base, long expected, ZonedDateTime end) {
2053         if (base.toLocalTime().equals(end.toLocalTime()) == false) {
2054             return;  // avoid DST gap input values
2055         }
2056         assertEquals(base.until(end, DAYS), expected);
2057     }
2058 
2059     @Test(dataProvider="plusTime")
2060     public void test_periodUntil_hours(ZonedDateTime base, long expected, ZonedDateTime end) {
2061         assertEquals(base.until(end, HOURS), expected);
2062     }
2063 
2064     @Test(dataProvider="plusTime")
2065     public void test_periodUntil_minutes(ZonedDateTime base, long expected, ZonedDateTime end) {
2066         assertEquals(base.until(end, MINUTES), expected * 60);
2067     }
2068 
2069     @Test(dataProvider="plusTime")
2070     public void test_periodUntil_seconds(ZonedDateTime base, long expected, ZonedDateTime end) {
2071         assertEquals(base.until(end, SECONDS), expected * 3600);
2072     }
2073 
2074     @Test(dataProvider="plusTime")
2075     public void test_periodUntil_nanos(ZonedDateTime base, long expected, ZonedDateTime end) {
2076         assertEquals(base.until(end, NANOS), expected * 3600_000_000_000L);
2077     }
2078 
2079     @Test
2080     public void test_periodUntil_parisLondon() {
2081         ZonedDateTime midnightLondon = LocalDate.of(2012, 6, 28).atStartOfDay(ZONE_LONDON);
2082         ZonedDateTime midnightParis1 = LocalDate.of(2012, 6, 29).atStartOfDay(ZONE_PARIS);
2083         ZonedDateTime oneAm1 = LocalDateTime.of(2012, 6, 29, 1, 0).atZone(ZONE_PARIS);
2084         ZonedDateTime midnightParis2 = LocalDate.of(2012, 6, 30).atStartOfDay(ZONE_PARIS);
2085 
2086         assertEquals(midnightLondon.until(midnightParis1, HOURS), 23);
2087         assertEquals(midnightLondon.until(oneAm1, HOURS), 24);
2088         assertEquals(midnightLondon.until(midnightParis2, HOURS), 23 + 24);
2089 
2090         assertEquals(midnightLondon.until(midnightParis1, DAYS), 0);
2091         assertEquals(midnightLondon.until(oneAm1, DAYS), 1);
2092         assertEquals(midnightLondon.until(midnightParis2, DAYS), 1);
2093     }
2094 
2095     @Test
2096     public void test_periodUntil_gap() {
2097         ZonedDateTime before = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
2098         ZonedDateTime after = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
2099 
2100         assertEquals(before.until(after, HOURS), 23);
2101         assertEquals(before.until(after, DAYS), 1);
2102     }
2103 
2104     @Test
2105     public void test_periodUntil_overlap() {
2106         ZonedDateTime before = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
2107         ZonedDateTime after = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
2108 
2109         assertEquals(before.until(after, HOURS), 25);
2110         assertEquals(before.until(after, DAYS), 1);
2111     }
2112 
2113     @Test(expectedExceptions=DateTimeException.class)
2114     public void test_periodUntil_differentType() {
2115         TEST_DATE_TIME_PARIS.until(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
2116     }
2117 
2118     @Test(expectedExceptions=NullPointerException.class)
2119     public void test_periodUntil_nullTemporal() {
2120         TEST_DATE_TIME_PARIS.until(null, DAYS);
2121     }
2122 
2123     @Test(expectedExceptions=NullPointerException.class)
2124     public void test_periodUntil_nullUnit() {
2125         TEST_DATE_TIME_PARIS.until(TEST_DATE_TIME_PARIS, null);
2126     }
2127 
2128     //-----------------------------------------------------------------------
2129     // format(DateTimeFormatter)
2130     //-----------------------------------------------------------------------
2131     @Test
2132     public void test_format_formatter() {
2133         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
2134         String t = ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).format(f);
2135         assertEquals(t, "2010 12 3 11 30 0");
2136     }
2137 
2138     @Test(expectedExceptions=NullPointerException.class)
2139     public void test_format_formatter_null() {
2140         ZonedDateTime.of(dateTime(2010, 12, 3, 11, 30), ZONE_PARIS).format(null);
2141     }
2142 
2143     //-----------------------------------------------------------------------
2144     // toOffsetDateTime()
2145     //-----------------------------------------------------------------------