Search in sources :

Example 96 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class AbstractDateTimeTest method basicTest_get_TemporalField_supported.

//-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test()
public void basicTest_get_TemporalField_supported() {
    for (TemporalAccessor sample : samples()) {
        for (TemporalField field : validFields()) {
            if (sample.range(field).isIntValue()) {
                // no exception
                sample.get(field);
            } else {
                try {
                    sample.get(field);
                    fail("Failed on " + sample + " " + field);
                } catch (DateTimeException ex) {
                // expected
                }
            }
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) Test(org.testng.annotations.Test)

Example 97 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TestDateTimeParsing method test_parse_instantZones_ZDT.

@Test(dataProvider = "instantZones")
public void test_parse_instantZones_ZDT(DateTimeFormatter formatter, String text, ZonedDateTime expected) {
    TemporalAccessor actual = formatter.parse(text);
    assertEquals(ZonedDateTime.from(actual), expected);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 98 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TestDateTimeParsing method test_parse_instantZones_supported.

@Test(dataProvider = "instantZones")
public void test_parse_instantZones_supported(DateTimeFormatter formatter, String text, ZonedDateTime expected) {
    TemporalAccessor actual = formatter.parse(text);
    assertEquals(actual.isSupported(INSTANT_SECONDS), true);
    assertEquals(actual.isSupported(EPOCH_DAY), true);
    assertEquals(actual.isSupported(SECOND_OF_DAY), true);
    assertEquals(actual.isSupported(NANO_OF_SECOND), true);
    assertEquals(actual.isSupported(MICRO_OF_SECOND), true);
    assertEquals(actual.isSupported(MILLI_OF_SECOND), true);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 99 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TestDateTimeFormatter method test_parsed_toString_resolvedDateTime.

@Test
public void test_parsed_toString_resolvedDateTime() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    TemporalAccessor temporal = f.parse("2010-06-30 11:30:56");
    String msg = temporal.toString();
    assertTrue(msg.contains("2010-06-30"), msg);
    assertTrue(msg.contains("11:30:56"), msg);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 100 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TestDateTimeParsing method test_parse_instantNoZone_supported.

@Test(dataProvider = "instantNoZone")
public void test_parse_instantNoZone_supported(DateTimeFormatter formatter, String text, Instant expected) {
    TemporalAccessor actual = formatter.parse(text);
    assertEquals(actual.isSupported(INSTANT_SECONDS), true);
    assertEquals(actual.isSupported(EPOCH_DAY), false);
    assertEquals(actual.isSupported(SECOND_OF_DAY), false);
    assertEquals(actual.isSupported(NANO_OF_SECOND), true);
    assertEquals(actual.isSupported(MICRO_OF_SECOND), true);
    assertEquals(actual.isSupported(MILLI_OF_SECOND), true);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Aggregations

TemporalAccessor (java.time.temporal.TemporalAccessor)217 Test (org.testng.annotations.Test)189 DateTimeFormatter (java.time.format.DateTimeFormatter)101 ParsePosition (java.text.ParsePosition)82 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)61 DateTimeException (java.time.DateTimeException)25 DateTimeParseException (java.time.format.DateTimeParseException)21 TemporalField (java.time.temporal.TemporalField)13 LocalDate (java.time.LocalDate)11 Instant (java.time.Instant)5 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 Chronology (java.time.chrono.Chronology)5 ResolverStyle (java.time.format.ResolverStyle)5 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)4 IsoChronology (java.time.chrono.IsoChronology)4 Format (java.text.Format)3 LocalTime (java.time.LocalTime)3 ZonedDateTime (java.time.ZonedDateTime)3 HijrahChronology (java.time.chrono.HijrahChronology)3 JapaneseChronology (java.time.chrono.JapaneseChronology)3