mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-01-30 03:30:34 +01:00
Don't return history data relative to the earliest point, only within the time period given
This commit is contained in:
parent
a65e5761d9
commit
cf9692f1e9
1 changed files with 3 additions and 4 deletions
|
|
@ -196,7 +196,7 @@ dkp_history_copy_array_timespan (const GPtrArray *array, guint timespan)
|
|||
guint i;
|
||||
const DkpHistoryObj *obj;
|
||||
GPtrArray *array_new;
|
||||
guint start;
|
||||
GTimeVal timeval;
|
||||
|
||||
/* no data */
|
||||
if (array->len == 0)
|
||||
|
|
@ -204,14 +204,13 @@ dkp_history_copy_array_timespan (const GPtrArray *array, guint timespan)
|
|||
|
||||
/* new data */
|
||||
array_new = g_ptr_array_new ();
|
||||
g_get_current_time (&timeval);
|
||||
|
||||
/* treat the timespan like a range, and search backwards */
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, array->len-1);
|
||||
start = obj->time;
|
||||
timespan *= 0.95f;
|
||||
for (i=array->len-1; i>0; i--) {
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
if (start - obj->time < timespan)
|
||||
if (timeval.tv_sec - obj->time < timespan)
|
||||
g_ptr_array_add (array_new, dkp_history_obj_copy (obj));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue