java.time.format.DecimalStyle Java Examples

The following examples show how to use java.time.format.DecimalStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestZoneTextPrinterParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@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);

}
 
Example #2
Source File: TCKDateTimeFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #3
Source File: TCKDateTimeFormatter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parse_CharSequence_ParsePosition() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parse("XXXONE30XXX", pos);
    assertEquals(pos.getIndex(), 8);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    assertEquals(result.isSupported(HOUR_OF_DAY), false);
}
 
Example #4
Source File: TCKDateTimeFormatter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_parseObject_StringParsePosition_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
    assertEquals(pos.getIndex(), 0);  // TODO: is this right?
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
 
Example #5
Source File: TCKDateTimeFormatter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseIncomplete() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONE30SomethingElse", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONE30SomethingElse"), true);
        assertEquals(ex.getParsedString(), "ONE30SomethingElse");
        assertEquals(ex.getErrorIndex(), 5);
        throw ex;
    }
}
 
Example #6
Source File: TCKDateTimeFormatter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test(expected=DateTimeParseException.class)
public void test_parseBest_String_parseIncomplete() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONE30SomethingElse", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONE30SomethingElse"), true);
        assertEquals(ex.getParsedString(), "ONE30SomethingElse");
        assertEquals(ex.getErrorIndex(), 5);
        throw ex;
    }
}
 
Example #7
Source File: TCKDateTimeFormatter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_format() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
 
Example #8
Source File: TCKDateTimeFormatter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parse_CharSequence_ParsePosition() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parse("XXXONE30XXX", pos);
    assertEquals(pos.getIndex(), 8);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    assertEquals(result.isSupported(HOUR_OF_DAY), false);
}
 
Example #9
Source File: TCKDateTimeFormatter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_parseObject_String() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #10
Source File: TCKDateTimeFormatter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #11
Source File: TCKDecimalStyle.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equalsHashCode3() {
    DecimalStyle a = DecimalStyle.STANDARD.withZeroDigit('A');
    DecimalStyle b = DecimalStyle.STANDARD.withDecimalSeparator('A');
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
}
 
Example #12
Source File: TCKDateTimeFormatter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=ParseException.class)
public void test_toFormat_parseObject_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    try {
        format.parseObject("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #13
Source File: TCKDateTimeFormatter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_parseObject_String() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #14
Source File: TCKDecimalStyle.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equalsHashCode3() {
    DecimalStyle a = DecimalStyle.STANDARD.withZeroDigit('A');
    DecimalStyle b = DecimalStyle.STANDARD.withDecimalSeparator('A');
    assertEquals(a.equals(b), false);
    assertEquals(b.equals(a), false);
}
 
Example #15
Source File: TCKDateTimeFormatter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #16
Source File: TCKDecimalStyle.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_STANDARD() {
    DecimalStyle loc1 = DecimalStyle.STANDARD;
    assertEquals(loc1.getZeroDigit(), '0');
    assertEquals(loc1.getPositiveSign(), '+');
    assertEquals(loc1.getNegativeSign(), '-');
    assertEquals(loc1.getDecimalSeparator(), '.');
}
 
Example #17
Source File: TCKDateTimeFormatter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parseUnresolved_StringParsePosition() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = test.parseUnresolved("ONE30XXX", pos);
    assertEquals(pos.getIndex(), 5);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #18
Source File: JFXDatePickerContent.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private String formatYear(YearMonth yearMonth) {
    try {
        Chronology chrono = getPrimaryChronology();
        ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1));
        return yearFormatter.withLocale(getLocale())
            .withChronology(chrono)
            .withDecimalStyle(DecimalStyle.of(getLocale()))
            .format(cDate);
    } catch (DateTimeException ex) {
        // Date is out of range.
        return "";
    }
}
 
Example #19
Source File: TCKDateTimeFormatter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_parseObject_String() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #20
Source File: TCKDateTimeFormatter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_toFormat_parseObject_String() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #21
Source File: TCKDateTimeFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #22
Source File: TCKDateTimeFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parseUnresolved_StringParsePosition() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = test.parseUnresolved("ONE30XXX", pos);
    assertEquals(pos.getIndex(), 5);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #23
Source File: TCKDecimalStyle.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_of_Locale() {
    DecimalStyle loc1 = DecimalStyle.of(Locale.CANADA);
    assertEquals(loc1.getZeroDigit(), '0');
    assertEquals(loc1.getPositiveSign(), '+');
    assertEquals(loc1.getNegativeSign(), '-');
    assertEquals(loc1.getDecimalSeparator(), '.');
}
 
Example #24
Source File: TCKDateTimeFormatter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parseUnresolved_StringParsePosition_parseError() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = test.parseUnresolved("ONEXXX", pos);
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
 
Example #25
Source File: TCKDecimalStyle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_equalsHashCode2() {
    DecimalStyle a = DecimalStyle.STANDARD.withZeroDigit('A');
    DecimalStyle b = DecimalStyle.STANDARD.withZeroDigit('A');
    assertEquals(a.equals(b), true);
    assertEquals(b.equals(a), true);
    assertEquals(a.hashCode(), b.hashCode());
}
 
Example #26
Source File: TCKDateTimeFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #27
Source File: TCKDateTimeFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=ParseException.class)
public void test_toFormat_parseObject_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    try {
        format.parseObject("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
Example #28
Source File: TCKDateTimeFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void test_parseBest_String_parseIncomplete() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    try {
        test.parseBest("ONE30SomethingElse", ZonedDateTime::from, LocalDate::from);
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("could not be parsed"), true);
        assertEquals(ex.getMessage().contains("ONE30SomethingElse"), true);
        assertEquals(ex.getParsedString(), "ONE30SomethingElse");
        assertEquals(ex.getErrorIndex(), 5);
        throw ex;
    }
}
 
Example #29
Source File: TCKDateTimeFormatter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parseUnresolved_StringParsePosition() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = test.parseUnresolved("ONE30XXX", pos);
    assertEquals(pos.getIndex(), 5);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
Example #30
Source File: TCKDateTimeFormatter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_toFormat_parseObject_StringParsePosition_invalidPosition_tooBig() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter dtf = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(6);
    Format test = dtf.toFormat();
    assertNull(test.parseObject("ONE30", pos));
    assertTrue(pos.getErrorIndex() >= 0);
}