- Supports '21st' as a date.  Theoretically.
This commit is contained in:
Paul Beckingham 2014-05-19 22:02:08 -04:00
parent 05fbdd594e
commit 23f6840b95

View file

@ -24,8 +24,10 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <iostream> #include <iostream>
#include <time.h> #include <time.h>
#include <text.h>
#include <Dates.h> #include <Dates.h>
static const char* days[] = static const char* days[] =
@ -375,24 +377,26 @@ bool namedDates (const std::string& name, Variant& value)
*/ */
} }
// Support "21st" to indicate the next date that is the 21st day.
// 1st // 1st
// 2nd // 2nd
// 3rd // 3rd
else if (name == "????") else if (name.length () >= 3 &&
name.length () <= 4 &&
isdigit (name[0]))
{ {
/*
int number; int number;
std::string ordinal; std::string ordinal;
if (isdigit (in[1])) if (isdigit (name[1]))
{ {
number = atoi (in.substr (0, 2).c_str ()); number = atoi (name.substr (0, 2).c_str ());
ordinal = lowerCase (in.substr (2)); ordinal = lowerCase (name.substr (2));
} }
else else
{ {
number = atoi (in.substr (0, 2).c_str ()); number = atoi (name.substr (0, 2).c_str ());
ordinal = lowerCase (in.substr (1)); ordinal = lowerCase (name.substr (1));
} }
// Sanity check. // Sanity check.
@ -403,16 +407,20 @@ bool namedDates (const std::string& name, Variant& value)
ordinal == "rd" || ordinal == "rd" ||
ordinal == "th") ordinal == "th")
{ {
int m = today.month (); struct tm* t = localtime (&now);
int d = today.day (); int y = t->tm_year + 1900;
int y = today.year (); int m = t->tm_mon + 1;
int d = t->tm_mday;
// If it is this month. // If it is this month.
if (d < number && if (d < number &&
number <= Date::daysInMonth (m, y)) number <= daysInMonth (m, y))
{ {
Date then (m, number, y); t->tm_hour = t->tm_min = t->tm_sec = 0;
_t = then._t; t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
value = Variant (mktime (t), Variant::type_date);
return true; return true;
} }
@ -426,14 +434,16 @@ bool namedDates (const std::string& name, Variant& value)
y++; y++;
} }
} }
while (number > Date::daysInMonth (m, y)); while (number > daysInMonth (m, y));
Date then (m, number, y); t->tm_hour = t->tm_min = t->tm_sec = 0;
_t = then._t; t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
value = Variant (mktime (t), Variant::type_date);
return true; return true;
} }
} }
*/
} }
else else