6.7.7.3 Free-Form Dates

When reading a date form during algebraic entry, Calc falls back on the algorithm described here if the input does not exactly match the current date format. This algorithm generally “does the right thing” and you don’t have to worry about it, but it is described here in full detail for the curious.

Calc does not distinguish between upper- and lower-case letters while interpreting dates.

First, the time portion, if present, is located somewhere in the text and then removed. The remaining text is then interpreted as the date.

A time is of the form ‘hh:mm:ss’, possibly with the seconds part omitted and possibly with an AM/PM indicator added to indicate 12-hour time. If the AM/PM is present, the minutes may also be omitted. The AM/PM part may be any of the words ‘am’, ‘pm’, ‘noon’, or ‘midnight’; each of these may be abbreviated to one letter, and the alternate forms ‘a.m.’, ‘p.m.’, and ‘mid’ are also understood. Obviously ‘noon’ and ‘midnight’ are allowed only on 12:00:00. The words ‘noon’, ‘mid’, and ‘midnight’ are also recognized with no number attached. Midnight will represent the beginning of a day.

If there is no AM/PM indicator, the time is interpreted in 24-hour format.

When reading the date portion, Calc first checks to see if it is an ISO 8601 week-numbering date; if the string contains an integer representing the year, a “W” followed by two digits for the week number, and an integer from 1 to 7 representing the weekday (in that order), then all other characters are ignored and this information determines the date. Otherwise, all words and numbers are isolated from the string; other characters are ignored. All words must be either month names or day-of-week names (the latter of which are ignored). Names can be written in full or as three-letter abbreviations.

Large numbers, or numbers with ‘+’ or ‘-’ signs, are interpreted as years. If one of the other numbers is greater than 12, then that must be the day and the remaining number in the input is therefore the month. Otherwise, Calc assumes the month, day and year are in the same order that they appear in the current date format. If the year is omitted, the current year is taken from the system clock.

If there are too many or too few numbers, or any unrecognizable words, then the input is rejected.

If there are any large numbers (of five digits or more) other than the year, they are ignored on the assumption that they are something like Julian dates that were included along with the traditional date components when the date was formatted.

One of the words ‘ad’, ‘a.d.’, ‘bc’, or ‘b.c.’ may optionally be used; the latter two are equivalent to a minus sign on the year value.

If you always enter a four-digit year, and use a name instead of a number for the month, there is no danger of ambiguity.