From d7ef3fc59cda8c4cc51c06744abe2a0960f224ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 27 Aug 2003 01:12:51 +0000 Subject: [PATCH] Now ignores the ending of ordered numbers (1st, 2nd, 3rd, ...). Added the "week[s]" keyword to accept strings like "5 weeks", doesn't work right yet in the "next/last week" case - that extra case should be added to computeRelativeUnit(). Removed an unused variable. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4384 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/parsedate.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/kernel/libroot/os/parsedate.cpp b/src/kernel/libroot/os/parsedate.cpp index d1a8408fd8..4f0de71f33 100644 --- a/src/kernel/libroot/os/parsedate.cpp +++ b/src/kernel/libroot/os/parsedate.cpp @@ -184,6 +184,7 @@ static const known_identifier kIdentifiers[] = { {"years", "year", TYPE_UNIT, FLAG_RELATIVE, UNIT_YEAR, 1}, {"months", "month",TYPE_UNIT, FLAG_RELATIVE, UNIT_MONTH, 1}, + {"weeks", "week", TYPE_UNIT, FLAG_RELATIVE, UNIT_DAY, 7}, {"days", "day", TYPE_UNIT, FLAG_RELATIVE, UNIT_DAY, 1}, {"hour", NULL, TYPE_UNIT, FLAG_RELATIVE, UNIT_SECOND, 1 * 60 * 60}, {"hours", "hrs", TYPE_UNIT, FLAG_RELATIVE, UNIT_SECOND, 1 * 60 * 60}, @@ -384,6 +385,18 @@ preparseDate(const char *dateString, parsed_element *elements) // skip number while (isdigit(dateString[1])) dateString++; + + // check for "1st", "2nd, "3rd", "4th", ... + + const char *suffixes[] = {"th", "st", "nd", "rd"}; + const char *validSuffix = elements[index].value > 3 ? "th" : suffixes[elements[index].value]; + if (!strncasecmp(dateString + 1, validSuffix, 2) + && !isalpha(dateString[3])) { + // for now, just ignore the suffix - but we might be able + // to deduce some meaning out of it, since it's not really + // possible to put it in anywhere + dateString += 2; + } } else if (isalpha(c)) { // fetch whole string @@ -536,7 +549,6 @@ computeDate(const char *format, bool *optional, parsed_element *elements, time_t parsed_element *element = elements; uint32 position = 0; struct tm tm; - bool relative = false; if (now == -1) now = time(NULL);