← board

sysutils: StrToDate / StrToDateTime and the TryStrTo* date variants

What is there and what is not

direction present missing
format FormatDateTime, DateToStr?, EncodeDate, EncodeTime, DecodeDate, DecodeTime
parse StrToTime StrToDate, StrToDateTime
non-raising TryStrToInt, TryStrToFloat, … TryStrToDate, TryStrToTime, TryStrToDateTime

So the surface is asymmetric: a program can format a date but not read one back.

Notes for whoever takes it

Gate

A .pas diffed against FPC 3.2.2 covering each function, valid and malformed input, ShortDateFormat/DateSeparator variations, the raising and non-raising variants, and leap-day and year-boundary dates. make lib-test green.

Resolution (2026-08-15)

StrToDate, StrToDateTime, TryStrToDate, TryStrToTime, TryStrToDateTime landed in lib/rtl/sysutils.pas, plus the two settings the parse direction needs and the RTL did not have: ShortDateFormat (default 'd/m/y', FPC's) and TwoDigitYearCenturyWindow (default 50).

Two FPC 3.2.2 probes, 53 rows total: probe 1 matches on 28 of 28, probe 2 on 24 of 25. test/lib_dateparse.pas is new (36 rows, wired into lib-test), and every row in it was read off FPC rather than reasoned about.

What was measured, and would have been got wrong

StrToTime was refactored into TryStrToTime + a two-line raising wrapper, and StrToDate/TryStrToDate share ParseDate the same way — the raising and non-raising arms cannot drift, which is the specific way this family has gone wrong before.

Known divergence, message text only

StrToDate('14 08 2026') (spaces where the separator belongs) raises "14 08 2026" is not a valid date format where FPC says Invalid date. Both raise EConvertError, both reject the input; only the class of message differs. It is left as-is because FPC's own split is not derivable from behaviour — '2026/08/14' (also a wrong separator) gives FPC the format message, so no single rule reproduces both rows, and inventing one would be a guess dressed as parity.

Not done here

ShortTimeFormat and the DateToStr/TimeToStr/DateTimeToStr renderers are still absent. They belong to the FORMAT direction, which this ticket is not, and ShortDateFormat only earned its place here because the parser reads it — a setting nothing honours would be a lie. Filed separately if a consumer wants it.

Log