[gnumeric] Add ODF compatibility function DAYS & Work around OpenOffice.org saving function names in lowercase.



commit dccc9f1a4ef16c52a4a547aa1dd9a941ab3b362e
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri Oct 23 23:14:02 2009 -0600

    Add ODF compatibility function DAYS & Work around OpenOffice.org saving function names in lowercase.
    
    2009-10-23  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_func_map_in): add EASTERSUNDAY
    	  and DAYS. Use case insensitive comparison for prefixes since
    	  OOo saves unknown functions in lower case.
    	* openoffice-write.c (odf_func_eastersunday_handler): new
    	(odf_expr_func_handler): add odf_func_eastersunday_handler and
    	  DAYS translation
    
    2009-10-23  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (gnumeric_days): new
    	(help_days): new
    	* plugin.xml.in: add DAYS

 NEWS                                  |    2 +
 plugins/fn-date/ChangeLog             |    6 +++++
 plugins/fn-date/functions.c           |   36 +++++++++++++++++++++++++++++++++
 plugins/fn-date/plugin.xml.in         |    1 +
 plugins/openoffice/ChangeLog          |    9 ++++++++
 plugins/openoffice/openoffice-read.c  |    7 +++--
 plugins/openoffice/openoffice-write.c |   18 +++++++++++++++-
 7 files changed, 75 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index da0f1ea..e8c348b 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ Andreas:
 	* Add R.PSNORM, R.DSNORM and R.DST.
 	* Fix small sort dialog problem. [#599091]
 	* A few functions from the christian liturgical calendar.
+	* Add ODF compatibility function DAYS.
+	* Work around OpenOffice.org saving function names in lowercase.
 
 Jody:
 	* First steps towards a turnkey win32 build.
diff --git a/plugins/fn-date/ChangeLog b/plugins/fn-date/ChangeLog
index 52c33b6..ee4c573 100644
--- a/plugins/fn-date/ChangeLog
+++ b/plugins/fn-date/ChangeLog
@@ -1,3 +1,9 @@
+2009-10-23  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* functions.c (gnumeric_days): new
+	(help_days): new
+	* plugin.xml.in: add DAYS
+
 2009-10-23  Morten Welinder  <terra gnome org>
 
 	* functions.c (gnumeric_date): Improve support for pre-1900 dates
diff --git a/plugins/fn-date/functions.c b/plugins/fn-date/functions.c
index 3703a2f..19de7b4 100644
--- a/plugins/fn-date/functions.c
+++ b/plugins/fn-date/functions.c
@@ -1133,6 +1133,38 @@ gnumeric_yearfrac (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_days[] = {
+        { GNM_FUNC_HELP_NAME, F_("DAYS:difference between dates in days") },
+        { GNM_FUNC_HELP_ARG, F_("start_date:starting date serial value")},
+        { GNM_FUNC_HELP_ARG, F_("end_date:ending date serial value")},
+	{ GNM_FUNC_HELP_DESCRIPTION, F_("DAYS returns the positive or negative number of days from @{start_date} to @{end_date}.") },
+	{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") },
+        { GNM_FUNC_HELP_EXAMPLES, "=DAYS(DATE(2003,2,3),DATE(2007,4,2))" },
+	{ GNM_FUNC_HELP_EXAMPLES, "=DAYS(DATE(2007,4,2),DATE(2003,2,3))" },
+	{ GNM_FUNC_HELP_EXAMPLES, "=DAYS(DATE(1900,2,28),DATE(1900,3,1))" },
+        { GNM_FUNC_HELP_SEEALSO, "DATEDIF"},
+	{ GNM_FUNC_HELP_END }
+};
+
+
+static GnmValue *
+gnumeric_days (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	int date1, date2;
+	GDate d1, d2;
+	GODateConventions const *conv = DATE_CONV (ei->pos);
+
+	date1 = gnm_floor (value_get_as_float (argv [0]));
+	date2 = gnm_floor (value_get_as_float (argv [1]));
+
+	go_date_serial_to_g (&d1, date1, conv);
+	go_date_serial_to_g (&d2, date2, conv);	
+
+	return value_new_int (g_date_days_between (&d1, &d2));
+}
+
+/***************************************************************************/
+
 GnmFuncDescriptor const datetime_functions[] = {
 	{ "date",        "fff",   help_date,
 	  gnumeric_date, NULL, NULL, NULL, NULL,
@@ -1235,5 +1267,9 @@ GnmFuncDescriptor const datetime_functions[] = {
 	  gnumeric_isoyear, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_UNITLESS,
 	  GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+	{ "days", "ff",
+	  help_days, gnumeric_days, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_UNITLESS,
+	  GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
         {NULL}
 };
diff --git a/plugins/fn-date/plugin.xml.in b/plugins/fn-date/plugin.xml.in
index ad18264..b20dd2b 100644
--- a/plugins/fn-date/plugin.xml.in
+++ b/plugins/fn-date/plugin.xml.in
@@ -17,6 +17,7 @@
 				<function name="datevalue"/>
 				<function name="datedif"/>
 				<function name="day"/>
+				<function name="days"/>
 				<function name="days360"/>
 				<function name="edate"/>
 				<function name="eomonth"/>
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index adee994..8ab4729 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,12 @@
+2009-10-23  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_func_map_in): add EASTERSUNDAY
+	  and DAYS. Use case insensitive comparison for prefixes since
+	  OOo saves unknown functions in lower case.
+	* openoffice-write.c (odf_func_eastersunday_handler): new
+	(odf_expr_func_handler): add odf_func_eastersunday_handler and
+	  DAYS translation
+
 2009-10-11  Morten Welinder <terra gnome org>
 
 	* Release 1.9.14
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 1bf4e45..65a14d1 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -4649,6 +4649,8 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 		{ "INDIRECT_XL",	"INDIRECT" },
 		{ "ADDRESS_XL",		"ADDRESS" },
 		{ "ERRORTYPE",		"ERROR.TYPE" },
+		{ "EASTERSUNDAY",	"EASTERSUNDAY" }, /* OOo stores this without prefix! */
+		{ "ORG.OPENOFFICE.EASTERSUNDAY",	"EASTERSUNDAY" },
 
 /* The following is a list of the functions defined in ODF OpenFormula draft 20090508 */
 /* where we do not have a function with the same name                                 */
@@ -4658,7 +4660,6 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 		{ "B","ODF.B" },
 		{ "COMBINA","ODF.COMBINA" },
 		{ "COUNTIFS","ODF.COUNTIFS" },
-		{ "DAYS","ODF.DAYS" },
 		{ "DDE","ODF.DDE" },
 		{ "IFNA","ODF.IFNA" },
 		{ "ISFORMULA","ODF.ISFORMULA" },
@@ -5099,9 +5100,9 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 			return res;
 	}
 
-	if (0 == strncmp (name, GnumericPrefix, sizeof (GnumericPrefix)-1)) {
+	if (0 == g_ascii_strncasecmp (name, GnumericPrefix, sizeof (GnumericPrefix)-1)) {
 		f = gnm_func_lookup_or_add_placeholder (name+sizeof (GnumericPrefix)-1, scope, TRUE);
-	} else if (0 != strncmp (name, OOoAnalysisPrefix, sizeof (OOoAnalysisPrefix)-1)) {
+	} else if (0 != g_ascii_strncasecmp (name, OOoAnalysisPrefix, sizeof (OOoAnalysisPrefix)-1)) {
 		if (NULL != namemap &&
 		    NULL != (new_name = g_hash_table_lookup (namemap, name)))
 			name = new_name;
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index b6a5a8f..fbe3f2f 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1533,6 +1533,21 @@ odf_func_sech_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 }
 
 
+static gboolean
+odf_func_eastersunday_handler (GnmConventionsOut *out, GnmExprFunction const *func)
+{
+	if (func->argc == 1) {
+		GString *target = out->accum;
+		GnmExprConstPtr const *ptr = func->argv;
+/* OOo incorrectly stores this without an ORG.OPENOFFICE. prefix. */
+		g_string_append (target, "EASTERSUNDAY(");
+		gnm_expr_as_gstring (ptr[0], out);
+		g_string_append (out->accum, ")");
+		return TRUE;
+	}
+	return FALSE;
+}
+
 static void
 odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 {
@@ -1547,6 +1562,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 			{"R.PCHISQ", odf_func_r_pchisq_handler},
 			{"SEC",      odf_func_sec_handler},
 			{"SECH",      odf_func_sech_handler},
+			{"EASTERSUNDAY", odf_func_eastersunday_handler},
 			{NULL, NULL}
 	};
 
@@ -1647,7 +1663,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "DATEVALUE","DATEVALUE" },
 		{ "DAVERAGE","DAVERAGE" },
 		{ "DAY","DAY" },
-		/* { "DAYS","DAYS" },  not implemented */
+		{ "DAYS","DAYS" },
 		{ "DAYS360","DAYS360" },
 		{ "DB","DB" },
 		{ "DCOUNT","DCOUNT" },



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