summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-07-17 06:12:32 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-07-17 06:12:32 -0400
commitf482d120fd648bdb137a1f3f9517e30095f8c38a (patch)
treee3402dc84124fd5b927434836e9a1d590cfdcf14
parent0f83b9f0c34e72c01730bb5cf0250f02a5c30a6e (diff)
downloadfork-ledger-f482d120fd648bdb137a1f3f9517e30095f8c38a.tar.gz
fork-ledger-f482d120fd648bdb137a1f3f9517e30095f8c38a.tar.bz2
fork-ledger-f482d120fd648bdb137a1f3f9517e30095f8c38a.zip
Correct several glaring issues with interval_t and the date parser, which has
all but entirely ruined Ledger's date handling capabilities.
-rw-r--r--datetime.cc28
-rw-r--r--datetime.h12
2 files changed, 22 insertions, 18 deletions
diff --git a/datetime.cc b/datetime.cc
index 0a5f5440..434660cd 100644
--- a/datetime.cc
+++ b/datetime.cc
@@ -33,8 +33,8 @@ const char * date_t::formats[] = {
datetime_t datetime_t::now(std::time(NULL));
namespace {
- static std::time_t base = -1;
- static int base_year = -1;
+ static std::time_t base = -1;
+ static int base_year = -1;
static const int month_days[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
@@ -132,17 +132,17 @@ namespace {
if (! parse_date_mask(word.c_str(), &when))
throw new datetime_error(std::string("Could not parse date mask: ") + word);
- when.tm_hour = 0;
- when.tm_min = 0;
- when.tm_sec = 0;
- when.tm_isdst = -1;
+ when.tm_hour = 0;
+ when.tm_min = 0;
+ when.tm_sec = 0;
+ when.tm_isdst = -1;
bool saw_year = true;
bool saw_mon = true;
bool saw_day = true;
if (when.tm_year == -1) {
- when.tm_year = date_t::current_year;
+ when.tm_year = date_t::current_year - 1900;
saw_year = false;
}
if (when.tm_mon == -1) {
@@ -155,18 +155,22 @@ namespace {
when.tm_mday = 1;
saw_day = false;
} else {
- saw_mon = false; // don't increment by month if day used
+ saw_mon = false; // don't increment by month if day used
saw_year = false; // don't increment by year if day used
}
if (begin) {
*begin = std::mktime(&when);
- if (end)
- *end = interval_t(saw_day ? 86400 : 0, saw_mon ? 1 : 0,
+ assert(int(*begin) != -1);
+ if (end) {
+ *end = interval_t(saw_day ? 1 : 0, saw_mon ? 1 : 0,
saw_year ? 1 : 0).increment(*begin);
+ assert(int(*end) != -1);
+ }
}
else if (end) {
*end = std::mktime(&when);
+ assert(int(*end) != -1);
}
}
@@ -321,12 +325,12 @@ namespace {
bool parse_date_mask(const char * date_str, struct std::tm * result)
{
if (! date_t::input_format.empty()) {
- std::memset(result, INT_MAX, sizeof(struct std::tm));
+ std::memset(result, -1, sizeof(struct std::tm));
if (strptime(date_str, date_t::input_format.c_str(), result))
return true;
}
for (const char ** f = date_t::formats; *f; f++) {
- std::memset(result, INT_MAX, sizeof(struct std::tm));
+ std::memset(result, -1, sizeof(struct std::tm));
if (strptime(date_str, *f, result))
return true;
}
diff --git a/datetime.h b/datetime.h
index 9f85d3f2..b5dffba0 100644
--- a/datetime.h
+++ b/datetime.h
@@ -256,12 +256,12 @@ inline std::ostream& operator<<(std::ostream& out,
struct interval_t
{
- unsigned short years;
- unsigned short months;
- unsigned short days;
- unsigned short hours;
- unsigned short minutes;
- unsigned short seconds;
+ int years;
+ int months;
+ int days;
+ int hours;
+ int minutes;
+ int seconds;
datetime_t begin;
datetime_t end;