Added UTC add operations.
authorArjen Baart <arjen@andromeda.nl>
Thu, 24 Oct 2019 21:10:54 +0000 (23:10 +0200)
committerArjen Baart <arjen@andromeda.nl>
Thu, 24 Oct 2019 21:10:54 +0000 (23:10 +0200)
.gitignore [new file with mode: 0644]
depends [new file with mode: 0644]
src/utc.cpp
test/Makefile.am
test/string_substring.exp [new file with mode: 0644]
test/utc_arithmetic.cpp [new file with mode: 0644]
test/utc_arithmetic.exp [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..70845e0
--- /dev/null
@@ -0,0 +1 @@
+Makefile.in
diff --git a/depends b/depends
new file mode 100644 (file)
index 0000000..8ec845b
--- /dev/null
+++ b/depends
@@ -0,0 +1 @@
+xmldoc
index e106c87..ebaef07 100644 (file)
@@ -84,6 +84,24 @@ UTC Now()
    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;
index b4691f5..0d8369c 100644 (file)
@@ -5,7 +5,7 @@ LDADD = ../src/.libs/libACL.la
 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
@@ -33,3 +33,4 @@ hour_check_now_SOURCES     = hour_check_now.cpp
 hour_now : hour_check_now
 utc_assign_SOURCES         = utc_assign.cpp
 utc_compare_SOURCES        = utc_compare.cpp
+utc_arithmetic_SOURCES     = utc_arithmetic.cpp
diff --git a/test/string_substring.exp b/test/string_substring.exp
new file mode 100644 (file)
index 0000000..734353e
--- /dev/null
@@ -0,0 +1,5 @@
+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)
diff --git a/test/utc_arithmetic.cpp b/test/utc_arithmetic.cpp
new file mode 100644 (file)
index 0000000..7006bd8
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************
+ *  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;
+}
+
diff --git a/test/utc_arithmetic.exp b/test/utc_arithmetic.exp
new file mode 100644 (file)
index 0000000..826046f
--- /dev/null
@@ -0,0 +1,4 @@
+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)