Search in sources :

Example 6 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_nullParsePosition.

@Test(expectedExceptions = NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullParsePosition() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.parseObject("ONE30", (ParsePosition) null);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 7 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_parseError.

@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);
    // TODO: is this right?
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
Also used : Format(java.text.Format) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 8 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_nullString.

@Test(expectedExceptions = NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullString() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    format.parseObject((String) null, pos);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 9 with Format

use of java.text.Format in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_format_notTemporal.

@Test(expectedExceptions = IllegalArgumentException.class)
public void test_toFormat_format_notTemporal() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.format("Not a Temporal");
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 10 with Format

use of java.text.Format in project phoenix by apache.

the class PhoenixResultSet method getString.

@Override
public String getString(int columnIndex) throws SQLException {
    checkCursorState();
    // Get the value using the expected type instead of trying to coerce to VARCHAR.
    // We can't coerce using our formatter because we don't have enough context in PDataType.
    ColumnProjector projector = rowProjector.getColumnProjector(columnIndex - 1);
    PDataType type = projector.getExpression().getDataType();
    Object value = projector.getValue(currentRow, type, ptr);
    if (wasNull = (value == null)) {
        return null;
    }
    // Run Object through formatter to get String.
    // This provides a simple way of getting a reasonable string representation
    // for types like DATE and TIME
    Format formatter = statement.getFormatter(type);
    return formatter == null ? value.toString() : formatter.format(value);
}
Also used : Format(java.text.Format) PDataType(org.apache.phoenix.schema.types.PDataType) ColumnProjector(org.apache.phoenix.compile.ColumnProjector)

Aggregations

Format (java.text.Format)146 SimpleDateFormat (java.text.SimpleDateFormat)60 DecimalFormat (java.text.DecimalFormat)39 Test (org.junit.Test)38 DateFormat (java.text.DateFormat)34 NumberFormat (java.text.NumberFormat)29 DateTimeFormatter (java.time.format.DateTimeFormatter)27 Date (java.util.Date)26 ChoiceFormat (java.text.ChoiceFormat)24 ParsePosition (java.text.ParsePosition)22 MessageFormat (java.text.MessageFormat)20 FieldPosition (java.text.FieldPosition)16 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)14 ParseException (java.text.ParseException)11 Locale (java.util.Locale)10 AttributedString (java.text.AttributedString)9 ArrayList (java.util.ArrayList)9 TemporalAccessor (java.time.temporal.TemporalAccessor)7 Calendar (java.util.Calendar)7