summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/textual.cc18
-rw-r--r--src/times.cc10
-rw-r--r--test/unit/t_times.cc196
3 files changed, 115 insertions, 109 deletions
diff --git a/src/textual.cc b/src/textual.cc
index f59496ba..ce945fdf 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -32,6 +32,7 @@
#include "journal.h"
#include "account.h"
#include "option.h"
+#define TIMELOG_SUPPORT 1
#if defined(TIMELOG_SUPPORT)
#include "timelog.h"
#endif
@@ -299,9 +300,11 @@ void instance_t::read_next_directive()
case ' ':
case '\t': {
+#if 0
char * p = skip_ws(line);
if (*p)
throw parse_error("Line begins with whitespace");
+#endif
break;
}
@@ -384,29 +387,30 @@ void instance_t::read_next_directive()
#if defined(TIMELOG_SUPPORT)
void instance_t::clock_in_directive(char * line,
- bool capitalized)
+ bool /*capitalized*/)
{
- string date(line, 2, 19);
+ string datetime(line, 2, 19);
char * p = skip_ws(line + 22);
char * n = next_element(p, true);
- timelog.clock_in(parse_datetime(date, current_year),
+ timelog.clock_in(parse_datetime(datetime, current_year),
account_stack.front()->find_account(p), n ? n : "");
}
void instance_t::clock_out_directive(char * line,
- bool capitalized)
+ bool /*capitalized*/)
{
- string date(line, 2, 19);
+ string datetime(line, 2, 19);
char * p = skip_ws(line + 22);
char * n = next_element(p, true);
- timelog.clock_out(parse_datetime(date, current_year),
- p ? account_stack.front()->find_account(p) : NULL, n);
+ timelog.clock_out(parse_datetime(datetime, current_year),
+ p ? account_stack.front()->find_account(p) : NULL, n ? n : "");
count++;
}
+
#endif // TIMELOG_SUPPORT
void instance_t::default_commodity_directive(char * line)
diff --git a/src/times.cc b/src/times.cc
index 7101d3c6..df760d10 100644
--- a/src/times.cc
+++ b/src/times.cc
@@ -106,12 +106,14 @@ namespace {
}
}
-datetime_t parse_datetime(const char * str, int current_year)
+datetime_t parse_datetime(const char * str, int)
{
std::tm when;
- // jww (2008-08-01): Needs to look for HH:MM:SS as well.
- quick_parse_date(str, when, current_year);
- return posix_time::ptime_from_tm(when);
+ std::memset(&when, -1, sizeof(std::tm));
+ if (strptime(str, "%Y/%m/%d %H:%M:%S", &when))
+ return posix_time::ptime_from_tm(when);
+ else
+ return datetime_t();
}
date_t parse_date(const char * str, int current_year)
diff --git a/test/unit/t_times.cc b/test/unit/t_times.cc
index af0f1414..59acd98e 100644
--- a/test/unit/t_times.cc
+++ b/test/unit/t_times.cc
@@ -20,52 +20,52 @@ void DateTimeTestCase::testConstructors()
#endif // NOT_FOR_PYTHON
#ifndef NOT_FOR_PYTHON
- datetime_t d0;
- datetime_t d1;
+ date_t d0;
+ date_t d1;
datetime_t d3;
- datetime_t d4;
- datetime_t d5;
- datetime_t d6;
- datetime_t d7;
- datetime_t d8;
- datetime_t d9;
-
- datetime_t d10;
- datetime_t d11;
- datetime_t d12;
- datetime_t d13;
- datetime_t d14;
+ date_t d4;
+ date_t d5;
+ date_t d6;
+ date_t d7;
+ date_t d8;
+ date_t d9;
+
+ date_t d10;
+ date_t d11;
+ date_t d12;
+ date_t d13;
+ date_t d14;
datetime_t d15;
#endif // NOT_FOR_PYTHON
- d1 = parse_datetime("1990/01/01");
+ d1 = parse_date("1990/01/01");
#ifndef NOT_FOR_PYTHON
d3 = boost::posix_time::from_time_t(localMoment);
#endif // NOT_FOR_PYTHON
- d4 = parse_datetime("2006/12/25");
- d5 = parse_datetime("12/25");
- d6 = parse_datetime("2006.12.25");
- d7 = parse_datetime("12.25");
- d8 = parse_datetime("2006-12-25");
- d9 = parse_datetime("12-25");
-
- d10 = parse_datetime("tue");
- d11 = parse_datetime("tuesday");
- d12 = parse_datetime("feb");
- d13 = parse_datetime("february");
- d14 = parse_datetime("2006");
+ d4 = parse_date("2006/12/25");
+ d5 = parse_date("12/25");
+ d6 = parse_date("2006.12.25");
+ d7 = parse_date("12.25");
+ d8 = parse_date("2006-12-25");
+ d9 = parse_date("12-25");
+
+ d10 = parse_date("tue");
+ d11 = parse_date("tuesday");
+ d12 = parse_date("feb");
+ d13 = parse_date("february");
+ d14 = parse_date("2006");
#ifndef NOT_FOR_PYTHON
d15 = d3;
#endif // NOT_FOR_PYTHON
#ifndef NOT_FOR_PYTHON
- assertTrue(d0.is_not_a_date_time());
- assertFalse(d1.is_not_a_date_time());
- assertFalse(d4.is_not_a_date_time());
+ assertTrue(d0.is_not_a_date());
+ assertFalse(d1.is_not_a_date());
+ assertFalse(d4.is_not_a_date());
#endif // NOT_FOR_PYTHON
- assertTrue(CURRENT_TIME() > d1);
- assertTrue(CURRENT_TIME() > d4);
+ assertTrue(CURRENT_DATE() > d1);
+ assertTrue(CURRENT_DATE() > d4);
#ifndef NOT_FOR_PYTHON
assertEqual(d3, d15);
@@ -79,72 +79,72 @@ void DateTimeTestCase::testConstructors()
#if 0
#ifndef NOT_FOR_PYTHON
- assertThrow(parse_datetime("2007/02/29"), boost::gregorian::bad_day_of_month);
- //assertThrow(parse_datetime("2007/13/01"), datetime_error);
- //assertThrow(parse_datetime("2007/00/01"), datetime_error);
- assertThrow(parse_datetime("2007/01/00"), boost::gregorian::bad_day_of_month);
- //assertThrow(parse_datetime("2007/00/00"), boost::gregorian::bad_day_of_month);
- //assertThrow(parse_datetime("2007/05/32"), boost::gregorian::bad_day_of_month);
-
- assertThrow(parse_datetime("2006x/12/25"), datetime_error);
- assertThrow(parse_datetime("2006/12x/25"), datetime_error);
- assertThrow(parse_datetime("2006/12/25x"), datetime_error);
-
- assertThrow(parse_datetime("feb/12/25"), datetime_error);
- assertThrow(parse_datetime("2006/mon/25"), datetime_error);
- assertThrow(parse_datetime("2006/12/web"), datetime_error);
-
- assertThrow(parse_datetime("12*25"), datetime_error);
-
- assertThrow(parse_datetime("tuf"), datetime_error);
- assertThrow(parse_datetime("tufsday"), datetime_error);
- assertThrow(parse_datetime("fec"), datetime_error);
- assertThrow(parse_datetime("fecruary"), datetime_error);
- assertThrow(parse_datetime("207x"), datetime_error);
- assertThrow(parse_datetime("hello"), datetime_error);
-
- d1 = parse_datetime("2002-02-02");
- d1 = parse_datetime("2002/02/02");
- d1 = parse_datetime("2002.02.02");
- d1 = parse_datetime("02-02-2002");
- d1 = parse_datetime("02/02/2002");
- d1 = parse_datetime("02.02.2002");
- d1 = parse_datetime("02-02-02");
- d1 = parse_datetime("02/02/02");
- d1 = parse_datetime("02.02.02");
- d1 = parse_datetime("02-02");
- d1 = parse_datetime("02/02");
- d1 = parse_datetime("02.02");
- d1 = parse_datetime("20020202");
- d1 = parse_datetime("20020202T023318");
- d1 = parse_datetime("20020202T023318-0700");
- d1 = parse_datetime("20020202T023318-0100");
- d1 = parse_datetime("02-Feb-2002");
- d1 = parse_datetime("2002-Feb-02");
- d1 = parse_datetime("02 Feb 2002");
- d1 = parse_datetime("02-Feb-2002");
- d1 = parse_datetime("02 February 2002");
- d1 = parse_datetime("02-February-2002");
- d1 = parse_datetime("2002 Feb 02");
- d1 = parse_datetime("2002-Feb-02");
- d1 = parse_datetime("2002 February 02");
- d1 = parse_datetime("2002-February-02");
- d1 = parse_datetime("02 Feb");
- d1 = parse_datetime("02-Feb");
- d1 = parse_datetime("02 February");
- d1 = parse_datetime("02-February");
- d1 = parse_datetime("Feb 02");
- d1 = parse_datetime("Feb-02");
- d1 = parse_datetime("February 02");
- d1 = parse_datetime("February-02");
- d1 = parse_datetime("Feb 02, 2002");
- d1 = parse_datetime("February 02, 2002");
- d1 = parse_datetime("2002-02-02 12:00:00");
- d1 = parse_datetime("2002-02-02 12:00:00 AM");
- d1 = parse_datetime("2002-02-02 12:00 AM");
- d1 = parse_datetime("2002-02-02 12:00AM");
- d1 = parse_datetime("2002-02-02 12p");
- d1 = parse_datetime("2002-02-02 12a");
+ assertThrow(parse_date("2007/02/29"), boost::gregorian::bad_day_of_month);
+ //assertThrow(parse_date("2007/13/01"), datetime_error);
+ //assertThrow(parse_date("2007/00/01"), datetime_error);
+ assertThrow(parse_date("2007/01/00"), boost::gregorian::bad_day_of_month);
+ //assertThrow(parse_date("2007/00/00"), boost::gregorian::bad_day_of_month);
+ //assertThrow(parse_date("2007/05/32"), boost::gregorian::bad_day_of_month);
+
+ assertThrow(parse_date("2006x/12/25"), datetime_error);
+ assertThrow(parse_date("2006/12x/25"), datetime_error);
+ assertThrow(parse_date("2006/12/25x"), datetime_error);
+
+ assertThrow(parse_date("feb/12/25"), datetime_error);
+ assertThrow(parse_date("2006/mon/25"), datetime_error);
+ assertThrow(parse_date("2006/12/web"), datetime_error);
+
+ assertThrow(parse_date("12*25"), datetime_error);
+
+ assertThrow(parse_date("tuf"), datetime_error);
+ assertThrow(parse_date("tufsday"), datetime_error);
+ assertThrow(parse_date("fec"), datetime_error);
+ assertThrow(parse_date("fecruary"), datetime_error);
+ assertThrow(parse_date("207x"), datetime_error);
+ assertThrow(parse_date("hello"), datetime_error);
+
+ d1 = parse_date("2002-02-02");
+ d1 = parse_date("2002/02/02");
+ d1 = parse_date("2002.02.02");
+ d1 = parse_date("02-02-2002");
+ d1 = parse_date("02/02/2002");
+ d1 = parse_date("02.02.2002");
+ d1 = parse_date("02-02-02");
+ d1 = parse_date("02/02/02");
+ d1 = parse_date("02.02.02");
+ d1 = parse_date("02-02");
+ d1 = parse_date("02/02");
+ d1 = parse_date("02.02");
+ d1 = parse_date("20020202");
+ d1 = parse_date("20020202T023318");
+ d1 = parse_date("20020202T023318-0700");
+ d1 = parse_date("20020202T023318-0100");
+ d1 = parse_date("02-Feb-2002");
+ d1 = parse_date("2002-Feb-02");
+ d1 = parse_date("02 Feb 2002");
+ d1 = parse_date("02-Feb-2002");
+ d1 = parse_date("02 February 2002");
+ d1 = parse_date("02-February-2002");
+ d1 = parse_date("2002 Feb 02");
+ d1 = parse_date("2002-Feb-02");
+ d1 = parse_date("2002 February 02");
+ d1 = parse_date("2002-February-02");
+ d1 = parse_date("02 Feb");
+ d1 = parse_date("02-Feb");
+ d1 = parse_date("02 February");
+ d1 = parse_date("02-February");
+ d1 = parse_date("Feb 02");
+ d1 = parse_date("Feb-02");
+ d1 = parse_date("February 02");
+ d1 = parse_date("February-02");
+ d1 = parse_date("Feb 02, 2002");
+ d1 = parse_date("February 02, 2002");
+ d1 = parse_date("2002-02-02 12:00:00");
+ d1 = parse_date("2002-02-02 12:00:00 AM");
+ d1 = parse_date("2002-02-02 12:00 AM");
+ d1 = parse_date("2002-02-02 12:00AM");
+ d1 = parse_date("2002-02-02 12p");
+ d1 = parse_date("2002-02-02 12a");
assertValid(d1);
#endif // NOT_FOR_PYTHON