Re: [evolution-patches] Re: 43485: strftime usage in e-cell-date



On Fri, 2003-05-23 at 14:11, Jeffrey Stedfast wrote:

> > But since this is a function scope stack variable and memory is cheap,
> > if 26 is marginal, perhaps I should just bump it to 100 and avoid any
> > risk?
> 
> sure, sounds good to me.

So after a big discussion on irc, the patch is growing...

This adds new utf8-friendly api to gal and uses it in e-cell-date.  The
mailer and addrbook need to be updated to use the new funcs.  The
calendar currently uses g_date_strftime, which apparently ignores any
time formatters in the fmt string, so if calendar needs to show time, it
needs to use this too, probably.

Mike
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gal/ChangeLog,v
retrieving revision 1.780
diff -u -p -r1.780 ChangeLog
--- ChangeLog	21 May 2003 16:26:15 -0000	1.780
+++ ChangeLog	23 May 2003 20:58:25 -0000
@@ -1,3 +1,9 @@
+2003-05-23  Mike Kestner  <mkestner ximian com>
+
+	* configure.in : bump libtool version for api addition
+	* gal/util/e-util.c (e_utf8_strftime): new, utf8 in/out
+	(e_utf8_strftime_fix_am_pm): new, utf8 in/out
+
 2003-05-21  Mike Kestner  <mkestner ximian com>
 
 	* configure.in : releasing 1.99.6
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gal/configure.in,v
retrieving revision 1.264
diff -u -p -r1.264 configure.in
--- configure.in	21 May 2003 16:28:12 -0000	1.264
+++ configure.in	23 May 2003 20:58:25 -0000
@@ -21,20 +21,20 @@ GAL_API_VERSION=2.0
 
 dnl libtool versioning
 
-dnl gal-1.99.6 = 0
+dnl gal-1.99.7 = 1
 dnl increment if any interfaces have been added; set to 0
 dnl  if any interfaces have been removed. removal has 
 dnl  precedence over adding, so set to 0 if both happened.
-GAL_AGE=0
+GAL_AGE=1
 
-dnl gal-1.99.6 = 1
+dnl gal-1.99.7 = 0
 dnl increment any time the source changes; set to 
 dnl  0 if you increment CURRENT
-GAL_REVISION=1
+GAL_REVISION=0
 
-dnl gal-1.99.6 = 3
+dnl gal-1.99.7 = 4
 dnl increment if the interface has additions, changes, removals.
-GAL_CURRENT=3
+GAL_CURRENT=4
 
 AC_SUBST(GAL_API_VERSION)
 AC_SUBST(GAL_CURRENT)
Index: gal/util/e-util.c
===================================================================
RCS file: /cvs/gnome/gal/gal/util/e-util.c,v
retrieving revision 1.58
diff -u -p -r1.58 e-util.c
--- gal/util/e-util.c	8 May 2003 14:58:57 -0000	1.58
+++ gal/util/e-util.c	23 May 2003 20:58:26 -0000
@@ -768,6 +768,18 @@ size_t e_strftime(char *s, size_t max, c
 #endif
 }
 
+size_t 
+e_utf8_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+	size_t sz;
+	char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+	size_t ret = e_strftime(s, max, locale_fmt, tm);
+	char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+	memmove(s, buf, sz);
+	g_free(locale_fmt);
+	g_free(buf);
+	return sz;
+}
 
 /**
  * Function to do a last minute fixup of the AM/PM stuff if the locale
@@ -828,6 +840,19 @@ size_t e_strftime_fix_am_pm(char *s, siz
 		}
 	}
 	return(ret);
+}
+
+size_t 
+e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+	size_t sz;
+	char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+	size_t ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
+	char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+	memmove(s, buf, sz);
+	g_free(locale_fmt);
+	g_free(buf);
+	return sz;
 }
 
 /**
Index: gal/util/e-util.h
===================================================================
RCS file: /cvs/gnome/gal/gal/util/e-util.h,v
retrieving revision 1.54
diff -u -p -r1.54 e-util.h
--- gal/util/e-util.h	5 Dec 2002 18:31:30 -0000	1.54
+++ gal/util/e-util.h	23 May 2003 20:58:26 -0000
@@ -196,6 +196,16 @@ size_t   e_strftime		(char              
 				 const char        *fmt,
 				 const struct tm   *tm);
 
+size_t   e_utf8_strftime_fix_am_pm  (char             *s,
+				     size_t            max,
+				     const char       *fmt,
+				     const struct tm  *tm);
+
+size_t   e_utf8_strftime	(char              *s,
+				 size_t             max,
+				 const char        *fmt,
+				 const struct tm   *tm);
+
 /* String to/from double conversion functions */
 gdouble   e_flexible_strtod     (const gchar       *nptr,
 				 gchar            **endptr);
Index: gal/e-table/ChangeLog
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/ChangeLog,v
retrieving revision 1.901
diff -u -p -r1.901 ChangeLog
--- gal/e-table/ChangeLog	21 May 2003 16:02:59 -0000	1.901
+++ gal/e-table/ChangeLog	23 May 2003 20:58:32 -0000
@@ -1,3 +1,8 @@
+2003-05-23  Mike Kestner  <mkestner ximian com>
+
+	* e-cell-date.c (ecd_get_text): use e_utf8_strftime_fix_am_pm
+	and remove locale to utf8 conversion at end.  [43485]
+
 2003-05-20  Ettore Perazzoli  <ettore ximian com>
 
 	* e-tree.c (tree_canvas_size_allocate): to really fix 42952
Index: gal/e-table/e-cell-date.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-cell-date.c,v
retrieving revision 1.13
diff -u -p -r1.13 e-cell-date.c
--- gal/e-table/e-cell-date.c	18 Mar 2003 20:49:59 -0000	1.13
+++ gal/e-table/e-cell-date.c	23 May 2003 20:58:32 -0000
@@ -43,8 +43,8 @@ ecd_get_text(ECellText *cell, ETableMode
 	time_t nowdate = time(NULL);
 	time_t yesdate;
 	struct tm then, now, yesterday;
-	char buf[26];
-	char *temp, *ret_val;
+	char buf[100];
+	char *temp;
 	gboolean done = FALSE;
 
 	if (date == 0) {
@@ -55,7 +55,7 @@ ecd_get_text(ECellText *cell, ETableMode
 	localtime_r (&nowdate, &now);
 
 	if (nowdate - date < 60 * 60 * 8 && nowdate > date) {
-		e_strftime_fix_am_pm (buf, 26, _("%l:%M %p"), &then);
+		e_utf8_strftime_fix_am_pm (buf, 100, _("%l:%M %p"), &then);
 		done = TRUE;
 	}
 
@@ -63,7 +63,7 @@ ecd_get_text(ECellText *cell, ETableMode
 		if (then.tm_mday == now.tm_mday &&
 		    then.tm_mon == now.tm_mon &&
 		    then.tm_year == now.tm_year) {
-			e_strftime_fix_am_pm (buf, 26, _("Today %l:%M %p"), &then);
+			e_utf8_strftime_fix_am_pm (buf, 100, _("Today %l:%M %p"), &then);
 			done = TRUE;
 		}
 	}
@@ -73,15 +73,7 @@ ecd_get_text(ECellText *cell, ETableMode
 		if (then.tm_mday == yesterday.tm_mday &&
 		    then.tm_mon == yesterday.tm_mon &&
 		    then.tm_year == yesterday.tm_year) {
-#if 0
-			if (nowdate - date < 60 * 60 * 12) {
-				e_strftime_fix_am_pm (buf, 26, _("Late Yesterday %l:%M %p"), &then);
-			} else {
-#endif
-				e_strftime_fix_am_pm (buf, 26, _("Yesterday %l:%M %p"), &then);
-#if 0
-			}
-#endif
+			e_utf8_strftime_fix_am_pm (buf, 100, _("Yesterday %l:%M %p"), &then);
 			done = TRUE;
 		}
 	}
@@ -93,7 +85,7 @@ ecd_get_text(ECellText *cell, ETableMode
 			if (then.tm_mday == yesterday.tm_mday &&
 			    then.tm_mon == yesterday.tm_mon &&
 			    then.tm_year == yesterday.tm_year) {
-				e_strftime_fix_am_pm (buf, 26, _("%a %l:%M %p"), &then);
+				e_utf8_strftime_fix_am_pm (buf, 100, _("%a %l:%M %p"), &then);
 				done = TRUE;
 				break;
 			}
@@ -101,26 +93,17 @@ ecd_get_text(ECellText *cell, ETableMode
 	}
 	if (!done) {
 		if (then.tm_year == now.tm_year) {
-			e_strftime_fix_am_pm (buf, 26, _("%b %d %l:%M %p"), &then);
+			e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %l:%M %p"), &then);
 		} else {
-			e_strftime_fix_am_pm (buf, 26, _("%b %d %Y"), &then);
+			e_utf8_strftime_fix_am_pm (buf, 100, _("%b %d %Y"), &then);
 		}
 	}
-#if 0
-#ifdef CTIME_R_THREE_ARGS
-	ctime_r (&date, buf, 26);
-#else
-	ctime_r (&date, buf);
-#endif
-#endif
 	temp = buf;
 	while ((temp = strstr (temp, "  "))) {
 		memmove (temp, temp + 1, strlen (temp));
 	}
 	temp = e_strdup_strip (buf);
-	ret_val = e_utf8_from_locale_string (temp);
-	g_free (temp);
-	return ret_val;
+	return temp;
 }
 
 static void


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