summaryrefslogtreecommitdiff
path: root/times.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-07-19 21:36:34 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-07-19 21:36:34 -0400
commitd568319495a0695582797de0be4b85e1e06e73b2 (patch)
treecda7e94b2da52b32006c6a83b335d72ff2ccc165 /times.cc
parent150abce0dbd11863e4a8309fd306a4c2667501f8 (diff)
parent2aeee0bb64b56959ebcf86165c0b31630e0f92ac (diff)
downloadfork-ledger-d568319495a0695582797de0be4b85e1e06e73b2.tar.gz
fork-ledger-d568319495a0695582797de0be4b85e1e06e73b2.tar.bz2
fork-ledger-d568319495a0695582797de0be4b85e1e06e73b2.zip
Merged in bug fixes from master (done for 2.6.1b)
Diffstat (limited to 'times.cc')
-rw-r--r--times.cc51
1 files changed, 38 insertions, 13 deletions
diff --git a/times.cc b/times.cc
index b90f71aa..865631d2 100644
--- a/times.cc
+++ b/times.cc
@@ -53,10 +53,13 @@ string output_time_format = "%Y/%m/%d";
#if 0
static const char * formats[] = {
+ "%y/%m/%d",
"%Y/%m/%d",
"%m/%d",
+ "%y.%m.%d",
"%Y.%m.%d",
"%m.%d",
+ "%y-%m-%d",
"%Y-%m-%d",
"%m-%d",
"%a",
@@ -68,8 +71,26 @@ static const char * formats[] = {
};
#endif
-bool day_before_month = false;
-static bool day_before_month_initialized = false;
+bool day_before_month = false;
+static bool day_before_month_initialized = false;
+
+#if 0
+datetime_t datetime_t::now(std::time(NULL));
+
+namespace {
+ 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
+ };
+
+ bool parse_date_mask(const char * date_str, struct std::tm * result);
+ bool parse_date(const char * date_str, std::time_t * result,
+ const int year = -1);
+ bool quick_parse_date(const char * date_str, std::time_t * result);
+}
+#endif
datetime_t parse_datetime(const char * str)
{
@@ -172,17 +193,17 @@ namespace {
if (! parse_date_mask(word.c_str(), &when))
throw new datetime_error(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) {
@@ -195,18 +216,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);
}
#endif
}
@@ -370,7 +395,7 @@ namespace {
#if 0
// jww (2008-05-08):
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;
}
@@ -397,7 +422,7 @@ namespace {
when.tm_sec = 0;
if (when.tm_year == -1)
- when.tm_year = ((year == -1) ? date_t::current_year : (year - 1900));
+ when.tm_year = ((year == -1) ? date_t::current_year : year) - 1900;
if (when.tm_mon == -1)
when.tm_mon = 0;
@@ -415,7 +440,7 @@ namespace {
{
#if 0
// jww (2008-05-08):
- return parse_date(date_str, result, date_t::current_year + 1900);
+ return parse_date(date_str, result, date_t::current_year);
#else
return false;
#endif