lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Down a calendric rabbit hole


From: Greg Chicares
Subject: [lmi] Down a calendric rabbit hole
Date: Thu, 1 Jun 2017 20:18:13 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Just disregard this whole message. I thought I would need to determine
the next billing date for a group contract, given its inception date
and its billing frequency (1, 2, 4, or 12 times a year), and that turns
out to be quite tricky, as is often true of calendar-date calculations.
But now it seems that this will be unnecessary after all. Of course, if
I just throw away the code I had attempted to write, events will conspire
to make it necessary again, so I'm posting it here just to force Murphy's
Law to work in my favor and guarantee that this will remain unnecessary.

diff --git a/calendar_date_test.cpp b/calendar_date_test.cpp
index 02d5dd6..5ec81a1 100644
--- a/calendar_date_test.cpp
+++ b/calendar_date_test.cpp
@@ -40,6 +40,7 @@ struct CalendarDateTest
     static void Test()
         {
         TestFundamentals();
+return;
         TestAlgorithm199Bounds();
         TestYMDBounds();
         TestYmdToJdnAndJdnToYmd();
@@ -77,8 +78,86 @@ int test_main(int, char*[])
     return 0;
 }
 
+#include "mc_enum_type_enums.hpp"
+
+// (1) next billing date
+//   b = years_and_months_since(LastCoiReentryDate, today());
+//   y = b.first;
+//   m = b.second;
+//   // mode is {1,2,4,12}
+//   m += m % 12/mode;
+//   b = add_years_and_months(LastCoiReentryDate, y, m, true)
+
+calendar_date next_bill_date
+    (calendar_date const& inception
+    ,calendar_date const& run_date
+    ,mcenum_mode          mode
+    )
+{
+    auto const b = years_and_months_since(inception, run_date);
+    int  const y = b.first;
+    int m = b.second;
+    // mode is {1,2,4,12}
+    int n = m + 0 + (12 - m) % 12 / mode;
+    calendar_date z = add_years_and_months(inception, y, n, true);
+    if(z < run_date)
+        {
+        ++m;
+//      n = m + 1 + (11 - m) % 12 / mode;
+        n = m + 0 + (12 - m) % 12 / mode;
+        z = add_years_and_months(inception, y, n, true);
+std::cout << "increased" << std::endl;
+        }
+std::cout << y << " " << m << " " << n << std::endl;
+    return z;
+}
+
 void CalendarDateTest::TestFundamentals()
 {
+    calendar_date const inception(2000, 1, 1);
+    calendar_date run_date;
+    calendar_date bill_date;
+
+    run_date  = calendar_date(2000,  1,  1);
+    bill_date = next_bill_date(inception, run_date, mce_semiannual);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  1,  1));
+std::cout << bill_date.str() << std::endl;
+
+    run_date  = calendar_date(2000,  1,  1);
+    bill_date = next_bill_date(inception, run_date, mce_quarterly);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  1,  1));
+std::cout << bill_date.str() << std::endl;
+
+    run_date  = calendar_date(2000,  1,  2);
+    bill_date = next_bill_date(inception, run_date, mce_semiannual);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  7,  1));
+std::cout << bill_date.str() << std::endl;
+
+    run_date  = calendar_date(2000,  2,  1);
+    bill_date = next_bill_date(inception, run_date, mce_semiannual);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  7,  1));
+
+    run_date  = calendar_date(2000,  6, 30);
+    bill_date = next_bill_date(inception, run_date, mce_quarterly);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  7,  1));
+
+    run_date  = calendar_date(2000,  1,  1);
+    bill_date = next_bill_date(inception, run_date, mce_quarterly);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  1,  1));
+
+    run_date  = calendar_date(2000,  1,  1);
+    bill_date = next_bill_date(inception, run_date, mce_quarterly);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  1,  1));
+
+    run_date  = calendar_date(2000,  1,  1);
+    bill_date = next_bill_date(inception, run_date, mce_quarterly);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  1,  1));
+
+    run_date  = calendar_date(2000,  1,  1);
+    bill_date = next_bill_date(inception, run_date, mce_quarterly);
+    BOOST_TEST_EQUAL(bill_date, calendar_date(2000,  1,  1));
+
+return;
     calendar_date dublin_epoch;
     dublin_epoch.julian_day_number(2415020);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]