extended date handling ...

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1460 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldfeatures/xacc-12-patch
Linas Vepstas 28 years ago
parent aa9f12b4b8
commit 6d25ae9dca

@ -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)
{

@ -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 *);

Loading…
Cancel
Save