gnumeric r17285 - in trunk: . src



Author: mortenw
Date: Thu Apr  2 14:23:11 2009
New Revision: 17285
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17285&view=rev

Log:
2009-04-02  Morten Welinder  <terra gnome org>

	* src/print-info.c (render_timestamp_with_format): Renamed form
	render_value_with_format.  Date convention issues fixed.

	* src/workbook.c (workbook_set_date_conv): New function.

	* src/xml-sax-read.c (xml_sax_calculation): Use
	workbook_set_date_conv.



Modified:
   trunk/ChangeLog
   trunk/src/print-info.c
   trunk/src/print-info.h
   trunk/src/workbook-priv.h
   trunk/src/workbook.c
   trunk/src/workbook.h
   trunk/src/xml-io.c
   trunk/src/xml-sax-read.c

Modified: trunk/src/print-info.c
==============================================================================
--- trunk/src/print-info.c	(original)
+++ trunk/src/print-info.c	Thu Apr  2 14:23:11 2009
@@ -506,13 +506,14 @@
 }
 
 static void
-render_value_with_format (GString *target, char const *number_format, HFRenderInfo *info)
+render_timestamp_with_format (GString *target, char const *number_format, HFRenderInfo *info)
 {
 	GOFormat *format;
 
-	/* TODO : Check this assumption.  Is it a localized format ?? */
+	/* TODO : Check this assumption.  Is it a localized format? */
 	format = go_format_new_from_XL (number_format);
-	format_value_gstring (target, format, info->date_time, NULL, -1, NULL);
+	format_value_gstring (target, format, info->date_time,
+			      NULL, -1, info->date_conv);
 	go_format_unref (format);
 }
 
@@ -526,7 +527,7 @@
 	else
 		date_format = "dd-mmm-yyyy";
 
-	render_value_with_format (target, date_format, info);
+	render_timestamp_with_format (target, date_format, info);
 }
 
 static void
@@ -538,7 +539,7 @@
 		time_format = args;
 	else
 		time_format = "hh:mm";
-	render_value_with_format (target, time_format, info);
+	render_timestamp_with_format (target, time_format, info);
 }
 
 static void
@@ -678,10 +679,11 @@
 	HFRenderInfo *hfi;
 
 	hfi = g_new0 (HFRenderInfo, 1);
-	hfi->date_time = value_new_float (
-		datetime_timet_to_serial_raw (time (NULL), NULL));
-#warning "FIXME: We cannot use NULL here."
-	range_init_full_sheet (&hfi->page_area, NULL);
+	hfi->date_conv = go_date_conv_from_str ("Lotus:1900");
+	hfi->date_time = value_new_float
+		(datetime_timet_to_serial_raw (time (NULL), hfi->date_conv));
+	/* It doesn't appear like the end is accessed.  */
+	range_init (&hfi->page_area, 0, 0, G_MAXINT / 2, G_MAXINT / 2);
 	hfi->top_repeating.col = 0;
 	hfi->top_repeating.row = 0;
 

Modified: trunk/src/print-info.h
==============================================================================
--- trunk/src/print-info.h	(original)
+++ trunk/src/print-info.h	Thu Apr  2 14:23:11 2009
@@ -111,6 +111,7 @@
 	int       page;
 	int       pages;
 	GnmValue *date_time;
+	GODateConventions const *date_conv;
 	GnmRange  page_area;
 	GnmCellPos top_repeating;
 } HFRenderInfo;

Modified: trunk/src/workbook-priv.h
==============================================================================
--- trunk/src/workbook-priv.h	(original)
+++ trunk/src/workbook-priv.h	Thu Apr  2 14:23:11 2009
@@ -37,7 +37,7 @@
 		double   tolerance;
 	} iteration;
 	gboolean recalc_auto;
-	GODateConventions date_conv;
+	GODateConventions const *date_conv;
 
 	gboolean during_destruction;
 	gboolean being_reordered;

Modified: trunk/src/workbook.c
==============================================================================
--- trunk/src/workbook.c	(original)
+++ trunk/src/workbook.c	Thu Apr  2 14:23:11 2009
@@ -177,7 +177,7 @@
 	wb->iteration.tolerance = .001;
 	wb->recalc_auto = TRUE;
 
-	wb->date_conv.use_1904 = FALSE;
+	workbook_set_1904 (wb, FALSE);
 
 	wb->file_format_level = FILE_FL_NEW;
 	wb->file_saver        = NULL;
@@ -1134,42 +1134,43 @@
 }
 
 /**
- * workbook_uses_1904 :
- * @wb :
+ * workbook_date_conv :
+ * @wb : Workbook
  *
- * Does @wb use the 1904 date convention ?  This could be expanded to return a
- * locale-ish type object to get passed around.  However, since we use libc for
- * some of the formatting and parsing we can not get around setting the actual
- * locale globally and there is not much that I can think of to put in here for
- * now.  Hence I'll leave it as a boolean.
+ * Returns: the date convention in effect for the workbook.
  **/
 GODateConventions const *
 workbook_date_conv (Workbook const *wb)
 {
 	g_return_val_if_fail (wb != NULL, NULL);
-	return &wb->date_conv;
+	return wb->date_conv;
 }
 
 /**
- * workbook_set_1904 :
- * @wb :
- * @flag : new value
+ * workbook_set_date_conv :
+ * @wb : worknook
+ * @date_conv : new date convention
  *
- * Sets the 1904 flag to @flag and returns the old value.
+ * Sets the date convention @date_conv.
  * NOTE : THIS IS NOT A SMART ROUTINE.  If you want to actually change this
  * We'll need to recalc and rerender everything.  That will need to be done
  * externally.
  **/
-gboolean
-workbook_set_1904 (Workbook *wb, gboolean flag)
+void
+workbook_set_date_conv (Workbook *wb, GODateConventions const *date_conv)
 {
-	gboolean old_val;
+	g_return_if_fail (IS_WORKBOOK (wb));
+	g_return_if_fail (date_conv != NULL);
 
-	g_return_val_if_fail (IS_WORKBOOK (wb), FALSE);
+	wb->date_conv = date_conv;
+}
 
-	old_val = wb->date_conv.use_1904;
-	wb->date_conv.use_1904 = flag;
-	return old_val;
+void
+workbook_set_1904 (Workbook *wb, gboolean base1904)
+{
+	GODateConventions const *date_conv =
+		go_date_conv_from_str (base1904 ? "Apple:1904" : "Lotus:1900");
+	workbook_set_date_conv (wb, date_conv);
 }
 
 /* ------------------------------------------------------------------------- */

Modified: trunk/src/workbook.h
==============================================================================
--- trunk/src/workbook.h	(original)
+++ trunk/src/workbook.h	Thu Apr  2 14:23:11 2009
@@ -73,7 +73,8 @@
 void     workbook_iteration_tolerance	 (Workbook *wb, double tolerance);
 
 GODateConventions const *workbook_date_conv (Workbook const *wb);
-gboolean workbook_set_1904 (Workbook *wb, gboolean flag);
+void workbook_set_date_conv (Workbook *wb, GODateConventions const *date_conv);
+void workbook_set_1904 (Workbook *wb, gboolean base1904);
 
 void workbook_attach_view (WorkbookView *wbv);
 void workbook_detach_view (WorkbookView *wbv);

Modified: trunk/src/xml-io.c
==============================================================================
--- trunk/src/xml-io.c	(original)
+++ trunk/src/xml-io.c	Thu Apr  2 14:23:11 2009
@@ -2453,8 +2453,12 @@
 		if (xml_node_get_double (child, "IterationTolerance", &d))
 			workbook_iteration_tolerance (ctxt->wb, d);
 		if (NULL != (str = xml_node_get_cstr (child, "DateConvention"))) {
-			workbook_set_1904 (ctxt->wb,
-				strcmp (str, "Apple:1904") == 0);
+			GODateConventions const *date_conv =
+				go_date_conv_from_str (CXML2C (str));
+			if (date_conv)
+				workbook_set_date_conv (ctxt->wb, date_conv);
+			else
+				g_printerr ("Ignoring invalid date conventions.\n");
 			xmlFree (str);
 		}
 	}

Modified: trunk/src/xml-sax-read.c
==============================================================================
--- trunk/src/xml-sax-read.c	(original)
+++ trunk/src/xml-sax-read.c	Thu Apr  2 14:23:11 2009
@@ -65,6 +65,7 @@
 #include <goffice/app/error-info.h>
 #include <goffice/utils/go-glib-extras.h>
 #include <goffice/utils/go-format.h>
+#include <goffice/utils/datetime.h>
 
 #include <gsf/gsf-libxml.h>
 #include <gsf/gsf-input.h>
@@ -543,8 +544,12 @@
 		else if (gnm_xml_attr_double (attrs, "IterationTolerance", &d))
 			workbook_iteration_tolerance (state->wb, d);
 		else if (strcmp (CXML2C (attrs[0]), "DateConvention") == 0) {
-			workbook_set_1904 (state->wb,
-				strcmp (attrs[1], "Apple:1904") == 0);
+			GODateConventions const *date_conv =
+				go_date_conv_from_str (CXML2C (attrs[1]));
+			if (date_conv)
+				workbook_set_date_conv (state->wb, date_conv);
+			else
+				g_printerr ("Ignoring invalid date conventions.\n");
 		} else
 			unknown_attr (xin, attrs);
 }



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