gnucash maint: Fix the implementations of gnc_foo_get_day_neutral.

John Ralls jralls at code.gnucash.org
Sat Mar 20 12:50:09 EDT 2021


Updated	 via  https://github.com/Gnucash/gnucash/commit/3a35514d (commit)
	from  https://github.com/Gnucash/gnucash/commit/c6c5777c (commit)



commit 3a35514d84c30fb8a2263e00672dc651be7a7dc5
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Mar 19 17:09:03 2021 -0700

    Fix the implementations of gnc_foo_get_day_neutral.
    
    As implemented these returned 10:59 AM local on the day but neutral
    time is 10:59 UTC.

diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 2f48aa91f..3a969a46d 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -1269,6 +1269,14 @@ gnc_tm_get_day_start (struct tm *tm, time64 time_val)
     gnc_tm_set_day_start(tm);
 }
 
+void
+gnc_tm_set_day_neutral (struct tm *tm)
+{
+    auto time_val{gnc_dmy2time64_internal(tm->tm_mday, tm->tm_mon + 1,
+                                          tm->tm_year + 1900, DayPart::neutral)};
+    gnc_localtime_r(&time_val, tm);
+}
+
 static void
 gnc_tm_get_day_neutral (struct tm *tm, time64 time_val)
 {
@@ -1302,11 +1310,9 @@ time64
 gnc_time64_get_day_neutral (time64 time_val)
 {
     struct tm tm;
-    time64 new_time;
-
-    gnc_tm_get_day_neutral(&tm, time_val);
-    new_time = gnc_mktime(&tm);
-    return new_time;
+    gnc_localtime_r(&time_val, &tm);
+    return gnc_dmy2time64_internal(tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900,
+                                   DayPart::neutral);
 }
 
 time64
diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index 7556fd1c6..8f445530a 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -539,18 +539,9 @@ void gnc_tm_set_day_start (struct tm *tm)
 }
 
 /** The gnc_tm_set_day_neutral() inline routine will set the appropriate
- *  fields in the struct tm to indicate 10:59am of that day.  This
- *  routine assumes that the contents of the data structure is already
- *  in normalized form.*/
-static inline
-void gnc_tm_set_day_neutral (struct tm *tm)
-{
-    /* First second of the day */
-    g_return_if_fail (tm != NULL);
-    tm->tm_hour = 10;
-    tm->tm_min = 59;
-    tm->tm_sec = 0;
-}
+ *  fields in the struct tm to indicate 10:59am of that day.
+ */
+void gnc_tm_set_day_neutral (struct tm *tm);
 
 /** The gnc_tm_set_day_middle() inline routine will set the appropriate
  *  fields in the struct tm to indicate noon of that day.  This
@@ -584,7 +575,7 @@ void gnc_tm_set_day_end (struct tm *tm)
  *  seconds and adjust it to the first second of that day. */
 time64 gnc_time64_get_day_start(time64 time_val);
 
-/** The gnc_time64_get_day_netural() routine will take the given time in
+/** The gnc_time64_get_day_neutral() routine will take the given time in
  *  seconds and adjust it to 10:59am of that day. */
 time64 gnc_time64_get_day_neutral(time64 time_val);
 



Summary of changes:
 libgnucash/engine/gnc-date.cpp | 16 +++++++++++-----
 libgnucash/engine/gnc-date.h   | 17 ++++-------------
 2 files changed, 15 insertions(+), 18 deletions(-)



More information about the gnucash-changes mailing list