Class DateTimeColumn

java.lang.Object
io.github.kelsoncm.fwf.columns.AbstractColumn
io.github.kelsoncm.fwf.columns.DateTimeColumn
Direct Known Subclasses:
DateColumn, TimeColumn

public class DateTimeColumn extends AbstractColumn
DateTime column supporting custom Python-style date-time format placeholders and zero-padding.
  • Field Details

    • format

      protected final String format
      The Python-style format string (e.g. "%d%m%Y%H%M").
    • javaPattern

      protected final String javaPattern
      The converted Java DateTimeFormatter pattern string.
    • formatter

      protected final DateTimeFormatter formatter
      The compiled DateTimeFormatter instance.
    • requiredFormatNumElements

      protected final int requiredFormatNumElements
      The required number of Python format specifiers in the format string.
  • Constructor Details

    • DateTimeColumn

      public DateTimeColumn(String name, String format, String description)
      Constructs a new DateTimeColumn with a name, format, and description.
      Parameters:
      name - the column name
      format - Python-style datetime format string
      description - human-readable description
    • 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 name
      format - Python-style datetime format string
      description - human-readable description
      requiredFormatNumElements - number of required specifiers
    • DateTimeColumn

      public DateTimeColumn(String name, String format)
      Constructs a new DateTimeColumn with a name and format.
      Parameters:
      name - the column name
      format - Python-style datetime format string
    • DateTimeColumn

      public DateTimeColumn(String name)
      Constructs a new DateTimeColumn with a name, defaulting to format "%d%m%Y%H%M".
      Parameters:
      name - the column name
  • Method Details

    • calculateSize

      protected static int calculateSize(String name, String format, int requiredFormatNumElements)
      Calculates column size in characters based on a sample formatting execution.
      Parameters:
      name - column name
      format - Python format string
      requiredFormatNumElements - expected count of specifiers
      Returns:
      total formatted size in characters
    • convertPythonFormatToJavaPattern

      protected static String convertPythonFormatToJavaPattern(String format)
      Converts Python strftime format tokens to Java DateTimeFormatter pattern symbols.
      Parameters:
      format - Python strftime format string
      Returns:
      Java DateTimeFormatter pattern
    • getFormat

      public String getFormat()
      Gets the Python-style format string.
      Returns:
      Python format string
    • toValue

      public Object toValue(String slice)
      Converts a raw fixed-width date-time string slice into a LocalDateTime value.
      Overrides:
      toValue in class AbstractColumn
      Parameters:
      slice - raw fixed-width substring
      Returns:
      parsed LocalDateTime, or null if slice consists entirely of zeros
      Throws:
      IllegalArgumentException - if slice is null or has an invalid format
    • toStr

      public String toStr(Object value)
      Formats a LocalDateTime or null into a fixed-width string of exact column size.
      Specified by:
      toStr in class AbstractColumn
      Parameters:
      value - LocalDateTime or null to format
      Returns:
      formatted date-time string or zero-filled string of size AbstractColumn.getSize()
      Throws:
      IllegalArgumentException - if value is not a LocalDateTime