From 697d228eb35942283a9d81eefe064d0b3514f7ec Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sun, 9 Jun 2013 21:32:06 +0000 Subject: [PATCH] Introduce transaction setter xaccTransSetDatePostedSecsNormalized() that ignores the time-of-day part. We've struggled with the time-of-day part of the PostedDate for long enough. The PostedDate field is just not meaningful with anything else but a plain date, and no time-of-day at all. Hence, the correct setter function for this particular field must ignore the time-of-day. Consequently, a GDate should be used here anyway, but in many places the time64 is more convenient. The new function will now redirect that time64 to the GDate setter function to make sure we will now map everything to one single date. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23044 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Transaction.c | 8 ++++++++ src/engine/Transaction.h | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 9878eacaa4..53f01b2d4a 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1803,6 +1803,14 @@ xaccTransSetDatePostedSecs (Transaction *trans, time64 secs) set_gains_date_dirty (trans); } +void +xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time) +{ + GDate date; + gnc_gdate_set_time64(&date, time); + xaccTransSetDatePostedGDate(trans, date); +} + void xaccTransSetDatePostedGDate (Transaction *trans, GDate date) { diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 70c16d6dcb..51ba5e0052 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -556,11 +556,27 @@ void xaccTransSetDate (Transaction *trans, void xaccTransSetDatePostedGDate (Transaction *trans, GDate date); /** The xaccTransSetDatePostedSecs() method will modify the posted - date of the transaction, specified by a time64 (see ctime(3)). The - posted date is the date when this transaction was posted at the - bank. */ + * date of the transaction, specified by a time64 (see ctime(3)). The + * posted date is the date when this transaction was posted at the + * bank. + * + * Please do not use this function, as the extra time-of-day part messes up a + * lot of places. Rather, please use xaccTransSetDatePostedGDate() or + * xaccTransSetDatePostedSecsNormalized(). + */ void xaccTransSetDatePostedSecs (Transaction *trans, time64 time); +/** This function sets the posted date of the transaction, specified by + * a time64 (see ctime(3)). Contrary to xaccTransSetDatePostedSecs(), the time + * will be normalized to only the date part, and the time-of-day will be + * ignored. The resulting date is the same as if it had been set as a GDate + * through xaccTransSetDatePostedGDate(). + * + * Please prefer this function over xaccTransSetDatePostedSecs(). + * + * The posted date is the date when this transaction was posted at the bank. */ +void xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time); + /** The xaccTransSetDatePostedTS() method does the same thing as xaccTransSetDatePostedSecs(), but takes a struct timespec64. */ void xaccTransSetDatePostedTS (Transaction *trans,