mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Patch from Klee Dienes <klee@mit.edu> (bugzilla #420550) to
re-implement gnc_lot_get_earliest_split and gnc_lot_get_latest_split using xaccSplitDateOrder. This greatly simplifies the functions. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15790 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
d4a33b2311
commit
09f8e28a83
@ -370,59 +370,25 @@ gnc_lot_remove_split (GNCLot *lot, Split *split)
|
|||||||
Split *
|
Split *
|
||||||
gnc_lot_get_earliest_split (GNCLot *lot)
|
gnc_lot_get_earliest_split (GNCLot *lot)
|
||||||
{
|
{
|
||||||
SplitList *node;
|
if (! lot->splits)
|
||||||
Timespec ts;
|
return NULL;
|
||||||
Split *earliest = NULL;
|
lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder);
|
||||||
|
return lot->splits->data;
|
||||||
ts.tv_sec = ((long long) ULONG_MAX);
|
|
||||||
ts.tv_nsec = 0;
|
|
||||||
if (!lot) return NULL;
|
|
||||||
|
|
||||||
for (node=lot->splits; node; node=node->next)
|
|
||||||
{
|
|
||||||
Split *s = node->data;
|
|
||||||
Transaction *trans = s->parent;
|
|
||||||
if (!trans) continue;
|
|
||||||
if ((ts.tv_sec > trans->date_posted.tv_sec) ||
|
|
||||||
((ts.tv_sec == trans->date_posted.tv_sec) &&
|
|
||||||
(ts.tv_nsec > trans->date_posted.tv_nsec)))
|
|
||||||
|
|
||||||
{
|
|
||||||
ts = trans->date_posted;
|
|
||||||
earliest = s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return earliest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Split *
|
Split *
|
||||||
gnc_lot_get_latest_split (GNCLot *lot)
|
gnc_lot_get_latest_split (GNCLot *lot)
|
||||||
{
|
{
|
||||||
SplitList *node;
|
SplitList *node;
|
||||||
Timespec ts;
|
|
||||||
Split *latest = NULL;
|
|
||||||
|
|
||||||
ts.tv_sec = 0;
|
if (! lot->splits)
|
||||||
ts.tv_nsec = 0;
|
return NULL;
|
||||||
if (!lot) return NULL;
|
lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder);
|
||||||
|
|
||||||
for (node=lot->splits; node; node=node->next)
|
for (node = lot->splits; node->next; node = node->next)
|
||||||
{
|
;
|
||||||
Split *s = node->data;
|
|
||||||
Transaction *trans = s->parent;
|
|
||||||
if (!trans) continue;
|
|
||||||
if ((ts.tv_sec < trans->date_posted.tv_sec) ||
|
|
||||||
((ts.tv_sec == trans->date_posted.tv_sec) &&
|
|
||||||
(ts.tv_nsec < trans->date_posted.tv_nsec)))
|
|
||||||
|
|
||||||
{
|
|
||||||
ts = trans->date_posted;
|
|
||||||
latest = s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return latest;
|
return node->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============================================================= */
|
/* ============================================================= */
|
||||||
|
Loading…
Reference in New Issue
Block a user