[gnumeric] Fix NETWORKDAYS with respect to 1900/2/29 and solver: fix problem with setting up the target entry d



commit 488a7234938c3796fbe02b2cb8a467fc114758e1
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Jul 4 10:21:35 2010 -0600

    Fix NETWORKDAYS with respect to 1900/2/29 and solver: fix problem with setting up the target entry differently.
    
    2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (gnumeric_networkdays): take care of 1900/2/29
    
    2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialog-solver.c (dialog_init): If we have no existing target we
    	should add the selection.

 plugins/fn-date/ChangeLog   |    4 ++++
 plugins/fn-date/functions.c |   23 +++++++++++++++++++----
 src/dialogs/ChangeLog       |    5 +++++
 src/dialogs/dialog-solver.c |    9 +++++++++
 4 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/plugins/fn-date/ChangeLog b/plugins/fn-date/ChangeLog
index 040ae51..b6f0cf1 100644
--- a/plugins/fn-date/ChangeLog
+++ b/plugins/fn-date/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* functions.c (gnumeric_networkdays): take care of 1900/2/29
+
 2010-07-03  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* functions.c (gnumeric_workday): take care of 1900/2/29
diff --git a/plugins/fn-date/functions.c b/plugins/fn-date/functions.c
index 452be86..5b9213b 100644
--- a/plugins/fn-date/functions.c
+++ b/plugins/fn-date/functions.c
@@ -963,9 +963,9 @@ static GnmValue *
 gnumeric_networkdays (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 {
 	int start_serial, old_start_serial;
-	int end_serial;
+	int end_serial, old_end_serial;
 	int res = 0;
-	GDate start_date;
+	GDate start_date, trouble;
 	GODateConventions const *conv = DATE_CONV (ei->pos);
 	gnm_float *holidays = NULL;
 	gnm_float *weekends = NULL;
@@ -991,6 +991,22 @@ gnumeric_networkdays (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	go_date_serial_to_g (&start_date, start_serial, conv);
 	if (!g_date_valid (&start_date))
 		goto bad;
+
+	old_end_serial = end_serial;
+	old_start_serial = start_serial;
+
+	g_date_set_dmy (&trouble, 1, 3, 1900);
+	if (g_date_compare (&start_date, &trouble) < 0) {
+		GDate end_date;
+		go_date_serial_to_g (&end_date, end_serial, conv);
+		g_date_set_dmy (&trouble, 28, 2, 1900);
+		if (!g_date_valid (&end_date) || g_date_compare (&trouble, &end_date) < 0) {
+			/* time period includes 1900/2/29 */
+			end_serial--;
+		}
+	}
+	
+
 	weekday = g_date_get_weekday (&start_date);
 
 	if (argv[3]) {
@@ -1055,7 +1071,6 @@ gnumeric_networkdays (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 		nholidays = 0;
 	}
 
-	old_start_serial = start_serial;
 	weeks = (end_serial - start_serial)/7;
 	start_serial = start_serial + weeks * 7;
 	res = weeks * n_non_weekend;
@@ -1070,7 +1085,7 @@ gnumeric_networkdays (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	 * we may have included holidays.
 	 */
 	
-	while (h < nholidays && holidays[h] <= end_serial) {
+	while (h < nholidays && holidays[h] <= old_end_serial) {
 		if (holidays[h] >= old_start_serial)
 			res--;
 		h++;
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 8842bf5..49cac1d 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,8 @@
+2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-solver.c (dialog_init): If we have no existing target we
+	should add the selection.
+	
 2010-07-04  Morten Welinder  <terra gnome org>
 
 	* dialog-solver.c (dialog_init): Don't add current selection to
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index e0bba77..df216fa 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -1128,6 +1128,15 @@ dialog_init (SolverState *state)
 	if (target_cell)
 		gnm_expr_entry_load_from_text (state->target_entry,
 					       cell_name (target_cell));
+	else {
+		GnmRange const*first = selection_first_range
+			(wb_control_cur_sheet_view
+			 (WORKBOOK_CONTROL (state->wbcg)), NULL, NULL);
+		if (first != NULL) {
+			gnm_expr_entry_load_from_range (state->target_entry,
+							state->sheet, first);
+		}
+	}
 
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
 		glade_xml_get_widget(state->gui, "max_button")),



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