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 Project: hottub   Author: dsrg-uoft   File: TestZoneTextPrinterParser.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: TCKDateTimeFormatter.java    License: 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 #3
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TCKDecimalStyle.java    License: 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 #4
Source Project: openjdk-8   Author: bpupadhyaya   File: TCKDateTimeFormatter.java    License: 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 #5
Source Project: jdk8u-dev-jdk   Author: frohoff   File: TCKDateTimeFormatter.java    License: 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 #6
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TCKDateTimeFormatter.java    License: 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 #7
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TCKDateTimeFormatter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_print_TemporalAppendable() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    StringBuilder buf = new StringBuilder();
    test.formatTo(LocalDate.of(2008, 6, 30), buf);
    assertEquals(buf.toString(), "ONE30");
}
 
Example #8
Source Project: jdk8u_jdk   Author: JetBrains   File: TCKDateTimeFormatter.java    License: 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 #9
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TCKDateTimeFormatter.java    License: 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 #10
Source Project: jdk8u60   Author: chenghanpeng   File: TCKDateTimeFormatter.java    License: 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 Project: j2objc   Author: google   File: TCKDateTimeFormatter.java    License: 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 #12
Source Project: openjdk-8-source   Author: keerath   File: TCKDateTimeFormatter.java    License: 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 #13
Source Project: hottub   Author: dsrg-uoft   File: TCKDateTimeFormatter.java    License: 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 Project: hottub   Author: dsrg-uoft   File: TCKDecimalStyle.java    License: 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 Project: dragonwell8_jdk   Author: alibaba   File: TCKDateTimeFormatter.java    License: 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 Project: openjdk-8   Author: bpupadhyaya   File: TCKDecimalStyle.java    License: 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 Project: jdk8u-jdk   Author: frohoff   File: TCKDateTimeFormatter.java    License: 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 #18
Source Project: openjdk-8   Author: bpupadhyaya   File: TCKDateTimeFormatter.java    License: 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 #19
Source Project: JFoenix   Author: jfoenixadmin   File: JFXDatePickerContent.java    License: 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 #20
Source Project: dragonwell8_jdk   Author: alibaba   File: TCKDateTimeFormatter.java    License: 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 Project: TencentKona-8   Author: Tencent   File: TCKDateTimeFormatter.java    License: 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 #22
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TCKDateTimeFormatter.java    License: 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 #23
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TCKDateTimeFormatter.java    License: 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 #24
Source Project: TencentKona-8   Author: Tencent   File: TCKDecimalStyle.java    License: 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 #25
Source Project: TencentKona-8   Author: Tencent   File: TCKDateTimeFormatter.java    License: 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 #26
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TCKDecimalStyle.java    License: 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 #27
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TCKDateTimeFormatter.java    License: 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 #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TCKDateTimeFormatter.java    License: 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 #29
Source Project: jdk8u-jdk   Author: frohoff   File: TCKDateTimeFormatter.java    License: 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 #30
Source Project: jdk8u-jdk   Author: frohoff   File: TCKDateTimeFormatter.java    License: 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);
}