Java Code Examples for java.text.Format#parseObject()
The following examples show how to use
java.text.Format#parseObject() .
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: ScriptValuesAddedFunctions.java From hop with Apache License 2.0 | 5 votes |
public static Object getFiscalDate( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 2 ) { try { if ( isNull( ArgList ) ) { return null; } else if ( isUndefined( ArgList ) ) { return Context.getUndefinedValue(); } Date dIn = (Date) Context.jsToJava( ArgList[ 0 ], Date.class ); Calendar startDate = Calendar.getInstance(); Calendar fisStartDate = Calendar.getInstance(); Calendar fisOffsetDate = Calendar.getInstance(); startDate.setTime( dIn ); Format dfFormatter = new SimpleDateFormat( "dd.MM.yyyy" ); String strOffsetDate = Context.toString( ArgList[ 1 ] ) + String.valueOf( startDate.get( Calendar.YEAR ) ); Date dOffset = (Date) dfFormatter.parseObject( strOffsetDate ); fisOffsetDate.setTime( dOffset ); String strFisStartDate = "01.01." + String.valueOf( startDate.get( Calendar.YEAR ) + 1 ); fisStartDate.setTime( (Date) dfFormatter.parseObject( strFisStartDate ) ); int iDaysToAdd = (int) ( ( startDate.getTimeInMillis() - fisOffsetDate.getTimeInMillis() ) / 86400000 ); fisStartDate.add( Calendar.DATE, iDaysToAdd ); return fisStartDate.getTime(); } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } } else { throw Context.reportRuntimeError( "The function call getFiscalDate requires 2 arguments." ); } }
Example 2
Source File: TCKDateTimeFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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); }
Example 3
Source File: SecondKaboom.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
protected void parseHelperSuccess(Format f, String parseString, Object expectedResult) { Object result; // First check the parseObject(String) method. try { result = f.parseObject(parseString); result.equals(expectedResult); if (expectedResult == null) { assertTrue(result == expectedResult); } else { assertEquals(result, expectedResult); } } catch (ParseException e) { fail(); } }
Example 4
Source File: TestDateTimeFormatter.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); }
Example 5
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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 6
Source File: TCKDateTimeFormatter.java From hottub with GNU General Public License v2.0 | 5 votes |
@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 7
Source File: TCKDateTimeFormatter.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@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 8
Source File: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 9
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=ParseException.class) public void test_toFormat_parseObject_String_parseError() throws Exception { DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD); Format format = test.toFormat(); try { format.parseObject("ONEXXX"); } catch (ParseException ex) { assertEquals(ex.getMessage().contains("ONEXXX"), true); assertEquals(ex.getErrorOffset(), 3); throw ex; } }
Example 10
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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); }
Example 11
Source File: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_toFormat_parseObject_StringParsePosition() 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("ONE30XXX", pos); assertEquals(pos.getIndex(), 5); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.getLong(DAY_OF_MONTH), 30L); }
Example 12
Source File: TCKDateTimeFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_toFormat_parseObject_StringParsePosition() 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("ONE30XXX", pos); assertEquals(pos.getIndex(), 5); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.getLong(DAY_OF_MONTH), 30L); }
Example 13
Source File: TCKDateTimeFormatter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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 14
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void test_toFormat_parseObject_StringParsePosition() 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("ONE30XXX", pos); assertEquals(pos.getIndex(), 5); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.getLong(DAY_OF_MONTH), 30L); }
Example 15
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_toFormat_parseObject_StringParsePosition() 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("ONE30XXX", pos); assertEquals(pos.getIndex(), 5); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.getLong(DAY_OF_MONTH), 30L); }
Example 16
Source File: TestDateTimeFormatter.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 17
Source File: TCKDateTimeFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ParseException.class) public void test_toFormat_parseObject_StringParsePosition_dateTimeError() throws Exception { Format format = DATE_FORMATTER.toFormat(LocalDate::from); format.parseObject("ONE2012 07 32"); }
Example 18
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ParseException.class) public void test_toFormat_parseObject_StringParsePosition_dateTimeError() throws Exception { Format format = DATE_FORMATTER.toFormat(LocalDate::from); format.parseObject("ONE2012 07 32"); }
Example 19
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void test_toFormat_parseObject_String_null() throws Exception { DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD); Format format = test.toFormat(); format.parseObject((String) null); }
Example 20
Source File: TCKDateTimeFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Test public void test_toFormat_Query_parseObject_String() throws Exception { Format format = DATE_FORMATTER.toFormat(LocalDate::from); LocalDate result = (LocalDate) format.parseObject("ONE2012 07 27"); assertEquals(result, LocalDate.of(2012, 7, 27)); }