r18925 - gnucash/trunk/src/engine - Add getter/setter for transaction posted-date as a GDate.
Christian Stimming
cstim at code.gnucash.org
Wed Mar 17 15:23:40 EDT 2010
Author: cstim
Date: 2010-03-17 15:23:40 -0400 (Wed, 17 Mar 2010)
New Revision: 18925
Trac: http://svn.gnucash.org/trac/changeset/18925
Modified:
gnucash/trunk/src/engine/Transaction.c
gnucash/trunk/src/engine/Transaction.h
Log:
Add getter/setter for transaction posted-date as a GDate.
In addition to the known timespec, the date is also stored
as a kvp_value of TYPE_GDATE so that we know afterwards this
date has really been set as a date.
Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c 2010-03-17 19:23:20 UTC (rev 18924)
+++ gnucash/trunk/src/engine/Transaction.c 2010-03-17 19:23:40 UTC (rev 18925)
@@ -1585,6 +1585,28 @@
}
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)
{
Timespec ts = {secs, 0};
@@ -1631,11 +1653,12 @@
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 @@
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)
{
Modified: gnucash/trunk/src/engine/Transaction.h
===================================================================
--- gnucash/trunk/src/engine/Transaction.h 2010-03-17 19:23:20 UTC (rev 18924)
+++ gnucash/trunk/src/engine/Transaction.h 2010-03-17 19:23:40 UTC (rev 18925)
@@ -442,6 +442,15 @@
void xaccTransSetDate (Transaction *trans,
int day, int mon, int year);
+/** This method modifies <i>posted</i> 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 <i>posted</i>
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 @@
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.*/
More information about the gnucash-changes
mailing list