--- /dev/null
+Makefile.in
return UTC(d, t);
}
+UTC operator+(UTC &t1, UTC &t2)
+{
+ UTC t = t1;
+
+ t.d += t2.d;
+ t.t += t2.t;
+
+ return t;
+}
+
+UTC UTC::operator+=(UTC u)
+{
+ d += u.d;
+ t += u.t;
+
+ return *this;
+}
+
std::ostream& operator<<(std::ostream &s, const UTC &t)
{
s << t.d << " " << t.t;
check_PROGRAMS = string_assign string_basics string_compare string_cat string_substring string_regex \
date_assign date_parse date_compare date_arithmetic date_attributes date_check_today \
hour_assign hour_parse hour_compare hour_arithmetic hour_check_now \
- utc_assign utc_compare
+ utc_assign utc_compare utc_arithmetic
string_assign_SOURCES = string_assign.cpp
string_basics_SOURCES = string_basics.cpp
hour_now : hour_check_now
utc_assign_SOURCES = utc_assign.cpp
utc_compare_SOURCES = utc_compare.cpp
+utc_arithmetic_SOURCES = utc_arithmetic.cpp
--- /dev/null
+The substring (3,5) of abcdefghijkl is defgh
+Replace substring (3,5) of abcdefghijkl with 12345678 : abc12345678ijkl
+Insert "12345678" into "abcdefghijkl" : abc12345678defghijkl
+Remove part of "abc12345678defghijkl" : abc12345678ijkl
+PASS string_substring (exit status: 0)
--- /dev/null
+/*******************************************************
+ * Unit test for the UTC class
+ *
+ * test UTC add and subtract expressions
+ ******************************************************
+ *
+ */
+
+#include "date.h"
+#include <assert.h>
+
+int main()
+{
+ date d0(9, 6, 2019);
+ hour t0;
+ UTC period0(date(5, 3, 6), t0);
+
+ UTC u0(d0, t0);
+ UTC d1;
+ UTC d2;
+ d2 = u0 + period0;
+
+ std::cout << u0 << " + " << period0 << " = " << d2 << "\n";
+ assert(d2 == UTC(date(14, 9, 2025), t0));
+
+ UTC period1(date(30, 11, 3), t0); // 3 years, 11 months and 30 days
+ d2 = u0 + period1;
+ std::cout << u0 << " + " << period1 << " = " << d2 << "\n";
+ assert(d2 == UTC(date(8, 6, 2023), t0));
+
+ d1 = UTC(date(22, 7, 2019), t0);
+ std::cout << d1 << " += " << period1 << " = ";
+ d1 += period1;
+ std::cout << d1 << "\n";
+ std::cout.flush();
+ assert(d1 == UTC(date(22, 7, 2023), t0));
+
+ return 0;
+}
+
--- /dev/null
+09-06-2019 00:00:00 + 05-03-6 00:00:00 = 14-09-2025 00:00:00
+09-06-2019 00:00:00 + 30-11-3 00:00:00 = 08-06-2023 00:00:00
+22-07-2019 00:00:00 += 30-11-3 00:00:00 = 22-07-2023 00:00:00
+PASS utc_arithmetic (exit status: 0)