diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c
index aa3bb6a9a7..5ca16efdbc 100644
--- a/src/engine/Transaction.c
+++ b/src/engine/Transaction.c
@@ -1584,6 +1584,28 @@ xaccTransSetDatePostedSecs (Transaction *trans, time_t secs)
set_gains_date_dirty (trans);
}
+void
+xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
+{
+ KvpValue* kvp_value;
+ KvpFrame* frame;
+ if (!trans) return;
+
+ /* We additionally save this date into a kvp frame to ensure in
+ * the future a date which was set as *date* (without time) can
+ * clearly be distinguished from the Timespec. */
+ kvp_value = kvp_value_new_gdate(date);
+ frame = kvp_frame_set_value_nc(trans->inst.kvp_data, TRANS_DATE_POSTED, kvp_value);
+ if (!frame)
+ {
+ kvp_value_delete(kvp_value);
+ }
+
+ xaccTransSetDateInternal(trans, &trans->date_posted,
+ gdate_to_timespec(date));
+ set_gains_date_dirty (trans);
+}
+
void
xaccTransSetDateEnteredSecs (Transaction *trans, time_t secs)
{
@@ -1631,11 +1653,12 @@ xaccTransSetDateEnteredTS (Transaction *trans, const Timespec *ts)
void
xaccTransSetDate (Transaction *trans, int day, int mon, int year)
{
- Timespec ts;
+ GDate *date;
if (!trans) return;
- ts = gnc_dmy2timespec(day, mon, year);
- xaccTransSetDateInternal(trans, &trans->date_posted, ts);
- set_gains_date_dirty (trans);
+ date = g_date_new_dmy(day, mon, year);
+ g_assert(g_date_valid(date));
+ xaccTransSetDatePostedGDate(trans, *date);
+ g_date_free(date);
}
void
@@ -1833,6 +1856,29 @@ xaccTransRetDatePostedTS (const Transaction *trans)
return trans ? trans->date_posted : ts;
}
+GDate
+xaccTransGetDatePostedGDate (const Transaction *trans)
+{
+ GDate result;
+ if (trans)
+ {
+ /* Can we look up this value in the kvp slot? If yes, use it
+ * from there because it doesn't suffer from time zone
+ * shifts. */
+ const KvpValue* kvp_value =
+ kvp_frame_get_slot(trans->inst.kvp_data, TRANS_DATE_POSTED);
+ if (kvp_value)
+ result = kvp_value_get_gdate(kvp_value);
+ else
+ result = timespec_to_gdate(xaccTransRetDatePostedTS(trans));
+ }
+ else
+ {
+ g_date_clear(&result, 1);
+ }
+ return result;
+}
+
Timespec
xaccTransRetDateEnteredTS (const Transaction *trans)
{
diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h
index 42515b1696..b1e6912fff 100644
--- a/src/engine/Transaction.h
+++ b/src/engine/Transaction.h
@@ -442,6 +442,15 @@ int xaccTransOrder (const Transaction *ta, const Transaction *tb);
void xaccTransSetDate (Transaction *trans,
int day, int mon, int year);
+/** This method modifies posted date of the transaction,
+ * specified by a GDate. The posted date is the date when this
+ * transaction was posted at the bank.
+ *
+ * This is identical to xaccTransSetDate(), but different from
+ * xaccTransSetDatePostedSecs which artificially introduces the
+ * time-of-day part, which needs to be ignored. */
+void xaccTransSetDatePostedGDate (Transaction *trans, GDate date);
+
/** The xaccTransSetDatePostedSecs() method will modify the posted
date of the transaction, specified by a time_t (see ctime(3)). The
posted date is the date when this transaction was posted at the
@@ -480,6 +489,9 @@ void xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts);
having different function names, GetDate and GetDatePosted refer
to the same single date.)*/
Timespec xaccTransRetDatePostedTS (const Transaction *trans);
+/** Retrieve the posted date of the transaction. The posted date is
+ the date when this transaction was posted at the bank. */
+GDate xaccTransGetDatePostedGDate (const Transaction *trans);
/** Retrieve the date of when the transaction was entered. The entered
* date is the date when the register entry was made.*/