mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
gncEntry members timespec->time64
This commit is contained in:
@@ -724,14 +724,12 @@ gnc_dialog_post_invoice(InvoiceWindow *iw, char *message,
|
||||
if (entries && ((gncInvoiceGetOwnerType (invoice) == GNC_OWNER_VENDOR) ||
|
||||
(gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)))
|
||||
{
|
||||
*postdate = gncEntryGetDate ((GncEntry*)entries->data);
|
||||
postdate->tv_sec = gncEntryGetDate ((GncEntry*)entries->data);
|
||||
for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
|
||||
{
|
||||
Timespec entrydate;
|
||||
|
||||
entrydate = gncEntryGetDate ((GncEntry*)entries_iter->data);
|
||||
if (timespec_cmp(&entrydate, postdate) > 0)
|
||||
*postdate = entrydate;
|
||||
time64 entrydate = gncEntryGetDate ((GncEntry*)entries_iter->data);
|
||||
if (entrydate > postdate->tv_sec)
|
||||
postdate->tv_sec = entrydate;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -944,7 +944,7 @@ gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger)
|
||||
|
||||
/* We also must set a new DateEntered on the new entry
|
||||
* because otherwise the ordering is not deterministic */
|
||||
gncEntrySetDateEntered (new_entry, timespec_now());
|
||||
gncEntrySetDateEntered (new_entry, gnc_time (NULL));
|
||||
|
||||
/* Set the hint for where to display on the refresh */
|
||||
ledger->hint_entry = new_entry;
|
||||
@@ -1017,7 +1017,7 @@ void gnc_entry_ledger_move_current_entry_updown (GncEntryLedger *ledger,
|
||||
* up the current sort ordering from here, so I cowardly refuse to
|
||||
* tweak the EntryDate in this case. */
|
||||
{
|
||||
Timespec t1, t2;
|
||||
time64 t1, t2;
|
||||
GDate d1 = gncEntryGetDateGDate(current),
|
||||
d2 = gncEntryGetDateGDate(target);
|
||||
if (g_date_compare(&d1, &d2) != 0)
|
||||
@@ -1029,7 +1029,7 @@ void gnc_entry_ledger_move_current_entry_updown (GncEntryLedger *ledger,
|
||||
code used the timespec at the start of day. */
|
||||
t1 = gncEntryGetDate(current);
|
||||
t2 = gncEntryGetDate(target);
|
||||
if (!timespec_equal(&t1, &t2))
|
||||
if (t1 != t2)
|
||||
{
|
||||
/* Timespecs are not equal, even though the GDates were equal? Then
|
||||
we set the GDates again. This will force the timespecs to be equal
|
||||
@@ -1048,12 +1048,12 @@ void gnc_entry_ledger_move_current_entry_updown (GncEntryLedger *ledger,
|
||||
/* Swap the date-entered of both entries. That's already
|
||||
* sufficient! */
|
||||
{
|
||||
Timespec time_current = gncEntryGetDateEntered(current);
|
||||
Timespec time_target = gncEntryGetDateEntered(target);
|
||||
time64 time_current = gncEntryGetDateEntered(current);
|
||||
time64 time_target = gncEntryGetDateEntered(target);
|
||||
|
||||
/* Special treatment for identical times (potentially caused
|
||||
* by the "duplicate entry" command) */
|
||||
if (timespec_equal(&time_current, &time_target))
|
||||
if (time_current == time_target)
|
||||
{
|
||||
/*g_warning("Surprise - both DateEntered are equal.");*/
|
||||
/* We just increment the DateEntered of the previously
|
||||
@@ -1061,9 +1061,9 @@ void gnc_entry_ledger_move_current_entry_updown (GncEntryLedger *ledger,
|
||||
* issues if multiple entries had this problem, but
|
||||
* whatever. */
|
||||
if (move_up)
|
||||
time_current.tv_sec++;
|
||||
++time_current;
|
||||
else
|
||||
time_target.tv_sec++;
|
||||
++time_target;
|
||||
}
|
||||
|
||||
/* Write the new DateEntered. */
|
||||
|
@@ -90,10 +90,8 @@ gnc_entry_ledger_save (GncEntryLedger *ledger, gboolean do_commit)
|
||||
|
||||
if (entry == blank_entry)
|
||||
{
|
||||
Timespec ts;
|
||||
ts.tv_sec = gnc_time (NULL);
|
||||
ts.tv_nsec = 0;
|
||||
gncEntrySetDateEntered (blank_entry, ts);
|
||||
time64 time = gnc_time (NULL);
|
||||
gncEntrySetDateEntered (blank_entry, time);
|
||||
|
||||
switch (ledger->type)
|
||||
{
|
||||
|
@@ -187,11 +187,11 @@ static const char * get_date_entry (VirtualLocation virt_loc,
|
||||
{
|
||||
GncEntryLedger *ledger = user_data;
|
||||
GncEntry *entry;
|
||||
Timespec ts;
|
||||
Timespec ts = {0,0};
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
|
||||
ts = gncEntryGetDate (entry);
|
||||
ts.tv_sec = gncEntryGetDate (entry);
|
||||
return gnc_print_date (ts);
|
||||
}
|
||||
|
||||
|
@@ -111,7 +111,6 @@ static xmlNodePtr
|
||||
entry_dom_tree_create (GncEntry* entry)
|
||||
{
|
||||
xmlNodePtr ret;
|
||||
Timespec ts;
|
||||
Account* acc;
|
||||
GncTaxTable* taxtable;
|
||||
GncOrder* order;
|
||||
@@ -123,11 +122,11 @@ entry_dom_tree_create (GncEntry* entry)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_guid_string,
|
||||
qof_instance_get_guid (QOF_INSTANCE (entry))));
|
||||
|
||||
ts = gncEntryGetDate (entry);
|
||||
xmlAddChild (ret, time64_to_dom_tree (entry_date_string, ts.tv_sec));
|
||||
auto time = gncEntryGetDate (entry);
|
||||
xmlAddChild (ret, time64_to_dom_tree (entry_date_string, time));
|
||||
|
||||
ts = gncEntryGetDateEntered (entry);
|
||||
xmlAddChild (ret, time64_to_dom_tree (entry_dateentered_string, ts.tv_sec));
|
||||
time = gncEntryGetDateEntered (entry);
|
||||
xmlAddChild (ret, time64_to_dom_tree (entry_dateentered_string, time));
|
||||
|
||||
maybe_add_string (ret, entry_description_string,
|
||||
gncEntryGetDescription (entry));
|
||||
@@ -241,14 +240,12 @@ set_string (xmlNodePtr node, GncEntry* entry,
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
set_timespec (xmlNodePtr node, GncEntry* entry,
|
||||
void (*func) (GncEntry* entry, Timespec ts))
|
||||
set_time64 (xmlNodePtr node, GncEntry* entry,
|
||||
void (*func) (GncEntry* entry, time64 ts))
|
||||
{
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
|
||||
|
||||
Timespec ts = {time, 0};
|
||||
func (entry, ts);
|
||||
func (entry, time);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -351,16 +348,14 @@ static gboolean
|
||||
entry_date_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata* pdata = static_cast<decltype (pdata)> (entry_pdata);
|
||||
|
||||
return set_timespec (node, pdata->entry, gncEntrySetDate);
|
||||
return set_time64 (node, pdata->entry, gncEntrySetDate);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_dateentered_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata* pdata = static_cast<decltype (pdata)> (entry_pdata);
|
||||
|
||||
return set_timespec (node, pdata->entry, gncEntrySetDateEntered);
|
||||
return set_time64 (node, pdata->entry, gncEntrySetDateEntered);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -1405,6 +1405,13 @@ gnc_gdate_set_time64 (GDate* gd, time64 time)
|
||||
tm.tm_year + 1900);
|
||||
}
|
||||
|
||||
time64 gdate_to_time64 (GDate d)
|
||||
{
|
||||
return gnc_dmy2time64_neutral (g_date_get_day(&d),
|
||||
g_date_get_month(&d),
|
||||
g_date_get_year(&d));
|
||||
}
|
||||
|
||||
Timespec gdate_to_timespec (GDate d)
|
||||
{
|
||||
return gnc_dmy2timespec_neutral (g_date_get_day(&d),
|
||||
|
@@ -354,6 +354,9 @@ GDate timespec_to_gdate (Timespec ts);
|
||||
/** Turns a GDate into a Timespec, returning the first second of the day */
|
||||
Timespec gdate_to_timespec (GDate d);
|
||||
|
||||
/** Turns a GDate into a time64, returning the first second of the day */
|
||||
time64 gdate_to_time64 (GDate d);
|
||||
|
||||
/** Convert a day, month, and year to a time64, returning the first second of the day */
|
||||
time64 gnc_dmy2time64 (gint day, gint month, gint year);
|
||||
|
||||
|
@@ -42,8 +42,8 @@ struct _gncEntry
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
Timespec date;
|
||||
Timespec date_entered;
|
||||
time64 date;
|
||||
time64 date_entered;
|
||||
char * desc;
|
||||
char * action;
|
||||
char * notes;
|
||||
@@ -87,7 +87,7 @@ struct _gncEntry
|
||||
gnc_numeric i_tax_value_rounded;
|
||||
gnc_numeric i_disc_value;
|
||||
gnc_numeric i_disc_value_rounded;
|
||||
Timespec i_taxtable_modtime;
|
||||
time64 i_taxtable_modtime;
|
||||
|
||||
/* vendor bill */
|
||||
gnc_numeric b_value;
|
||||
@@ -95,7 +95,7 @@ struct _gncEntry
|
||||
GList * b_tax_values;
|
||||
gnc_numeric b_tax_value;
|
||||
gnc_numeric b_tax_value_rounded;
|
||||
Timespec b_taxtable_modtime;
|
||||
time64 b_taxtable_modtime;
|
||||
};
|
||||
|
||||
struct _gncEntryClass
|
||||
@@ -478,14 +478,12 @@ static void gncEntryFree (GncEntry *entry)
|
||||
/* ================================================================ */
|
||||
/* Set Functions */
|
||||
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec date)
|
||||
void gncEntrySetDate (GncEntry *entry, time64 date)
|
||||
{
|
||||
gboolean first_date = FALSE;
|
||||
Timespec zero_time = { 0, 0 };
|
||||
|
||||
if (!entry) return;
|
||||
if (timespec_equal (&entry->date, &date)) return;
|
||||
if (timespec_equal (&entry->date, &zero_time))
|
||||
if (entry->date == date) return;
|
||||
if (!entry->date)
|
||||
first_date = TRUE;
|
||||
gncEntryBeginEdit (entry);
|
||||
entry->date = date;
|
||||
@@ -510,15 +508,15 @@ void gncEntrySetDateGDate (GncEntry *entry, const GDate* date)
|
||||
/* Watch out: Here we are deviating from the initial convention that a
|
||||
GDate always converts to the start time of the day. Instead, the GDate is
|
||||
converted to "noon" on the respective date. This is not nice, but this
|
||||
convention was used for the Timespec of GncEntry all the time, so we better
|
||||
convention was used for the time64 of GncEntry all the time, so we better
|
||||
stick to it.*/
|
||||
gncEntrySetDate(entry, timespecCanonicalDayTime(gdate_to_timespec(*date)));
|
||||
gncEntrySetDate(entry, time64CanonicalDayTime(gdate_to_time64(*date)));
|
||||
}
|
||||
|
||||
void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
|
||||
void gncEntrySetDateEntered (GncEntry *entry, time64 date)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (timespec_equal (&entry->date_entered, &date)) return;
|
||||
if (entry->date_entered == date) return;
|
||||
gncEntryBeginEdit (entry);
|
||||
entry->date_entered = date;
|
||||
mark_entry (entry);
|
||||
@@ -875,37 +873,19 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest, gboolean add_entry)
|
||||
/* ================================================================ */
|
||||
/* Get Functions */
|
||||
|
||||
Timespec gncEntryGetDate (const GncEntry *entry)
|
||||
time64 gncEntryGetDate (const GncEntry *entry)
|
||||
{
|
||||
Timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
if (!entry) return ts;
|
||||
return entry->date;
|
||||
}
|
||||
|
||||
time64 gncEntryGetDateTT (const GncEntry *entry)
|
||||
{
|
||||
return entry ? entry->date.tv_sec : 0;
|
||||
return entry ? entry->date : 0;
|
||||
}
|
||||
|
||||
GDate gncEntryGetDateGDate(const GncEntry *entry)
|
||||
{
|
||||
return timespec_to_gdate(gncEntryGetDate(entry));
|
||||
return time64_to_gdate(gncEntryGetDate(entry));
|
||||
}
|
||||
|
||||
Timespec gncEntryGetDateEntered (const GncEntry *entry)
|
||||
time64 gncEntryGetDateEntered (const GncEntry *entry)
|
||||
{
|
||||
Timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
if (!entry) return ts;
|
||||
return entry->date_entered;
|
||||
}
|
||||
|
||||
time64 gncEntryGetDateEnteredTT (const GncEntry *entry)
|
||||
{
|
||||
return entry ? entry->date_entered.tv_sec : 0;
|
||||
return entry ? entry->date_entered : 0;
|
||||
}
|
||||
|
||||
const char * gncEntryGetDescription (const GncEntry *entry)
|
||||
@@ -1353,19 +1333,19 @@ gncEntryRecomputeValues (GncEntry *entry)
|
||||
if (entry->i_tax_table)
|
||||
{
|
||||
Timespec modtime = gncTaxTableLastModified (entry->i_tax_table);
|
||||
if (timespec_cmp (&entry->i_taxtable_modtime, &modtime))
|
||||
if (entry->i_taxtable_modtime != modtime.tv_sec)
|
||||
{
|
||||
entry->values_dirty = TRUE;
|
||||
entry->i_taxtable_modtime = modtime;
|
||||
entry->i_taxtable_modtime = modtime.tv_sec;
|
||||
}
|
||||
}
|
||||
if (entry->b_tax_table)
|
||||
{
|
||||
Timespec modtime = gncTaxTableLastModified (entry->b_tax_table);
|
||||
if (timespec_cmp (&entry->b_taxtable_modtime, &modtime))
|
||||
if (entry->b_taxtable_modtime == modtime.tv_sec)
|
||||
{
|
||||
entry->values_dirty = TRUE;
|
||||
entry->b_taxtable_modtime = modtime;
|
||||
entry->b_taxtable_modtime = modtime.tv_sec;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1612,11 +1592,8 @@ int gncEntryCompare (const GncEntry *a, const GncEntry *b)
|
||||
if (!a && b) return -1;
|
||||
if (a && !b) return 1;
|
||||
|
||||
compare = timespec_cmp (&(a->date), &(b->date));
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
|
||||
if (compare) return compare;
|
||||
if (a->date != b->date) return a->date - b->date;
|
||||
if (a->date_entered != b->date_entered) return a->date_entered - b->date_entered;
|
||||
|
||||
compare = g_strcmp0 (a->desc, b->desc);
|
||||
if (compare) return compare;
|
||||
|
@@ -101,8 +101,8 @@ void gncEntrySetDateGDate (GncEntry *entry, const GDate* date);
|
||||
/** DEPRECATED - use gncEntrySetDateGDate() instead! (Because the time-of-day
|
||||
is a misleading extra information. We are only dealing with the day
|
||||
information! */
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDate (GncEntry *entry, time64 date);
|
||||
void gncEntrySetDateEntered (GncEntry *entry, time64 date);
|
||||
void gncEntrySetDescription (GncEntry *entry, const char *desc);
|
||||
void gncEntrySetAction (GncEntry *entry, const char *action);
|
||||
void gncEntrySetNotes (GncEntry *entry, const char *notes);
|
||||
@@ -159,10 +159,8 @@ GDate gncEntryGetDateGDate (const GncEntry *entry);
|
||||
/** DEPRECATED - use gncEntryGetDateGDate() instead! (Because the time-of-day
|
||||
is a misleading extra information. We are only dealing with the day
|
||||
information! */
|
||||
Timespec gncEntryGetDate (const GncEntry *entry);
|
||||
Timespec gncEntryGetDateEntered (const GncEntry *entry);
|
||||
time64 gncEntryGetDateTT (const GncEntry *entry);
|
||||
time64 gncEntryGetDateEnteredTT (const GncEntry *entry);
|
||||
time64 gncEntryGetDate (const GncEntry *entry);
|
||||
time64 gncEntryGetDateEntered (const GncEntry *entry);
|
||||
const char * gncEntryGetDescription (const GncEntry *entry);
|
||||
const char * gncEntryGetAction (const GncEntry *entry);
|
||||
const char * gncEntryGetNotes (const GncEntry *notes);
|
||||
|
@@ -63,7 +63,7 @@ teardown( Fixture *fixture, gconstpointer pData )
|
||||
static void
|
||||
test_entry_basics ( Fixture *fixture, gconstpointer pData )
|
||||
{
|
||||
Timespec ts1 = timespec_now(), ts2;
|
||||
time64 ts1 = gnc_time(NULL), ts2;
|
||||
const char *desc = "Test description with éà unicode chars";
|
||||
const char *action = "Test action with éà unicode chars";
|
||||
const char *note = "Test note with éà unicode chars";
|
||||
@@ -77,11 +77,11 @@ test_entry_basics ( Fixture *fixture, gconstpointer pData )
|
||||
g_test_message( " Date" );
|
||||
gncEntrySetDate (entry, ts1);
|
||||
ts2 = gncEntryGetDate (entry);
|
||||
g_assert(timespec_equal (&ts2, &ts1));
|
||||
g_assert(ts2 == ts1);
|
||||
g_test_message( " DateEntered" );
|
||||
gncEntrySetDateEntered (entry, ts1);
|
||||
ts2 = gncEntryGetDateEntered (entry);
|
||||
g_assert(timespec_equal (&ts2, &ts1));
|
||||
g_assert(ts2 == ts1);
|
||||
g_test_message( " Description" );
|
||||
gncEntrySetDescription (entry, desc);
|
||||
g_assert(g_strcmp0 (gncEntryGetDescription (entry), desc) == 0);
|
||||
|
Reference in New Issue
Block a user