java.lang.Object
io.github.connellite.util.internal.strftime.Strftime

public final class Strftime extends Object
A port of the POSIX strftime engine from glibc, writing straight into a StringBuilder.

The structure follows __strftime_internal closely enough to be read side by side with it: one pass over the pattern, per-specifier state for the flags, field width and E/O modifier, and two shared number emitters that the numeric conversions jump to the way the C code jumps to do_number and do_number_spacepad. Unknown conversions are echoed back literally, as glibc's bad_format does, rather than reported as errors.

Besides the conversions POSIX requires, the GNU flags - _ 0 ^ #, the field width, and the extensions %P %k %l %s are supported. The POSIX + flag is supported as well, which glibc itself does not parse.

Three places adapt glibc's locale database to what the JDK exposes, and so are ports in spirit rather than in letter:

  • glibc's nl_get_alt_digit returns a whole alternative numeral per value; the JDK only offers a zero digit through DecimalStyle, so O shifts each rendered digit instead, and keeps the padding glibc's alternative path skips.
  • glibc's era_format is a locale-supplied sub-pattern; the JDK has no equivalent field, so %EY formats through a CLDR era-and-year pattern.
  • %c uses glibc's C-locale fallback "%a %b %e %H:%M:%S %Y" rather than a localized date-time pattern, which is the layout this library has always produced, while %x and %X are localized.