gnumeric r16661 - in trunk: . plugins/fn-date



Author: mortenw
Date: Tue Jun 24 14:49:42 2008
New Revision: 16661
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16661&view=rev

Log:
2008-06-24  Morten Welinder  <terra gnome org>

	* functions.c (gnumeric_edate): Work around glib problem.  Fixes
	#539868.



Modified:
   trunk/NEWS
   trunk/plugins/fn-date/ChangeLog
   trunk/plugins/fn-date/functions.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Tue Jun 24 14:49:42 2008
@@ -51,6 +51,7 @@
 	* Plug leaks in GROWTH.  [#539827]
 	* Plug leak in NETWORKDAYS.
 	* Add missing "return" in CODE.
+	* Fix EDATE issue.  [#539868]
 
 SeÃn de BÃrca:
 	* Move to tango based icons. [#450444]

Modified: trunk/plugins/fn-date/functions.c
==============================================================================
--- trunk/plugins/fn-date/functions.c	(original)
+++ trunk/plugins/fn-date/functions.c	Tue Jun 24 14:49:42 2008
@@ -455,6 +455,7 @@
 	gnm_float serial = value_get_as_float (argv[0]);
 	gnm_float months = value_get_as_float (argv[1]);
 	GDate date;
+	int m, y;
 
 	if (serial < 0 || serial > INT_MAX)
                   return value_new_error_NUM (ei->pos);
@@ -465,10 +466,16 @@
 	if (!g_date_valid (&date))
                   return value_new_error_VALUE (ei->pos);
 
-	if (months > 0)
-		g_date_add_months (&date, (int)months);
+	m = (int)months;
+	y = g_date_get_year (&date) + m / 12;
+
+	/* Pretest for the benefit of #539868 */
+	if (y > 9999 || y < 1900)
+		g_date_clear (&date, 1);
+	else if (months > 0)
+		g_date_add_months (&date, m);
 	else
-		g_date_subtract_months (&date, (int)-months);
+		g_date_subtract_months (&date, -m);
 
 	if (!g_date_valid (&date) ||
 	    g_date_get_year (&date) < 1900 ||



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]