summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-19 16:10:43 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:28 -0400
commit12f9ddbb95ac9457f6ef504183db62c716ab9e35 (patch)
treec819e494c7c21e4a121441982496e3eb6f472470
parent654c1c0b943313b060f239315b64c84357909f9f (diff)
downloadfork-ledger-12f9ddbb95ac9457f6ef504183db62c716ab9e35.tar.gz
fork-ledger-12f9ddbb95ac9457f6ef504183db62c716ab9e35.tar.bz2
fork-ledger-12f9ddbb95ac9457f6ef504183db62c716ab9e35.zip
Added time parsing
-rw-r--r--parsetime.yy20
-rw-r--r--tests/corelib/numerics/Commodity.cc27
-rw-r--r--tests/corelib/numerics/Commodity.h2
3 files changed, 29 insertions, 20 deletions
diff --git a/parsetime.yy b/parsetime.yy
index ae7ca125..f34730c4 100644
--- a/parsetime.yy
+++ b/parsetime.yy
@@ -95,7 +95,9 @@ input: date optspace ;
optspace: /* epsilon */ | TOK_SPACE ;
-date: absdate {
+date:
+ absdate opttime
+{
if (timeval->tm_gmtoff != -1) {
boost::posix_time::ptime::time_duration_type offset;
offset = boost::posix_time::seconds(timeval->tm_gmtoff);
@@ -193,23 +195,31 @@ absdate:
}
;
+opttime: /* epsilon */ |
+ TOK_SPACE TOK_TWONUM ':' TOK_TWONUM ':' TOK_TWONUM
+{
+ timeval->tm_hour = $2.ival;
+ timeval->tm_min = $4.ival;
+ timeval->tm_sec = $6.ival;
+};
+
isodate:
- year TOK_FOURNUM opttime
+ year TOK_FOURNUM optisotime
{
timeval->tm_year = $1.ival - 1900;
timeval->tm_mon = $2.ival / 100 - 1;
timeval->tm_mday = $3.ival % 100;
};
-opttime: /* epsilon */ |
- 'T' TOK_FOURNUM TOK_TWONUM optzone
+optisotime: /* epsilon */ |
+ 'T' TOK_FOURNUM TOK_TWONUM optisozone
{
timeval->tm_hour = $2.ival / 100;
timeval->tm_min = $2.ival % 100;
timeval->tm_sec = $3.ival;
};
-optzone: /* epsilon */ |
+optisozone: /* epsilon */ |
'-' TOK_FOURNUM {
timeval->tm_gmtoff = - (($2.ival / 100) * 3600 + ($2.ival % 100) * 60);
}
diff --git a/tests/corelib/numerics/Commodity.cc b/tests/corelib/numerics/Commodity.cc
index 9a3ec4c1..a2dbb58d 100644
--- a/tests/corelib/numerics/Commodity.cc
+++ b/tests/corelib/numerics/Commodity.cc
@@ -8,19 +8,14 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CommodityTestCase, "numerics");
void CommodityTestCase::setUp() {}
void CommodityTestCase::tearDown() {}
-void CommodityTestCase::testConstructors()
-{
-
-}
-
void CommodityTestCase::testPriceHistory()
{
- ptime jan17_07 = boost::posix_time::time_from_string("2007/01/17 00:00:00");
- ptime feb27_07 = boost::posix_time::time_from_string("2007/02/27 18:00:00");
- ptime feb28_07 = boost::posix_time::time_from_string("2007/02/28 06:00:00");
- ptime feb28_07sbm = boost::posix_time::time_from_string("2007/02/28 11:59:59");
- ptime mar01_07 = boost::posix_time::time_from_string("2007/03/01 00:00:00");
- ptime apr15_07 = boost::posix_time::time_from_string("2007/04/15 13:00:00");
+ ptime jan17_07 = parse_datetime("2007/01/17 00:00:00");
+ ptime feb27_07 = parse_datetime("2007/02/27 18:00:00");
+ ptime feb28_07 = parse_datetime("2007/02/28 06:00:00");
+ ptime feb28_07sbm = parse_datetime("2007/02/28 11:59:59");
+ ptime mar01_07 = parse_datetime("2007/03/01 00:00:00");
+ ptime apr15_07 = parse_datetime("2007/04/15 13:00:00");
// jww (2007-04-17): tbd
amount_t x1("100.10 AAPL");
@@ -29,9 +24,15 @@ void CommodityTestCase::testPriceHistory()
// deal of their state depends on how they were seen to be used.
commodity_t& aapl(x1.commodity());
- aapl.add_price(now, amount_t("$10.20"));
+ aapl.add_price(jan17_07, amount_t("$10.20"));
+ aapl.add_price(feb27_07, amount_t("$13.40"));
+ aapl.add_price(feb28_07, amount_t("$18.33"));
+ aapl.add_price(feb28_07sbm, amount_t("$18.30"));
+ aapl.add_price(mar01_07, amount_t("$19.50"));
+ aapl.add_price(apr15_07, amount_t("$21.22"));
- assertEqual(amount_t("$1021.02"), x1.value(now));
+ assertEqual(amount_t("$1831.83"), x1.value(feb28_07sbm));
+ assertEqual(amount_t("$2124.12"), x1.value(now));
assertValid(x1);
}
diff --git a/tests/corelib/numerics/Commodity.h b/tests/corelib/numerics/Commodity.h
index 46af6ecf..dafa03e9 100644
--- a/tests/corelib/numerics/Commodity.h
+++ b/tests/corelib/numerics/Commodity.h
@@ -7,7 +7,6 @@ class CommodityTestCase : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(CommodityTestCase);
- CPPUNIT_TEST(testConstructors);
CPPUNIT_TEST(testPriceHistory);
CPPUNIT_TEST(testLots);
CPPUNIT_TEST(testScalingBase);
@@ -22,7 +21,6 @@ public:
virtual void setUp();
virtual void tearDown();
- void testConstructors();
void testPriceHistory();
void testLots();
void testScalingBase();