[Transaction.cpp] use qof_instance kvp API for GDate

pull/2107/head
Christopher Lam 10 months ago
parent fac028133e
commit f3f917df38

@ -1945,16 +1945,13 @@ xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
void
xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
{
GValue v = G_VALUE_INIT;
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 time64. */
g_value_init (&v, G_TYPE_DATE);
g_value_set_static_boxed (&v, &date);
qof_instance_set_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_DATE_POSTED);
g_value_unset (&v);
qof_instance_set_path_kvp<GDate> (QOF_INSTANCE(trans), date, {TRANS_DATE_POSTED});
qof_instance_set_dirty (QOF_INSTANCE(trans));
/* mark dirty and commit handled by SetDateInternal */
xaccTransSetDateInternal(trans, &trans->date_posted,
gdate_to_time64(date));
@ -2301,11 +2298,8 @@ xaccTransGetDatePostedGDate (const Transaction *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. */
GValue v = G_VALUE_INIT;
qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_POSTED);
if (G_VALUE_HOLDS_BOXED (&v))
result = *(GDate*)g_value_get_boxed (&v);
g_value_unset (&v);
if (auto res = qof_instance_get_path_kvp<GDate> (QOF_INSTANCE(trans), {TRANS_DATE_POSTED}))
result = *res;
if (! g_date_valid (&result) || gdate_to_time64 (result) == INT64_MAX)
{
/* Well, this txn doesn't have a valid GDate saved in a slot.

@ -1081,12 +1081,14 @@ qof_instance_set_path_kvp (QofInstance* inst, std::optional<T> value, const Path
}
template std::optional<Time64> qof_instance_get_path_kvp <Time64> (QofInstance*, const Path&);
template std::optional<GDate> qof_instance_get_path_kvp <GDate> (QofInstance*, const Path&);
template std::optional<const char*> qof_instance_get_path_kvp <const char*> (QofInstance*, const Path&);
template std::optional<gnc_numeric> qof_instance_get_path_kvp <gnc_numeric> (QofInstance*, const Path&);
template std::optional<GncGUID*> qof_instance_get_path_kvp <GncGUID*> (QofInstance*, const Path&);
template std::optional<int64_t> qof_instance_get_path_kvp <int64_t> (QofInstance*, const Path&);
template void qof_instance_set_path_kvp <Time64> (QofInstance*, std::optional<Time64>, const Path& path);
template void qof_instance_set_path_kvp <GDate> (QofInstance*, std::optional<GDate>, const Path& path);
template void qof_instance_set_path_kvp <const char*> (QofInstance*, std::optional<const char*>, const Path& path);
template void qof_instance_set_path_kvp <gnc_numeric> (QofInstance*, std::optional<gnc_numeric>, const Path& path);
template void qof_instance_set_path_kvp <GncGUID*> (QofInstance*, std::optional<GncGUID*>, const Path& path);

Loading…
Cancel
Save