Commit ef126ae6 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder
Browse files

Improve Excel compatibility.

2006-01-26  Morten Welinder  <terra@gnome.org>

	* functions.c (gnumeric_date): Improve Excel compatibility.
parent 0d60023a
......@@ -40,6 +40,7 @@ Morten:
* Fix MID for out-of-bounds values.
* Fix constructed-range parsing for OO.
* Fix SECOND, MINUTE, HOUR compatibility problems.
* Fix DATE compatibility for bizarre input.
Jon Kåre:
* Hand clipboard off to clipboard manager when exiting.
......
2006-01-26 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_date): Improve Excel compatibility.
2006-01-24 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_second, gnumeric_minute, gnumeric_hour):
......
......@@ -107,37 +107,44 @@ static GnmFuncHelp const help_date[] = {
static GnmValue *
gnumeric_date (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int year, month, day;
gnm_float year = value_get_as_float (argv [0]);
gnm_float month = value_get_as_float (argv [1]);
gnm_float day = value_get_as_float (argv [2]);
GDate date;
GODateConventions const *conv = DATE_CONV (ei->pos);
year = value_get_as_int (argv [0]);
month = value_get_as_int (argv [1]);
day = value_get_as_int (argv [2]);
if (year < 0 || year > 9999)
if (year < 0 || year >= 10000)
goto error;
if (year < 1900) /* 1900, not 100. Ick! */
year += 1900;
/* This uses floor and not trunc on purpose. */
month = gnm_floor (month);
if (gnm_abs (month) > 120000) /* Actual number not critical. */
goto error;
/* This uses floor and not trunc on purpose. */
day = gnm_floor (day);
if (day < -32768 || day >= 32768)
day = 32767; /* Absurd, but yes. */
g_date_clear (&date, 1);
g_date_set_dmy (&date, 1, 1, year);
g_date_set_dmy (&date, 1, 1, (int)year);
if (!g_date_valid (&date))
goto error;
if (month > 0)
g_date_add_months (&date, month - 1);
if ((int)month > 0)
g_date_add_months (&date, (int)month - 1);
else
g_date_subtract_months (&date, 1 - month);
g_date_subtract_months (&date, 1 - (int)month);
if (!g_date_valid (&date))
goto error;
if (day > 0)
g_date_add_days (&date, day - 1);
if ((int)day > 0)
g_date_add_days (&date, (int)day - 1);
else
g_date_subtract_days (&date, 1 - day);
g_date_subtract_days (&date, 1 - (int)day);
if (!g_date_valid (&date))
goto error;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment