/** * Gets a value using a query. * * @param query the query to use, not null * @return the result, null if not found and optional is true * @throws DateTimeException if the type is not available and the section is not optional */ <R> R getValue(Query<R> query) { R result = this.dateTime.query(query); if (result == null && this.optional == 0) { throw new DateTimeException("Unable to extract value: " + this.dateTime.getClass()); } return result; }
@Override public boolean print(DateTimePrintContext context, StringBuilder buf) { ZoneId zone = context.getValue(Query.ZONE_ID); if (zone == null) { return false; } // TODO: fix getText(textStyle, context.getLocale()) buf.append(zone.getId()); // TODO: Use symbols return true; }
@Override public boolean print(DateTimePrintContext context, StringBuilder buf) { ZoneId zone = context.getValue(Query.ZONE_ID); if (zone == null || (this.regionOnly && zone instanceof ZoneOffset)) { return false; } buf.append(zone.getId()); return true; }
@Override public boolean print(DateTimePrintContext context, StringBuilder buf) { Chrono<?> chrono = context.getValue(Query.CHRONO); if (chrono == null) { return false; } if (this.textStyle == null) { buf.append(chrono.getId()); } else { buf.append(chrono.getId()); // TODO: Use symbols } return true; }
@Test(groups = { "tck" }) public void basicTest_query() { for (DateTimeAccessor sample : samples()) { assertEquals(sample.query(new Query<String>() { @Override public String doQuery(DateTimeAccessor dateTime) { return "foo"; } }), "foo"); } }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_DATE_TIME.query(Query.CHRONO), ISOChrono.INSTANCE); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_DATE_TIME.query(Query.ZONE_ID), this.TEST_DATE_TIME.getZone()); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_DATE_TIME.query(Query.TIME_PRECISION), NANOS); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_DATE_TIME.query(Query.OFFSET), OFFSET_0100); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_2008_6_30_11_30_59_000000500.query(Query.CHRONO), ISOChrono.INSTANCE); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_2008_6_30_11_30_59_000000500.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_2008_6_30_11_30_59_000000500.query(Query.TIME_PRECISION), NANOS); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_2008_6_30_11_30_59_000000500.query(Query.OFFSET), OFFSET_PONE); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(DayOfWeek.FRIDAY.query(Query.CHRONO), null); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(DayOfWeek.FRIDAY.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(DayOfWeek.FRIDAY.query(Query.TIME_PRECISION), null); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_2007_07_15_12_30_40_987654321.query(Query.CHRONO), ISOChrono.INSTANCE); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_2007_07_15_12_30_40_987654321.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_2007_07_15_12_30_40_987654321.query(Query.TIME_PRECISION), NANOS); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_2007_07_15_12_30_40_987654321.query(Query.OFFSET), null); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_2007_07_15.query(Query.CHRONO), ISOChrono.INSTANCE); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_2007_07_15.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_2007_07_15.query(Query.TIME_PRECISION), null); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_2007_07_15.query(Query.OFFSET), null); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_12_30_40_987654321.query(Query.CHRONO), null); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_12_30_40_987654321.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_12_30_40_987654321.query(Query.TIME_PRECISION), NANOS); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_12_30_40_987654321.query(Query.OFFSET), null); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_2007_07_15_PONE.query(Query.CHRONO), ISOChrono.INSTANCE); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_2007_07_15_PONE.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_2007_07_15_PONE.query(Query.TIME_PRECISION), null); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_2007_07_15_PONE.query(Query.OFFSET), OFFSET_PONE); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(this.TEST_11_30_59_500_PONE.query(Query.CHRONO), null); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(this.TEST_11_30_59_500_PONE.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(this.TEST_11_30_59_500_PONE.query(Query.TIME_PRECISION), NANOS); }
@Test(groups = { "tck" }) public void test_query_offset() { assertEquals(this.TEST_11_30_59_500_PONE.query(Query.OFFSET), OFFSET_PONE); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(Instant.EPOCH.query(Query.CHRONO), null); }
@Test(groups = { "tck" }) public void test_query_zone() { assertEquals(Instant.EPOCH.query(Query.ZONE_ID), null); }
@Test(groups = { "tck" }) public void test_query_timePrecision() { assertEquals(Instant.EPOCH.query(Query.TIME_PRECISION), NANOS); }
@Test(groups = { "tck" }) public void test_query_chrono() { assertEquals(Month.JUNE.query(Query.CHRONO), ISOChrono.INSTANCE); }