Created
August 23, 2021 14:49
-
-
Save hugithordarson/87a888c7e7a05b3e4e7191c45c191260 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package is.rebbi.core.formatters; | |
import java.text.FieldPosition; | |
import java.text.Format; | |
import java.text.ParsePosition; | |
import java.time.format.DateTimeFormatter; | |
import java.time.temporal.TemporalAccessor; | |
import java.util.Objects; | |
public class DateTimeFormatterWrapper extends Format { | |
private DateTimeFormatter _formatter; | |
public DateTimeFormatterWrapper( DateTimeFormatter formatter ) { | |
Objects.requireNonNull( formatter ); | |
_formatter = formatter; | |
} | |
@Override | |
public StringBuffer format( Object object, StringBuffer toAppendTo, FieldPosition pos ) { | |
if( object == null ) { | |
return toAppendTo; | |
} | |
return toAppendTo.append( _formatter.format( (TemporalAccessor)object ) ); | |
} | |
@Override | |
public Object parseObject( String source, ParsePosition pos ) { | |
return _formatter.parse( source, pos ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment