@Test public void testParse() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); checkParseKettle(); checkParseKettleLong(); checkParseDbDefault(); checkParseLocaleDefault(); } }
@Override public Date parse( String text, ParsePosition pos ) { String timestampFormatDate; Date tempDate; if ( compatibleToSuperPattern ) { tempDate = super.parse( text, pos ); return new Timestamp( tempDate.getTime() ); } StringBuilder dateText = new StringBuilder( text.substring( pos.getIndex() ) ); ParsePosition positionError = new ParsePosition( 0 ); tempDate = super.parse( dateText.toString(), positionError ); if ( tempDate != null ) { pos.setErrorIndex( pos.getIndex() ); return null; } int startNanosecondsPosition = positionError.getErrorIndex(); int endNanosecondsPosition = endNanosecondPatternPosition - startNanosecondPatternPosition + 1 + startNanosecondsPosition; endNanosecondsPosition = ( endNanosecondsPosition >= dateText.length() ) ? dateText.length() : endNanosecondsPosition; String nanoseconds = String.valueOf( dateText.subSequence( startNanosecondsPosition, endNanosecondsPosition ) ); dateText.delete( startNanosecondsPosition, endNanosecondsPosition ); ParsePosition position = new ParsePosition( 0 ); dateText.append( NANOSECOND_PLACEHOLDER ); tempDate = super.parse( dateText.toString(), position ); if ( tempDate == null ) { pos.setErrorIndex( position.getErrorIndex() ); return null; } timestampFormatDate = defaultTimestampFormat.format( tempDate ); String result = timestampFormatDate + '.' + nanoseconds; Timestamp res = Timestamp.valueOf( timestampFormatDate + '.' + nanoseconds ); pos.setIndex( pos.getIndex() + result.length() ); return res; }
SimpleTimestampFormat extends SimpleDateFormat { @Override public Date parse( String text, ParsePosition pos ) { String timestampFormatDate; Date tempDate; if ( compatibleToSuperPattern ) { tempDate = super.parse( text, pos ); return new Timestamp( tempDate.getTime() ); } StringBuilder dateText = new StringBuilder( text.substring( pos.getIndex() ) ); ParsePosition positionError = new ParsePosition( 0 ); tempDate = super.parse( dateText.toString(), positionError ); if ( tempDate != null ) { pos.setErrorIndex( pos.getIndex() ); return null; } int startNanosecondsPosition = positionError.getErrorIndex(); int endNanosecondsPosition = endNanosecondPatternPosition - startNanosecondPatternPosition + 1 + startNanosecondsPosition; endNanosecondsPosition = ( endNanosecondsPosition >= dateText.length() ) ? dateText.length() : endNanosecondsPosition; String nanoseconds = String.valueOf( dateText.subSequence( startNanosecondsPosition, endNanosecondsPosition ) ); dateText.delete( startNanosecondsPosition, endNanosecondsPosition ); ParsePosition position = new ParsePosition( 0 ); dateText.append( NANOSECOND_PLACEHOLDER ); tempDate = super.parse( dateText.toString(), position ); if ( tempDate == null ) { pos.setErrorIndex( position.getErrorIndex() ); return null; } timestampFormatDate = defaultTimestampFormat.format( tempDate ); String result = timestampFormatDate + '.' + nanoseconds; Timestamp res = Timestamp.valueOf( timestampFormatDate + '.' + nanoseconds ); pos.setIndex( pos.getIndex() + result.length() ); return res; } }
SimpleTimestampFormat extends SimpleDateFormat { @Override public Date parse( String text, ParsePosition pos ) { String timestampFormatDate; Date tempDate; if ( compatibleToSuperPattern ) { tempDate = super.parse( text, pos ); return new Timestamp( tempDate.getTime() ); } StringBuilder dateText = new StringBuilder( text.substring( pos.getIndex() ) ); ParsePosition positionError = new ParsePosition( 0 ); tempDate = super.parse( dateText.toString(), positionError ); if ( tempDate != null ) { pos.setErrorIndex( pos.getIndex() ); return null; } int startNanosecondsPosition = positionError.getErrorIndex(); int endNanosecondsPosition = endNanosecondPatternPosition - startNanosecondPatternPosition + 1 + startNanosecondsPosition; endNanosecondsPosition = ( endNanosecondsPosition >= dateText.length() ) ? dateText.length() : endNanosecondsPosition; String nanoseconds = String.valueOf( dateText.subSequence( startNanosecondsPosition, endNanosecondsPosition ) ); dateText.delete( startNanosecondsPosition, endNanosecondsPosition ); ParsePosition position = new ParsePosition( 0 ); dateText.append( NANOSECOND_PLACEHOLDER ); tempDate = super.parse( dateText.toString(), position ); if ( tempDate == null ) { pos.setErrorIndex( position.getErrorIndex() ); return null; } timestampFormatDate = defaultTimestampFormat.format( tempDate ); String result = timestampFormatDate + '.' + nanoseconds; Timestamp res = Timestamp.valueOf( timestampFormatDate + '.' + nanoseconds ); pos.setIndex( pos.getIndex() + result.length() ); return res; } SimpleTimestampFormat( String pattern );  SimpleTimestampFormat( String pattern, Locale locale );  SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); }
SimpleTimestampFormat extends SimpleDateFormat { @Override public Date parse( String text, ParsePosition pos ) { String timestampFormatDate; Date tempDate; if ( compatibleToSuperPattern ) { tempDate = super.parse( text, pos ); return new Timestamp( tempDate.getTime() ); } StringBuilder dateText = new StringBuilder( text.substring( pos.getIndex() ) ); ParsePosition positionError = new ParsePosition( 0 ); tempDate = super.parse( dateText.toString(), positionError ); if ( tempDate != null ) { pos.setErrorIndex( pos.getIndex() ); return null; } int startNanosecondsPosition = positionError.getErrorIndex(); int endNanosecondsPosition = endNanosecondPatternPosition - startNanosecondPatternPosition + 1 + startNanosecondsPosition; endNanosecondsPosition = ( endNanosecondsPosition >= dateText.length() ) ? dateText.length() : endNanosecondsPosition; String nanoseconds = String.valueOf( dateText.subSequence( startNanosecondsPosition, endNanosecondsPosition ) ); dateText.delete( startNanosecondsPosition, endNanosecondsPosition ); ParsePosition position = new ParsePosition( 0 ); dateText.append( NANOSECOND_PLACEHOLDER ); tempDate = super.parse( dateText.toString(), position ); if ( tempDate == null ) { pos.setErrorIndex( position.getErrorIndex() ); return null; } timestampFormatDate = defaultTimestampFormat.format( tempDate ); String result = timestampFormatDate + '.' + nanoseconds; Timestamp res = Timestamp.valueOf( timestampFormatDate + '.' + nanoseconds ); pos.setIndex( pos.getIndex() + result.length() ); return res; } SimpleTimestampFormat( String pattern );  SimpleTimestampFormat( String pattern, Locale locale );  SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); }
SimpleTimestampFormat extends SimpleDateFormat { @Override public Date parse( String text, ParsePosition pos ) { String timestampFormatDate; Date tempDate; if ( compatibleToSuperPattern ) { tempDate = super.parse( text, pos ); return new Timestamp( tempDate.getTime() ); } StringBuilder dateText = new StringBuilder( text.substring( pos.getIndex() ) ); ParsePosition positionError = new ParsePosition( 0 ); tempDate = super.parse( dateText.toString(), positionError ); if ( tempDate != null ) { pos.setErrorIndex( pos.getIndex() ); return null; } int startNanosecondsPosition = positionError.getErrorIndex(); int endNanosecondsPosition = endNanosecondPatternPosition - startNanosecondPatternPosition + 1 + startNanosecondsPosition; endNanosecondsPosition = ( endNanosecondsPosition >= dateText.length() ) ? dateText.length() : endNanosecondsPosition; String nanoseconds = String.valueOf( dateText.subSequence( startNanosecondsPosition, endNanosecondsPosition ) ); dateText.delete( startNanosecondsPosition, endNanosecondsPosition ); ParsePosition position = new ParsePosition( 0 ); dateText.append( NANOSECOND_PLACEHOLDER ); tempDate = super.parse( dateText.toString(), position ); if ( tempDate == null ) { pos.setErrorIndex( position.getErrorIndex() ); return null; } timestampFormatDate = defaultTimestampFormat.format( tempDate ); String result = timestampFormatDate + '.' + nanoseconds; Timestamp res = Timestamp.valueOf( timestampFormatDate + '.' + nanoseconds ); pos.setIndex( pos.getIndex() + result.length() ); return res; } SimpleTimestampFormat( String pattern );  SimpleTimestampFormat( String pattern, Locale locale );  SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }