[gnumeric] WEEKNUM: make this compatible with xl for method 1 and 2.



commit 4b40bf63f39d587c0ea526ad150d40281573eb3f
Author: Morten Welinder <terra gnome org>
Date:   Thu Apr 22 14:28:14 2010 -0400

    WEEKNUM: make this compatible with xl for method 1 and 2.

 NEWS                        |    1 +
 plugins/fn-date/ChangeLog   |    4 ++++
 plugins/fn-date/functions.c |   19 ++++++++++++-------
 3 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index ba6afb6..4bd59c8 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ Jean
 Morten:
 	* Make sure an empty string is shown with a quote.
 	* Fix problem loading cells with empty strings.  [#616139]
+	* Fix WEEKNUM problems.  [#616330]
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.2
diff --git a/plugins/fn-date/ChangeLog b/plugins/fn-date/ChangeLog
index 3999d70..b09f4f7 100644
--- a/plugins/fn-date/ChangeLog
+++ b/plugins/fn-date/ChangeLog
@@ -1,3 +1,7 @@
+2010-04-22  Morten Welinder  <terra gnome org>
+
+	* functions.c (gnumeric_weeknum): Cleanup.  Doc fixes.
+
 2010-04-16  Morten Welinder <terra gnome org>
 
 	* Release 1.10.2
diff --git a/plugins/fn-date/functions.c b/plugins/fn-date/functions.c
index e7cdf43..3cef41f 100644
--- a/plugins/fn-date/functions.c
+++ b/plugins/fn-date/functions.c
@@ -1076,8 +1076,8 @@ static GnmFuncHelp const help_weeknum[] = {
         { GNM_FUNC_HELP_ARG, F_("date:date serial value")},
         { GNM_FUNC_HELP_ARG, F_("method:numbering system")},
 	{ GNM_FUNC_HELP_DESCRIPTION, F_("WEEKNUM calculates the week number according to @{method} which defaults to 1.") },
-	{ GNM_FUNC_HELP_NOTE, F_("If @{method} is 1, then weeks start on Sundays and days before first Sunday are in week 0.") },
-	{ GNM_FUNC_HELP_NOTE, F_("If @{method} is 2, then weeks start on Mondays and days before first Monday are in week 0.") },
+	{ GNM_FUNC_HELP_NOTE, F_("If @{method} is 1, then weeks start on Sundays and January 1 is in week 1.") },
+	{ GNM_FUNC_HELP_NOTE, F_("If @{method} is 2, then weeks start on Mondays and January 1 is in week 1.") },
 	{ GNM_FUNC_HELP_NOTE, F_("If @{method} is 150, then the ISO 8601 numbering is used.") },
         { GNM_FUNC_HELP_EXAMPLES, "=WEEKNUM(DATE(2000,1,1))" },
         { GNM_FUNC_HELP_EXAMPLES, "=WEEKNUM(DATE(2008,1,1))" },
@@ -1090,17 +1090,22 @@ gnumeric_weeknum (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 {
 	GDate date;
 	gnm_float method = argv[1] ? gnm_floor (value_get_as_float (argv[1])) : 1;
-
-	if (!(method == GO_WEEKNUM_METHOD_SUNDAY ||
-	      method == GO_WEEKNUM_METHOD_MONDAY ||
-	      method == GO_WEEKNUM_METHOD_ISO))
+	int m;
+
+	if (method == 1)
+		m = GO_WEEKNUM_METHOD_SUNDAY;
+	else if (method == 2)
+		m = GO_WEEKNUM_METHOD_MONDAY;
+	else if (method == 150 || method == 21)
+		m = GO_WEEKNUM_METHOD_ISO;
+	else
 		return value_new_error_VALUE (ei->pos);
 
 	datetime_value_to_g (&date, argv[0], DATE_CONV (ei->pos));
 	if (!g_date_valid (&date))
                   return value_new_error_VALUE (ei->pos);
 
-	return value_new_int (go_date_weeknum (&date, (int)method));
+	return value_new_int (go_date_weeknum (&date, m));
 }
 
 /***************************************************************************/



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