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.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18925 57a11ea4-9604-0410-9ed3-97b8803252fd
pull/1/head
Christian Stimming 17 years ago
parent 0b7b3cf6a1
commit 59be2dc692

@ -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)
{

@ -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 <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 @@ 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.*/

Loading…
Cancel
Save