gnucash maint: Add more tests for neutral time.

John Ralls jralls at code.gnucash.org
Sat Mar 14 13:15:49 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/8b616449 (commit)
	from  https://github.com/Gnucash/gnucash/commit/6d9e7d93 (commit)



commit 8b6164497852737f85e4246746db8953a4860107
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Mar 14 10:15:12 2020 -0700

    Add more tests for neutral time.

diff --git a/libgnucash/engine/test/gtest-gnc-datetime.cpp b/libgnucash/engine/test/gtest-gnc-datetime.cpp
index debcd00f9..3fcbb6d20 100644
--- a/libgnucash/engine/test/gtest-gnc-datetime.cpp
+++ b/libgnucash/engine/test/gtest-gnc-datetime.cpp
@@ -385,7 +385,8 @@ TEST(gnc_datetime_constructors, test_gncdate_neutral_constructor)
 {
     const ymd aymd = { 2017, 04, 20 };
     GncDateTime atime(GncDate(aymd.year, aymd.month, aymd.day), DayPart::neutral);
-    GncDateTime gncdt(1492685940); /* 20 Apr 2017 10:59:00 Z */
+    time64 date{1492685940};
+    GncDateTime gncdt(date); /* 20 Apr 2017 10:59:00 Z */
     /* The ymd constructor sets the time of day at 10:59:00 for
      * timezones between UTC-10 and UTC+13. For other timezones the
      * time of day is adjusted to ensure a consistent date and the
@@ -397,9 +398,48 @@ TEST(gnc_datetime_constructors, test_gncdate_neutral_constructor)
         gncdt.offset() <= max_eastern_offset)
     {
         EXPECT_EQ(atime.format("%d-%m-%Y %H:%M:%S %Z"), "20-04-2017 10:59:00 UTC");
+//        EXPECT_EQ(atime, gncdt);
+        EXPECT_EQ(date, static_cast<time64>(gncdt));
+        EXPECT_EQ(date, static_cast<time64>(atime));
     }
 }
 
+TEST(gnc_datetime_constructors, test_neutral_across_timezones)
+{
+    const ymd begins = {2018, 03, 05};
+    const ymd ends = {2018, 03, 15};
+    const time64 ten_days = 864000;
+#ifdef __MINGW32__
+    TimeZoneProvider tzp_lon{"GMT Standard Time"};
+    TimeZoneProvider tzp_perth{"W. Australia Standard Time"};
+    TimeZoneProvider tzp_la{"Pacific Standard Time"};
+#else
+    TimeZoneProvider tzp_lon("Europe/London");
+    TimeZoneProvider tzp_perth("Australia/Perth");
+    TimeZoneProvider tzp_la("America/Los_Angeles");
+#endif
+    _set_tzp(tzp_lon);
+    GncDateTime btime_lon(GncDate(begins.year, begins.month, begins.day), DayPart::neutral);
+    GncDateTime etime_lon(GncDate(ends.year, ends.month, ends.day), DayPart::neutral);
+    _reset_tzp();
+    _set_tzp(tzp_perth);
+    GncDateTime btime_perth(GncDate(begins.year, begins.month, begins.day), DayPart::neutral);
+    GncDateTime etime_perth(GncDate(ends.year, ends.month, ends.day), DayPart::neutral);
+    _reset_tzp();
+    _set_tzp(tzp_la);
+    GncDateTime btime_la(GncDate(begins.year, begins.month, begins.day), DayPart::neutral);
+    GncDateTime etime_la(GncDate(ends.year, ends.month, ends.day), DayPart::neutral);
+    _reset_tzp();
+
+    EXPECT_EQ(static_cast<time64>(btime_lon), static_cast<time64>(btime_perth));
+    EXPECT_EQ(static_cast<time64>(btime_lon), static_cast<time64>(btime_la));
+    EXPECT_EQ(static_cast<time64>(etime_lon), static_cast<time64>(etime_perth));
+    EXPECT_EQ(static_cast<time64>(etime_lon), static_cast<time64>(etime_la));
+    EXPECT_EQ(ten_days, static_cast<time64>(etime_lon) - static_cast<time64>(btime_lon));
+    EXPECT_EQ(ten_days, static_cast<time64>(etime_perth) - static_cast<time64>(btime_perth));
+    EXPECT_EQ(ten_days, static_cast<time64>(etime_la) - static_cast<time64>(btime_la));
+}
+
 TEST(gnc_datetime_functions, test_format)
 {
     GncDateTime atime(2394187200); //2045-11-13 12:00:00 Z



Summary of changes:
 libgnucash/engine/test/gtest-gnc-datetime.cpp | 42 ++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)



More information about the gnucash-changes mailing list