mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 672760 - Postponed transaction applied invalid date
Part 2: GDate can represent a wider range that GDateTime, so make sure that GDates outside of the range are clamped. The GDateTime range is 1 - 9999 CE, more than wide enough for most purposes. GDate can represent out to 65535CE, but the significant difference is that a freshly-cleared GDate is 0CE, which GDateTime won't accept. That we set to the Unix Epoch 0, 1970-Jan-1.
This commit is contained in:
@@ -422,6 +422,7 @@ gnc_difftime (const time64 secs1, const time64 secs2)
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
|
||||
GDateTime*
|
||||
gnc_g_date_time_new_from_timespec_local (Timespec ts)
|
||||
{
|
||||
@@ -646,6 +647,22 @@ int gnc_date_get_last_mday (int month, int year)
|
||||
return last_day_of_month[0][month-1];
|
||||
}
|
||||
|
||||
/* Safety function */
|
||||
static void
|
||||
gnc_gdate_range_check (GDate *gd)
|
||||
{
|
||||
int year;
|
||||
if (!g_date_valid (gd))
|
||||
{
|
||||
g_date_set_dmy (gd, 1, 1, 1970);
|
||||
return;
|
||||
}
|
||||
year = g_date_get_year (gd);
|
||||
// Adjust the GDate to fit in the range of GDateTime.
|
||||
year = (year < 1 ? 1 : year > 9999 ? 9999 : year);
|
||||
g_date_set_year (gd, year);
|
||||
return;
|
||||
}
|
||||
/* Return the set dateFormat.
|
||||
|
||||
return QofDateFormat: enumeration indicating preferred format
|
||||
@@ -873,10 +890,14 @@ qof_print_date_buff (char * buff, size_t len, time64 t)
|
||||
size_t
|
||||
qof_print_gdate( char *buf, size_t len, const GDate *gd )
|
||||
{
|
||||
GDate date;
|
||||
g_date_clear (&date, 1);
|
||||
date = *gd;
|
||||
gnc_gdate_range_check (&date);
|
||||
return qof_print_date_dmy_buff( buf, len,
|
||||
g_date_get_day(gd),
|
||||
g_date_get_month(gd),
|
||||
g_date_get_year(gd) );
|
||||
g_date_get_day(&date),
|
||||
g_date_get_month(&date),
|
||||
g_date_get_year(&date) );
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -1599,6 +1620,7 @@ GDate* gnc_g_date_new_today ()
|
||||
|
||||
Timespec gdate_to_timespec (GDate d)
|
||||
{
|
||||
gnc_gdate_range_check (&d);
|
||||
return gnc_dmy2timespec(g_date_get_day(&d),
|
||||
g_date_get_month(&d),
|
||||
g_date_get_year(&d));
|
||||
|
||||
Reference in New Issue
Block a user