From 811d752a12f82c042d67eb9a6fca670c2f8bfb61 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 6 Oct 1998 07:28:30 +0000 Subject: [PATCH] add some stuff to improve date handling git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1278 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/FileIO.c | 5 +++++ src/engine/Transaction.c | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/engine/FileIO.c b/src/engine/FileIO.c index 5c9520fbf0..f365c55f76 100644 --- a/src/engine/FileIO.c +++ b/src/engine/FileIO.c @@ -107,6 +107,11 @@ #define RFLAGS O_RDONLY #define VERSION 7 + +/* hack alert the current file format does not support most of the + * new/improved account & transaction structures + */ + /** GLOBALS *********************************************************/ /* the default currency is used when importin old-style diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 11e92ac42b..015c880f4b 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -25,6 +25,9 @@ #include #include +#include +#include +#include #include "config.h" @@ -788,6 +791,15 @@ xaccTransCommitEdit (Transaction *trans) return; } + /* try to get the sorting order lined up according to + * when the user typed things in. */ + if (0 == trans->date_entered.tv_sec) { + struct timeval tv; + gettimeofday (&tv, NULL); + trans->date_entered.tv_sec = tv.tv_sec; + trans->date_entered.tv_nsec = 1000 * tv.tv_usec; + } + /* Alternately the transaction may have only one split in * it, in which case ... that's OK if and only if the split has no * value (i.e. is only recording a price). Otherwise, a single @@ -1265,14 +1277,14 @@ xaccTransOrder (Transaction **ta, Transaction **tb) db = (*tb)->num; SAFE_STRCMP (da, db); + /* if dates differ, return */ + DATE_CMP(ta,tb,date_entered); + /* otherwise, sort on description string */ da = (*ta)->description; db = (*tb)->description; SAFE_STRCMP (da, db); - /* if dates differ, return */ - DATE_CMP(ta,tb,date_entered); - /* otherwise, sort on docref string */ da = (*ta)->docref; db = (*tb)->docref; @@ -1364,10 +1376,6 @@ xaccTransSetDateSecs (Transaction *trans, time_t secs) if (!trans) return; CHECK_OPEN (trans); - /* hack alert -- for right now, keep the posted and the entered - * dates in sync. Later, we'll have to split these up. */ - - trans->date_entered.tv_sec = secs; trans->date_posted.tv_sec = secs; /* Because the date has changed, we need to make sure that each of the