mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
changes from rob browning
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1708 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
935d2436f1
commit
ef9c6fbeff
@ -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
|
||||
|
@ -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 ... */
|
||||
|
Loading…
Reference in New Issue
Block a user