gnumeric r17207 - in trunk: . src
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r17207 - in trunk: . src
- Date: Sat, 14 Mar 2009 22:44:12 +0000 (UTC)
Author: mortenw
Date: Sat Mar 14 22:44:12 2009
New Revision: 17207
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17207&view=rev
Log:
2009-03-14 Morten Welinder <terra gnome org>
* src/gnm-format.c (gnm_format_frob_slashes): Import from
number-match and make public. Rename from frob_slashes. All
callers changed.
(gnm_format_for_date_editing): Change slashes to whatever the
locale uses.
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/src/gnm-format.c
trunk/src/gnm-format.h
trunk/src/number-match.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Sat Mar 14 22:44:12 2009
@@ -32,6 +32,7 @@
[Part of #364291]
* Fix lotus importer crash. [#575190]
* Improve entry of date for locales not using slashes. [Part of #33229]
+ * Make date edit use the date separator of the locale. [Part of #33229]
* Fix xls writing crash. [Part of #575318]
* Fix criticals in xls export for comments without author.
Modified: trunk/src/gnm-format.c
==============================================================================
--- trunk/src/gnm-format.c (original)
+++ trunk/src/gnm-format.c Sat Mar 14 22:44:12 2009
@@ -270,17 +270,76 @@
GOFormat *
gnm_format_for_date_editing (GnmCell const *cell)
{
+ char *fmttxt;
+ GOFormat *fmt;
int mbd = cell
? gnm_format_month_before_day (gnm_cell_get_format (cell),
cell->value)
: go_locale_month_before_day ();
switch (mbd) {
- case 0: return go_format_new_from_XL ("d/m/yyyy");
+ case 0:
+ fmttxt = gnm_format_frob_slashes ("d/m/yyyy");
+ break;
default:
- case 1: return go_format_new_from_XL ("m/d/yyyy");
- case 2: return go_format_new_from_XL ("yyyy-m-d");
+ case 1:
+ fmttxt = gnm_format_frob_slashes ("m/d/yyyy");
+ break;
+ case 2:
+ fmttxt = gnm_format_frob_slashes ("yyyy-m-d");
+ break;
}
+
+ fmt = go_format_new_from_XL (fmttxt);
+ g_free (fmttxt);
+ return fmt;
+}
+
+/*
+ * Change slashes to whatever the locale uses for date separation.
+ * Note: this operates on strings, not GOFormats.
+ *
+ * We aren't doing this completely right: a locale might use 24/12-1999 and
+ * we'll just use the slash.
+ *
+ * If it wasn't so hacky, this should go to go-locale.c
+ */
+char *
+gnm_format_frob_slashes (const char *fmt)
+{
+ const GString *df = go_locale_get_date_format();
+ GString *res = g_string_new (NULL);
+ gunichar date_sep = '/';
+ const char *s;
+
+ for (s = df->str; *s; s++) {
+ switch (*s) {
+ case 'd': case 'm': case 'y':
+ while (g_ascii_isalpha (*s))
+ s++;
+ while (g_unichar_isspace (g_utf8_get_char (s)))
+ s = g_utf8_next_char (s);
+ if (*s != ',' &&
+ g_unichar_ispunct (g_utf8_get_char (s))) {
+ date_sep = g_utf8_get_char (s);
+ goto got_date_sep;
+ }
+ break;
+ default:
+ ; /* Nothing */
+ }
+ }
+got_date_sep:
+
+ while (*fmt) {
+ if (*fmt == '/') {
+ g_string_append_unichar (res, date_sep);
+ } else
+ g_string_append_c (res, *fmt);
+ fmt++;
+ }
+
+ return g_string_free (res, FALSE);
}
Modified: trunk/src/gnm-format.h
==============================================================================
--- trunk/src/gnm-format.h (original)
+++ trunk/src/gnm-format.h Sat Mar 14 22:44:12 2009
@@ -40,6 +40,8 @@
int gnm_format_month_before_day (GOFormat const *fmt,
GnmValue const *value);
+char *gnm_format_frob_slashes (const char *s);
+
GOFormat *gnm_format_for_date_editing (GnmCell const *cell);
gboolean gnm_format_has_hour (GOFormat const *fmt,
Modified: trunk/src/number-match.c
==============================================================================
--- trunk/src/number-match.c (original)
+++ trunk/src/number-match.c Sat Mar 14 22:44:12 2009
@@ -451,52 +451,6 @@
s >= 0 && s < 60;
}
-/*
- * Change slashes to whatever the locale uses for date separation.
- *
- * We aren't doing this completely right: a locale might use 24/12-1999 and
- * we'll just use the slash.
- */
-static char *
-frob_slashes (const char *fmt)
-{
- const GString *df = go_locale_get_date_format();
- GString *res = g_string_new (NULL);
- gunichar date_sep = '/';
- const char *s;
-
- /* If it wasn't so hacky, this should go to go-locale.c */
- for (s = df->str; *s; s++) {
- switch (*s) {
- case 'd': case 'm': case 'y':
- while (g_ascii_isalpha (*s))
- s++;
- while (g_unichar_isspace (g_utf8_get_char (s)))
- s = g_utf8_next_char (s);
- if (*s != ',' &&
- g_unichar_ispunct (g_utf8_get_char (s))) {
- date_sep = g_utf8_get_char (s);
- goto got_date_sep;
- }
- break;
- default:
- ; /* Nothing */
- }
- }
-got_date_sep:
-
- while (*fmt) {
- if (*fmt == '/') {
- g_string_append_unichar (res, date_sep);
- } else
- g_string_append_c (res, *fmt);
- fmt++;
- }
-
- return g_string_free (res, FALSE);
-}
-
-
#define DO_SIGN(sign,uc,action) \
{ \
if (uc == '-' || uc == UNICODE_MINUS_SIGN_C) { \
@@ -663,7 +617,7 @@
day = handle_day (text, match + 27);
year = handle_year (text, match + 30);
if (g_date_valid_dmy (day, month, year)) {
- date_format = frob_slashes ("mmm/dd/yyyy");
+ date_format = gnm_format_frob_slashes ("mmm/dd/yyyy");
text += match[0].rm_eo;
goto got_date;
}
@@ -728,9 +682,9 @@
}
year = handle_year (text, match + 3);
if (g_date_valid_dmy (day, month, year)) {
- date_format = frob_slashes (month_before_day
- ? "m/d/yyyy"
- : "d/m/yyyy");
+ date_format = gnm_format_frob_slashes (month_before_day
+ ? "m/d/yyyy"
+ : "d/m/yyyy");
text += match[0].rm_eo;
goto got_date;
}
@@ -761,12 +715,12 @@
month = handle_month (text, match + 1);
day = handle_day (text, match + 3);
year = current_year ();
- date_format = frob_slashes ("m/d/yyyy");
+ date_format = gnm_format_frob_slashes ("m/d/yyyy");
} else if (good_ddmmsep) {
month = handle_month (text, match + 3);
day = handle_day (text, match + 1);
year = current_year ();
- date_format = frob_slashes ("d/m/yyyy");
+ date_format = gnm_format_frob_slashes ("d/m/yyyy");
} else
year = month = day = -1;
if (g_date_valid_dmy (day, month, year)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]