Repository navigation
Layouts from a format string. Every input parses to what it did in 0.4.2.
Added
Layout.fromFormatString(dialect, format, opts), the inverse of
formatString: a layout from a strftime, Go or Java format string, for a
column whose format is known, so that no value is detected. The order is
the format's, so%d/%m/%Ygives a reusable layout where one detected
from13/02/2024is decided per value. Each dialect reads as its own
parser does, within what a layout holds: a one-or-two-digit field takes
either,%fone to nine digits,%zZor either offset form, and a
month or weekday name any month or weekday in English and the options'
locales.error.Unsupportedfor a field no layout reads,
error.InvalidFormatfor a string that is no date format, and
error.NoBaseTimefor one with no year and no base time. Through C as
dateparsa_layout_from_formatand through Python as
Layout.from_format. Two fuzz targets hold it: a layout's format string
read back reads the value it was spelled from to the same time, and
agrees with the layout wherever both read; and a layout from any format
string spells formats that read back to the same time. (#27)
Changed
- A reused layout whose fields all have fixed widths (ISO 8601, RFC 3339,
SQL, compact dates) reads a value in about 0.9 of the time it did: an ISO
date-time in 9.7 ns where it took 10.3, an ISO date in 6.8 where it took
7.8, on an M5 Max. The fixed-slot path is inlined intoexecuteby hand. formatStringspells from any value the layout reads, not only the one
it was detected from at the same widths: a layout from1/2/2024spells
11/12/2024as%m/%d/%Ywhere it gaveerror.NotDetectedFrom. Python's
Layout.format_stringtakes the value asvalue=.formatStringwrites text between two fields as one run, so Java quotes
it once; refuses a NUL, which no C format string holds; spells a literal
Tafter a one-or-two-digit day rather than refusing it; spells a
weekday only in English and the locales the layout reads, and only as a
whole word, as a format string reads one; and refuses any format
fromFormatStringwould not read back, such as one with more runs of
text than a layout has fields.