From de92dc7ef04c889a046e5e93d3b40e04bf7fd7b1 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 20 Dec 1998 20:44:08 +0000 Subject: [PATCH] fixes for date handling git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1462 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Transaction.c | 24 +++++++++++++++++++++--- src/engine/Transaction.h | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 42614c6346..cd260e3151 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1511,13 +1511,29 @@ xaccTransSetDateEnteredTS (Transaction *trans, Timespec *ts) trans->date_entered.tv_nsec = ts->tv_nsec; } +#define THIRTY_TWO_YEARS 0x3c30fc00L + void xaccTransSetDate (Transaction *trans, int day, int mon, int year) { struct tm date; - time_t secs; + long long secs; + long long era = 0; + + year -= 1900; - date.tm_year = 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; @@ -1527,7 +1543,9 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year) /* compute number of seconds */ secs = mktime (&date); - xaccTransSetDateSecs (trans, secs); + secs += era * THIRTY_TWO_YEARS; + + xaccTransSetDateSecsL (trans, secs); } void diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index bb30b7cb88..b0de2f4f2f 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -204,7 +204,9 @@ char * xaccTransGetNum (Transaction *); char * xaccTransGetDescription (Transaction *); char * xaccTransGetDocref (Transaction *); time_t xaccTransGetDate (Transaction *); +#ifndef SWIG /* swig chokes on long long */ long long xaccTransGetDateL (Transaction *); +#endif void xaccTransGetDateTS (Transaction *, Timespec *); void xaccTransGetDateEnteredTS (Transaction *, Timespec *);