goffice r2055 - in trunk: . goffice/utils



Author: mortenw
Date: Thu Apr 10 14:51:56 2008
New Revision: 2055
URL: http://svn.gnome.org/viewvc/goffice?rev=2055&view=rev

Log:
2008-04-10  Morten Welinder  <terra gnome org>

	* goffice/utils/datetime.c (go_date_conv_from_str,
	go_date_conv_equal, go_date_conv_translate): New functions.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/goffice/utils/datetime.c
   trunk/goffice/utils/datetime.h

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Thu Apr 10 14:51:56 2008
@@ -5,6 +5,7 @@
 
 Morten:
 	* Add go_format_is_invalid.
+	* Improve date convention framework.
 
 --------------------------------------------------------------------------
 goffice 0.6.2:

Modified: trunk/goffice/utils/datetime.c
==============================================================================
--- trunk/goffice/utils/datetime.c	(original)
+++ trunk/goffice/utils/datetime.c	Thu Apr 10 14:51:56 2008
@@ -11,6 +11,7 @@
 
 #include <goffice/goffice-config.h>
 #include "datetime.h"
+#include <goffice/math/go-math.h>
 
 #include <math.h>
 #include <string.h>
@@ -500,6 +501,56 @@
 	return conv->use_1904 ? 1904 : 1900;
 }
 
+const GODateConventions *
+go_date_conv_from_str (const char *s)
+{
+	static const GODateConventions apple1904 = { TRUE };
+	static const GODateConventions lotus1900 = { FALSE };
+
+	g_return_val_if_fail (s != NULL, NULL);
+
+	if (strcmp (s, "Apple:1904") == 0)
+		return &apple1904;
+
+	if (strcmp (s, "Lotus:1900") == 0)
+		return &lotus1900;
+
+	return NULL;
+}
+
+gboolean
+go_date_conv_equal (const GODateConventions *a, const GODateConventions *b)
+{
+	g_return_val_if_fail (a != NULL, FALSE);
+	g_return_val_if_fail (b != NULL, FALSE);
+
+	return a->use_1904 == b->use_1904;
+}
+
+double
+go_date_conv_translate (double f,
+			const GODateConventions *src,
+			const GODateConventions *dst)
+{
+	g_return_val_if_fail (src != NULL, f);
+	g_return_val_if_fail (dst != NULL, f);
+
+	if (!go_finite (f) || go_date_conv_equal (src, dst))
+		return f;
+
+	if (dst->use_1904) {
+		if (f < date_serial_19000228 + 1)
+			f += 1;
+		f -= 1462;
+	} else {
+		f += 1462;
+		if (f < date_serial_19000228 + 2)
+			f -= 1;
+	}
+
+	return f;
+}
+
 /* ------------------------------------------------------------------------- */
 
 static char *

Modified: trunk/goffice/utils/datetime.h
==============================================================================
--- trunk/goffice/utils/datetime.h	(original)
+++ trunk/goffice/utils/datetime.h	Thu Apr 10 14:51:56 2008
@@ -90,9 +90,16 @@
 
 int gnm_date_convention_base (GODateConventions const *conv);
 
+const GODateConventions *go_date_conv_from_str (const char *s);
+gboolean go_date_conv_equal (const GODateConventions *a, const GODateConventions *b);
+double go_date_conv_translate (double f,
+			       const GODateConventions *src,
+			       const GODateConventions *dst);
+
 char *go_date_weekday_name (GDateWeekday wd, gboolean abbrev);
 char *go_date_month_name (GDateMonth m, gboolean abbrev);
 
+
 G_END_DECLS
 
 #endif /* _GO_DATETIME_H_ */



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