gnumeric r17239 - in trunk: . src



Author: mortenw
Date: Wed Mar 25 19:34:20 2009
New Revision: 17239
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17239&view=rev

Log:
2009-03-25  Morten Welinder  <terra gnome org>

	* src/gnm-format.c (gnm_format_is_time_for_value): Simplify.

	* src/stf-export.c (try_auto_date): Check validity of date.
	Handle elapsed times.  Sneakily also handle negative date serials
	if goffice does.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/README
   trunk/src/gnm-format.c
   trunk/src/stf-export.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Wed Mar 25 19:34:20 2009
@@ -1,5 +1,8 @@
 Gnumeric 1.9.6
 
+Morten:
+	* Handle elapsed time formats better on text export.
+
 --------------------------------------------------------------------------
 Gnumeric 1.9.5
 

Modified: trunk/README
==============================================================================
--- trunk/README	(original)
+++ trunk/README	Wed Mar 25 19:34:20 2009
@@ -17,7 +17,7 @@
 	glib		>= 2.10.0	libglib2.0-dev
 	gtk+		>= 2.12.0	libgtk2.0-dev
 	libgsf		>= 1.14.6	libgsf-1-dev
-	libgoffice	>= 0.7.4	libgoffice-0-5-dev
+	libgoffice	>= 0.7.5	libgoffice-0-5-dev
 	libglade	>= 2.3.6	libglade2-dev
 	gnome-xml   	>= 2.4.12	libxml2-dev
 	pango		>= 1.12.0	libpango1.0-dev

Modified: trunk/src/gnm-format.c
==============================================================================
--- trunk/src/gnm-format.c	(original)
+++ trunk/src/gnm-format.c	Wed Mar 25 19:34:20 2009
@@ -248,7 +248,7 @@
 	if (value)
 		fmt = gnm_format_specialize (fmt, value);
 
-	return (go_format_get_family (fmt) == GO_FORMAT_TIME);
+	return go_format_is_time (fmt);
 }
 
 int

Modified: trunk/src/stf-export.c
==============================================================================
--- trunk/src/stf-export.c	(original)
+++ trunk/src/stf-export.c	Wed Mar 25 19:34:20 2009
@@ -35,6 +35,7 @@
 #include "cell.h"
 #include "value.h"
 #include "gnm-format.h"
+#include "gnm-datetime.h"
 #include <gsf/gsf-output-iconv.h>
 #include <gsf/gsf-output-memory.h>
 #include <gsf/gsf-impl-utils.h>
@@ -145,29 +146,32 @@
 	GOFormat *actual;
 	char *res;
 	gboolean needs_date, needs_time, needs_frac_sec;
-	gboolean is_date, is_time;
+	gboolean is_date;
+	int is_time;
 	GString *xlfmt;
+	GDate date;
 
-	is_date = gnm_format_is_date_for_value (format, value) > 0;
-	is_time = gnm_format_is_time_for_value (format, value) > 0;
+	format = gnm_format_specialize (format, value);
+	is_date = go_format_is_date (format) > 0;
+	is_time = go_format_is_time (format);
 
-	if (!is_date && !is_time)
+	if (!is_date && is_time <= 0)
 		return NULL;
 
-	if (!VALUE_IS_NUMBER (value))
+	/* We don't want to coerce strings.  */
+	if (!VALUE_IS_FLOAT (value))
 		return NULL;
-	v = value_get_as_float (value);
-	if (v >= 2958466)
-		return NULL;  /* Year 10000 or beyond.  */
 
-#warning "We need to deal with this when fixing #509720"
-	if (v < 0)
+	/* Verify that the date is valid.  */
+	if (!datetime_value_to_g (&date, value, date_conv))
 		return NULL;
+
+	v = value_get_as_float (value);
 	vr = gnm_fake_round (v);
 	vs = (24 * 60 * 60) * gnm_abs (v - vr);
 
-	needs_date = is_date || v >= 1;
-	needs_time = is_time || gnm_abs (v - vr) > 1e-9;
+	needs_date = is_time < 2 && (is_date || gnm_abs (v) >= 1);
+	needs_time = is_time > 0 || gnm_abs (v - vr) > 1e-9;
 	needs_frac_sec = needs_time && gnm_abs (vs - gnm_fake_round (vs)) >= 0.5e-3;
 
 	xlfmt = g_string_new (NULL);
@@ -175,7 +179,10 @@
 	if (needs_time) {
 		if (needs_date)
 			g_string_append_c (xlfmt, ' ');
-		g_string_append (xlfmt, "hh:mm:ss");
+		if (is_time == 2)
+			g_string_append (xlfmt, "[h]:mm:ss");
+		else
+			g_string_append (xlfmt, "hh:mm:ss");
 		if (needs_frac_sec)
 			g_string_append (xlfmt, ".000");
 	}



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