From 6d25ae9dcac0d131f75e7d914e2dcf7db3fb2ff7 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 20 Dec 1998 20:23:28 +0000 Subject: [PATCH] extended date handling ... git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1460 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/datecell.c | 39 +++++++++++++++++++++++++++++++++++++++ src/register/datecell.h | 1 + 2 files changed, 40 insertions(+) diff --git a/src/register/datecell.c b/src/register/datecell.c index 311ee7a405..96aeb35b08 100644 --- a/src/register/datecell.c +++ b/src/register/datecell.c @@ -398,6 +398,45 @@ xaccSetDateCellValueSecs (DateCell *cell, time_t secs) /* ================================================ */ +#define THIRTY_TWO_YEARS 0x3c30fc00L + +void +xaccSetDateCellValueSecsL (DateCell *cell, long long secs) +{ + char buff[30]; + struct tm * stm; + + /* try to deal with dates earlier than December 1901 + * or later than Jan 2038. Note that this blows off + * centenial leap years. */ + if ((0x80000000L > secs) || (0x7fffffffL < secs)) + { + int yrs; + time_t rem; + rem = secs % THIRTY_TWO_YEARS; + yrs = secs / THIRTY_TWO_YEARS; + stm = localtime (&rem); + cell->date = *stm; + cell->date.tm_year += 32 * yrs; + } else { + /* OK, time value is an unsigned 32-bit int */ + time_t sicko; + sicko = secs; + stm = localtime (&sicko); + cell->date = *stm; + } + + printDate (buff, cell->date.tm_mday, + cell->date.tm_mon+1, + cell->date.tm_year+1900); + + if (cell->cell.value) free (cell->cell.value); + cell->cell.value = strdup (buff); + +} + +/* ================================================ */ + static void setDateCellValue (BasicCell *_cell, const char *str) { diff --git a/src/register/datecell.h b/src/register/datecell.h index ed839c93de..3903a9fb97 100644 --- a/src/register/datecell.h +++ b/src/register/datecell.h @@ -86,6 +86,7 @@ void xaccDestroyDateCell (DateCell *); void xaccSetDateCellValue (DateCell *, int day, int mon, int year); void xaccSetDateCellValueSecs (DateCell *, time_t secs); +void xaccSetDateCellValueSecsL (DateCell *, long long secs); void xaccCommitDateCell (DateCell *);