From f89fbf4fa4939c052a3ca6bf2201c893540191b0 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 10 Oct 1998 05:39:08 +0000 Subject: [PATCH] add datte reconciled to file format git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1283 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/FileIO.c | 29 +++++++++++++++++++++++++++-- src/engine/Transaction.c | 38 +++++++++++++++++++++++++++++++++++--- src/engine/Transaction.h | 4 ++++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/engine/FileIO.c b/src/engine/FileIO.c index 3d2d012970..769e663969 100644 --- a/src/engine/FileIO.c +++ b/src/engine/FileIO.c @@ -54,8 +54,8 @@ * numGroups (Group)^numGroups * * Transaction ::== num date_entered date_posted description * * numSplits (Split)^numSplits * - * Split ::== memo action reconciled * - * amount share_price account * + * Split ::== memo action reconciled date_recned * + * amount share_price account * * token ::== int [the version of file format == VERSION] * * numTrans ::== int * * numAccounts ::== int * @@ -72,6 +72,7 @@ * num ::== String * * date_entered::== Date * * date_posted ::== Date * + * date_recned ::== Date * * description ::== String * * memo ::== String * * action ::== String * @@ -989,6 +990,25 @@ readSplit ( int fd, int token ) } xaccSplitSetReconcile (split, recn); + /* version 8 and newwer files store date-reconciled */ + if (8 <= token) { + struct timespec ts; + int rc; + + rc = readTSDate( fd, &ts, token ); + if( -1 == rc ) + { + PERR ("Premature end of Split at date"); + xaccSplitDestroy (split); + return NULL; + } + xaccSplitSetDateReconciledTS (split, &ts); + } else { + time_t now; + now = time (0); + xaccSplitSetDateReconciledSecs (split, now); + } + /* first, read number of shares ... */ err = read( fd, &num_shares, sizeof(double) ); if( sizeof(double) != err ) @@ -1513,6 +1533,7 @@ writeSplit ( int fd, Split *split ) { int err=0; int acc_id; + struct timespec ts; double damount; Account *xfer_acc; char recn; @@ -1531,6 +1552,10 @@ writeSplit ( int fd, Split *split ) err = write( fd, &recn, sizeof(char) ); if( err != sizeof(char) ) return -1; + + xaccSplitGetDateReconciledTS (split, &ts); + err = writeTSDate( fd, &ts); + if( -1 == err ) return err; damount = xaccSplitGetShareAmount (split); INFO_2 ("writeSplit: amount=%f \n", damount); diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 3e6e180a06..8656aa8ec5 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1377,6 +1377,7 @@ xaccTransSetDateSecs (Transaction *trans, time_t secs) CHECK_OPEN (trans); trans->date_posted.tv_sec = secs; + trans->date_posted.tv_nsec = 0; /* Because the date has changed, we need to make sure that each of the * splits is properly ordered in each of thier accounts. We could do that @@ -1395,6 +1396,7 @@ xaccTransSetDateEnteredSecs (Transaction *trans, time_t secs) CHECK_OPEN (trans); trans->date_entered.tv_sec = secs; + trans->date_entered.tv_nsec = 0; } void @@ -1439,10 +1441,14 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year) void xaccTransSetDateToday (Transaction *trans) { - time_t secs; + struct timeval tv; - secs = time (0); - xaccTransSetDateSecs (trans, secs); + if (!trans) return; + CHECK_OPEN (trans); + + gettimeofday (&tv, NULL); + trans->date_posted.tv_sec = tv.tv_sec; + trans->date_posted.tv_nsec = 1000 * tv.tv_usec; } @@ -1609,6 +1615,32 @@ xaccSplitSetReconcile (Split *split, char recn) xaccAccountRecomputeBalance (split->acc); } +void +xaccSplitSetDateReconciledSecs (Split *split, time_t secs) +{ + if (!split) return; + MARK_SPLIT (split); + + split->date_reconciled.tv_sec = secs; + split->date_reconciled.tv_nsec = 0; +} + +void +xaccSplitSetDateReconciledTS (Split *split, struct timespec *ts) +{ + if (!split) return; + MARK_SPLIT (split); + + split->date_reconciled = *ts; +} + +void +xaccSplitGetDateReconciledTS (Split * split, Timespec *ts) +{ + if (!split || !ts) return; + *ts = (split->date_reconciled); +} + /********************************************************************\ \********************************************************************/ diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 642d9c0ae6..feff3ce629 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -212,6 +212,10 @@ void xaccSplitSetAction (Split *, const char *); * are "no", "cleared" and "reconciled" */ void xaccSplitSetReconcile (Split *, char); +void xaccSplitSetDateReconciledSecs (Split *, time_t); +void xaccSplitSetDateReconciledTS (Split *, struct timespec *); +void xaccSplitGetDateReconciledTS (Split *, struct timespec *); + /* * The following four functions set the prices and amounts.