add date cell set value method

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@471 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-01-31 18:23:02 +00:00
parent 547efd820b
commit 1eb7c9df08
2 changed files with 57 additions and 25 deletions

View File

@ -236,9 +236,9 @@ DateMV (struct _BasicCell *_cell,
xaccValidateDate (date, 0);
}
sprintf (buff, "%d/%d/%d", date->tm_mday,
date->tm_mon+1,
date->tm_year+1900);
sprintf (buff, "%2d/%2d/%4d", date->tm_mday,
date->tm_mon+1,
date->tm_year+1900);
xaccSetBasicCellValue (&(cell->cell), buff);
datestr = strdup (buff);
@ -259,10 +259,11 @@ DateLeave (struct _BasicCell *_cell, const char * curr)
* what date that cell thinks it has. */
xaccParseDate (&(cell->date), curr);
sprintf (buff, "%d/%d/%d", cell->date.tm_mday,
cell->date.tm_mon+1,
cell->date.tm_year+1900);
sprintf (buff, "%2d/%2d/%4d", cell->date.tm_mday,
cell->date.tm_mon+1,
cell->date.tm_year+1900);
xaccSetBasicCellValue (&(cell->cell), buff);
retval = strdup (buff);
return retval;
}
@ -283,24 +284,41 @@ xaccMallocDateCell (void)
void
xaccInitDateCell (DateCell *cell)
{
time_t secs;
struct tm *now;
char buff[30];
time_t secs;
struct tm *now;
char buff[30];
xaccInitBasicCell (&(cell->cell));
xaccInitBasicCell (&(cell->cell));
/* default value is today's date */
time (&secs);
now = localtime (&secs);
cell->date = *now;
sprintf (buff, "%d/%d/%d", now->tm_mday, now->tm_mon+1, now->tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
cell->cell.enter_cell = DateEnter;
cell->cell.modify_verify = DateMV;
cell->cell.leave_cell = DateLeave;
/* default value is today's date */
time (&secs);
now = localtime (&secs);
cell->date = *now;
sprintf (buff, "%2d/%2d/%4d", now->tm_mday, now->tm_mon+1, now->tm_year+1900);
xaccSetBasicCellValue (&(cell->cell), buff);
cell->cell.enter_cell = DateEnter;
cell->cell.modify_verify = DateMV;
cell->cell.leave_cell = DateLeave;
}
/* --------------- end of file ---------------------- */
/* ================================================ */
void
xaccSetDateCellValue (DateCell *cell, int day, int mon, int year)
{
struct tm dada;
char buff[30];
dada.tm_mday = day;
dada.tm_mon = mon-1;
dada.tm_year = year - 1900;
xaccValidateDate (&dada, 0);
sprintf (buff, "%2d/%2d/%4d", dada.tm_mday, dada.tm_mon+1, dada.tm_year+1900);
xaccSetBasicCellValue (&(cell->cell), buff);
}
/* ============== END OF FILE ===================== */

View File

@ -1,4 +1,16 @@
/*
* FILE:
* datecell.h
*
* FUNCTION:
* Implements date handling
*
* The xaccSetDateCellValue() method accepts a numeric date and
* sets the contents of the date cell to that value. The
* value day, month, year should follow the regular written
* conventions, i.e. day==(1..31), mon==(1..12), year==4 digits
*/
#ifndef __XACC_DATE_CELL_C__
#define __XACC_DATE_CELL_C__
@ -12,7 +24,9 @@ typedef struct _DateCell {
/* installs a callback to handle date recording */
DateCell * xaccMallocDateCell (void);
void xaccInitDateCell (DateCell *);
void xaccInitDateCell (DateCell *);
void xaccSetDateCellValue (DateCell *, int day, int mon, int year);
#endif /* __XACC_DATE_CELL_C__ */