Search in sources :

Example 51 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatters method test_pattern_StringLocale.

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@Test
public void test_pattern_StringLocale() {
    DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.UK);
    assertEquals(test.format(LocalDate.of(2012, 6, 30)), "30 Jun 2012");
    assertEquals(test.getLocale(), Locale.UK);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 52 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_print_TemporalAppendable_nullTemporal.

@Test(expectedExceptions = NullPointerException.class)
public void test_print_TemporalAppendable_nullTemporal() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    StringBuilder buf = new StringBuilder();
    test.formatTo((TemporalAccessor) null, buf);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 53 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TestTextPrinter method test_formatDayOfWeek.

@Test(dataProvider = "print_DayOfWeekData")
public void test_formatDayOfWeek(Locale locale, String pattern, String expected, DayOfWeek dayOfWeek) {
    DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
    String text = formatter.format(dayOfWeek);
    assertEquals(text, expected);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 54 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TestZoneTextPrinterParser method test_ParseText.

@Test(dataProvider = "preferredZones")
public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) {
    DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred).toFormatter(locale).withDecimalStyle(DecimalStyle.of(locale));
    String ret = fmt.parse(text, TemporalQueries.zone()).getId();
    System.out.printf("[%-5s %s] %24s -> %s(%s)%n", locale.toString(), style == TextStyle.FULL ? " full" : "short", text, ret, expected);
    assertEquals(ret, expected);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 55 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TestZoneTextPrinterParser method parseText.

private void parseText(Set<String> zids, Locale locale, TextStyle style, boolean ci) {
    System.out.println("---------------------------------------");
    DateTimeFormatter fmt = getFormatter(locale, style, ci);
    for (String[] names : new DateFormatSymbols(locale).getZoneStrings()) {
        if (!zids.contains(names[0])) {
            continue;
        }
        String zid = names[0];
        String expected = ZoneName.toZid(zid, locale);
        parse(fmt, zid, expected, zid, locale, style, ci);
        int i = style == TextStyle.FULL ? 1 : 2;
        for (; i < names.length; i += 2) {
            parse(fmt, zid, expected, names[i], locale, style, ci);
        }
    }
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

DateTimeFormatter (java.time.format.DateTimeFormatter)905 Test (org.junit.Test)297 Test (org.testng.annotations.Test)272 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)229 TemporalAccessor (java.time.temporal.TemporalAccessor)205 LocalDate (java.time.LocalDate)142 ParsePosition (java.text.ParsePosition)94 LocalDateTime (java.time.LocalDateTime)92 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)85 ZonedDateTime (java.time.ZonedDateTime)71 Instant (java.time.Instant)53 DateTimeParseException (java.time.format.DateTimeParseException)50 ZoneId (java.time.ZoneId)39 TemporalField (java.time.temporal.TemporalField)39 WeekFields (java.time.temporal.WeekFields)36 AbstractTCKTest (tck.java.time.AbstractTCKTest)36 DateTimeException (java.time.DateTimeException)34 IOException (java.io.IOException)26 Format (java.text.Format)26 LocalTime (java.time.LocalTime)25