summaryrefslogtreecommitdiff
path: root/tests/corelib
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-19 14:47:33 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:27 -0400
commitc5214c87594e0de68111a9160dba5dc1aceb9a43 (patch)
tree41419220704bb48e79d506cee4d12cb3e35fdc69 /tests/corelib
parent53c132ad98caf765eaba51fe4c5a85e4a69ddf06 (diff)
downloadfork-ledger-c5214c87594e0de68111a9160dba5dc1aceb9a43.tar.gz
fork-ledger-c5214c87594e0de68111a9160dba5dc1aceb9a43.tar.bz2
fork-ledger-c5214c87594e0de68111a9160dba5dc1aceb9a43.zip
Changed date parser to use lex/yacc.
Diffstat (limited to 'tests/corelib')
-rw-r--r--tests/corelib/numerics/DateTime.cc122
1 files changed, 52 insertions, 70 deletions
diff --git a/tests/corelib/numerics/DateTime.cc b/tests/corelib/numerics/DateTime.cc
index fe5ac68b..02dd7a0d 100644
--- a/tests/corelib/numerics/DateTime.cc
+++ b/tests/corelib/numerics/DateTime.cc
@@ -13,89 +13,71 @@ void DateTimeTestCase::tearDown() {}
void DateTimeTestCase::testConstructors()
{
- struct tm moment;
- std::memset(&moment, INT_MAX, sizeof(struct tm));
-
-#ifdef HAVE_STRPTIME
- strptime("2006/12/25 00:00:00", "%Y/%m/%d %H:%M:%S", &moment);
-#endif
-
-#ifdef HAVE_TIMEGM
- std::time_t gmtMoment = timegm(&moment);
-#endif
- std::time_t localMoment = std::mktime(&moment);
-
- date_t d1;
-#ifdef HAVE_TIMEGM
- date_t d2(gmtMoment);
-#endif
- date_t d3(localMoment);
- date_t d4("2006/12/25");
- date_t d5("12/25");
- date_t d6("2006.12.25");
- date_t d7("12.25");
- date_t d8("2006-12-25");
- date_t d9("12-25");
- date_t d10("tue");
- date_t d11("tuesday");
- date_t d12("feb");
- date_t d13("february");
- date_t d14("2006");
- date_t d15(d3);
-
-#ifdef HAVE_TIMEGM
- if (std::memcmp(&gmtMoment, &localMoment, sizeof(std::time_t)) == 0)
- assertEqual(d2, d3);
- else
- assertNotEqual(d2, d3);
+ std::time_t time_t_now = std::time(NULL);
+ struct tm * moment = std::localtime(&time_t_now);
+
+ std::time_t localMoment = std::mktime(moment);
+
+ ptime d0;
+ ptime d1(parse_datetime("1990/01/01"));
+ ptime d3(boost::posix_time::from_time_t(localMoment));
+ ptime d4(parse_datetime("2006/12/25"));
+ ptime d5(parse_datetime("12/25"));
+ ptime d6(parse_datetime("2006.12.25"));
+ ptime d7(parse_datetime("12.25"));
+ ptime d8(parse_datetime("2006-12-25"));
+ ptime d9(parse_datetime("12-25"));
+#if 0
+ ptime d10(parse_datetime("tue"));
+ ptime d11(parse_datetime("tuesday"));
+ ptime d12(parse_datetime("feb"));
+ ptime d13(parse_datetime("february"));
+ ptime d14(parse_datetime("2006"));
#endif
+ ptime d15(d3);
- assertFalse(d1);
- assertTrue(d4);
+ assertTrue(d0.is_not_a_date_time());
+ assertFalse(d1.is_not_a_date_time());
+ assertFalse(d4.is_not_a_date_time());
- assertTrue(date_t::now > d1);
- assertTrue(date_t::now > d3);
- assertTrue(date_t::now > d4);
+ assertTrue(now > d1);
+ assertTrue(now <= d3);
+ assertTrue(now > d4);
- assertEqual(d3, d4);
assertEqual(d3, d15);
assertEqual(d4, d6);
assertEqual(d4, d8);
assertEqual(d5, d7);
assertEqual(d5, d9);
+#if 0
assertEqual(d10, d11);
assertEqual(d12, d13);
+#endif
- assertThrow(date_t("2007/02/29"), date_error *);
- assertThrow(date_t("2007/13/01"), date_error *);
- assertThrow(date_t("2007/00/01"), date_error *);
- assertThrow(date_t("2007/01/00"), date_error *);
- assertThrow(date_t("2007/00/00"), date_error *);
- assertThrow(date_t("2007/05/32"), date_error *);
-
- assertThrow(date_t("2006x/12/25"), date_error *);
- assertThrow(date_t("2006/12x/25"), date_error *);
- assertThrow(date_t("2006/12/25x"), date_error *);
-
- assertThrow(date_t("feb/12/25"), date_error *);
- assertThrow(date_t("2006/mon/25"), date_error *);
- assertThrow(date_t("2006/12/web"), date_error *);
+ assertThrow(parse_datetime("2007/02/29"), datetime_error *);
+ assertThrow(parse_datetime("2007/13/01"), datetime_error *);
+ assertThrow(parse_datetime("2007/00/01"), datetime_error *);
+ assertThrow(parse_datetime("2007/01/00"), datetime_error *);
+ assertThrow(parse_datetime("2007/00/00"), datetime_error *);
+ assertThrow(parse_datetime("2007/05/32"), datetime_error *);
+
+ 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 *);
- assertThrow(date_t("12*25"), date_error *);
-
- assertThrow(date_t("tuf"), date_error *);
- assertThrow(date_t("tufsday"), date_error *);
- assertThrow(date_t("fec"), date_error *);
- assertThrow(date_t("fecruary"), date_error *);
- assertThrow(date_t("207x"), date_error *);
- assertThrow(date_t("hello"), date_error *);
-
- datetime_t dt1;
- datetime_t dt2;
- datetime_t dt3;
- datetime_t dt4;
- datetime_t dt5;
-
interval_t i1;
interval_t i2;
}