Class DateTimeColumn
java.lang.Object
io.github.kelsoncm.fwf.columns.AbstractColumn
io.github.kelsoncm.fwf.columns.DateTimeColumn
- Direct Known Subclasses:
DateColumn, TimeColumn
DateTime column supporting custom Python-style date-time format placeholders and zero-padding.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringThe Python-style format string (e.g.protected final DateTimeFormatterThe compiledDateTimeFormatterinstance.protected final StringThe converted JavaDateTimeFormatterpattern string.protected final intThe required number of Python format specifiers in the format string.Fields inherited from class AbstractColumn
description, name, size, start -
Constructor Summary
ConstructorsModifierConstructorDescriptionDateTimeColumn(String name) Constructs a newDateTimeColumnwith a name, defaulting to format"%d%m%Y%H%M".DateTimeColumn(String name, String format) Constructs a newDateTimeColumnwith a name and format.DateTimeColumn(String name, String format, String description) Constructs a newDateTimeColumnwith a name, format, and description.protectedDateTimeColumn(String name, String format, String description, int requiredFormatNumElements) Protected constructor allowing sub-classes to specify the required number of format specifiers. -
Method Summary
Modifier and TypeMethodDescriptionprotected static intcalculateSize(String name, String format, int requiredFormatNumElements) Calculates column size in characters based on a sample formatting execution.protected static StringConverts Python strftime format tokens to Java DateTimeFormatter pattern symbols.Gets the Python-style format string.Formats aLocalDateTimeor null into a fixed-width string of exact column size.Converts a raw fixed-width date-time string slice into aLocalDateTimevalue.Methods inherited from class AbstractColumn
getDescription, getEnd, getName, getSize, getStart, setStart, validateToStrSize
-
Field Details
-
format
The Python-style format string (e.g."%d%m%Y%H%M"). -
javaPattern
The converted JavaDateTimeFormatterpattern string. -
formatter
The compiledDateTimeFormatterinstance. -
requiredFormatNumElements
protected final int requiredFormatNumElementsThe required number of Python format specifiers in the format string.
-
-
Constructor Details
-
DateTimeColumn
-
DateTimeColumn
protected DateTimeColumn(String name, String format, String description, int requiredFormatNumElements) Protected constructor allowing sub-classes to specify the required number of format specifiers.- Parameters:
name- the column nameformat- Python-style datetime format stringdescription- human-readable descriptionrequiredFormatNumElements- number of required specifiers
-
DateTimeColumn
-
DateTimeColumn
Constructs a newDateTimeColumnwith a name, defaulting to format"%d%m%Y%H%M".- Parameters:
name- the column name
-
-
Method Details
-
calculateSize
Calculates column size in characters based on a sample formatting execution.- Parameters:
name- column nameformat- Python format stringrequiredFormatNumElements- expected count of specifiers- Returns:
- total formatted size in characters
-
convertPythonFormatToJavaPattern
-
getFormat
-
toValue
Converts a raw fixed-width date-time string slice into aLocalDateTimevalue.- Overrides:
toValuein classAbstractColumn- Parameters:
slice- raw fixed-width substring- Returns:
- parsed
LocalDateTime, or null if slice consists entirely of zeros - Throws:
IllegalArgumentException- ifsliceis null or has an invalid format
-
toStr
Formats aLocalDateTimeor null into a fixed-width string of exact column size.- Specified by:
toStrin classAbstractColumn- Parameters:
value-LocalDateTimeor null to format- Returns:
- formatted date-time string or zero-filled string of size
AbstractColumn.getSize() - Throws:
IllegalArgumentException- ifvalueis not aLocalDateTime
-