From ef9c6fbeffea14a47f2c797ffd337b6e40128d1d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 30 May 1999 00:17:48 +0000 Subject: [PATCH] changes from rob browning git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1708 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Transaction.c | 82 ++++++++++++++++++++++------------------ src/engine/Transaction.h | 7 +++- 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index dfca8da2d5..05e14a3e60 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -343,8 +343,8 @@ xaccInitTransaction( Transaction * trans ) trans->date_posted.tv_sec = 0; trans->date_posted.tv_nsec = 0; - trans->write_flag = 0; - trans->open = 0; + trans->write_flag = 0; + trans->open = 0; trans->orig = NULL; } @@ -1510,7 +1510,7 @@ xaccTransSetDateEnteredSecs (Transaction *trans, time_t secs) } void -xaccTransSetDateTS (Transaction *trans, Timespec *ts) +xaccTransSetDateTS (Transaction *trans, const Timespec *ts) { if (!trans) return; CHECK_OPEN (trans); @@ -1525,7 +1525,7 @@ xaccTransSetDateTS (Transaction *trans, Timespec *ts) } void -xaccTransSetDateEnteredTS (Transaction *trans, Timespec *ts) +xaccTransSetDateEnteredTS (Transaction *trans, const Timespec *ts) { if (!trans) return; CHECK_OPEN (trans); @@ -1536,39 +1536,49 @@ xaccTransSetDateEnteredTS (Transaction *trans, Timespec *ts) #define THIRTY_TWO_YEARS 0x3c30fc00LL +Timespec +gnc_dmy2timespec(int day, int month, int year) { + Timespec result; + struct tm date; + long long secs = 0; + long long era = 0; + + year -= 1900; + + /* make a crude attempt to deal with dates outside the + * range of Dec 1901 to Jan 2038. Note the we screw up + * centenial leap years here ... so hack alert -- + */ + if ((2 > year) || (136 < year)) + { + era = year / 32; + year %= 32; + if (0 > year) { year += 32; era -= 1; } + } + + date.tm_year = year; + date.tm_mon = month - 1; + date.tm_mday = day; + date.tm_hour = 11; + date.tm_min = 0; + date.tm_sec = 0; + + /* compute number of seconds */ + secs = mktime (&date); + + secs += era * THIRTY_TWO_YEARS; + + result.tv_sec = secs; + result.tv_nsec = 0; + + return(result); +} + + void -xaccTransSetDate (Transaction *trans, int day, int mon, int year) -{ - struct tm date; - long long secs = 0; - long long era = 0; - - year -= 1900; - - /* make a crude attempt to deal with dates outside the - * range of Dec 1901 to Jan 2038. Note the we screw up - * centenial leap years here ... so hack alert -- - */ - if ((2 > year) || (136 < year)) - { - era = year / 32; - year %= 32; - if (0 > year) { year += 32; era -= 1; } - } - - date.tm_year = year; - date.tm_mon = mon - 1; - date.tm_mday = day; - date.tm_hour = 11; - date.tm_min = 0; - date.tm_sec = 0; - - /* compute number of seconds */ - secs = mktime (&date); - - secs += era * THIRTY_TWO_YEARS; - - xaccTransSetDateSecsL (trans, secs); +xaccTransSetDate (Transaction *trans, int day, int mon, int year) { + Timespec ts = gnc_dmy2timespec(day, mon, year); + xaccTransSetDateTS (trans, &ts); } void diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index dc34df623d..5e62947a21 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -140,6 +140,9 @@ void xaccTransBeginEdit (Transaction *, int defer); void xaccTransCommitEdit (Transaction *); void xaccTransRollbackEdit (Transaction *); +/* Convert a day, month, and year to a Timespec */ +Timespec gnc_dmy2timespec(int day, int month, int year); + /* * The xaccTransSetDateSecs() method will modify the posted date * of the transaction. (Footnote: this shouldn't matter to a user, @@ -161,10 +164,10 @@ void xaccTransRollbackEdit (Transaction *); void xaccTransSetDate (Transaction *, int day, int mon, int year); void xaccTransSetDateSecs (Transaction *, time_t); void xaccTransSetDateToday (Transaction *); -void xaccTransSetDateTS (Transaction *, Timespec *); +void xaccTransSetDateTS (Transaction *, const Timespec *); void xaccTransSetDateEnteredSecs (Transaction *, time_t); -void xaccTransSetDateEnteredTS (Transaction *, Timespec *); +void xaccTransSetDateEnteredTS (Transaction *, const Timespec *); /* set the Num and Description fields ... */