]> saetta.ns0.it Git - libgtkform/commitdiff
Bugfix for gtk_form_field_datetime_is_empty that it was incomplete.
authorAndrea Zagli <azagli@libero.it>
Sat, 7 Nov 2009 12:04:13 +0000 (13:04 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 7 Nov 2009 12:04:13 +0000 (13:04 +0100)
src/fielddatetime.c

index ba03320e2f4085f2135f2670259d796f2603d212..8b5b8596d262ba9804ee2999ce6c8cc1b37c7c05 100644 (file)
@@ -57,6 +57,8 @@ static gchar *gtk_form_field_datetime_str_replace (const gchar *string,
                                       const gchar *origin,
                                       const gchar *replace);
 
+static gboolean gtk_form_field_datetime_is_valid (GtkFormFieldDateTime *field);
+
 #define GTK_FORM_FIELD_DATETIME_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_FORM_FIELD_DATETIME, GtkFormFieldDateTimePrivate))
 
 typedef struct _GtkFormFieldDateTimePrivate GtkFormFieldDateTimePrivate;
@@ -294,9 +296,7 @@ gtk_form_field_datetime_is_empty (GtkFormField *field)
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), TRUE);
 
-       ret = FALSE;
-
-       return ret;
+       return !gtk_form_field_datetime_is_valid (GTK_FORM_FIELD_DATETIME (field));
 }
 
 /**
@@ -414,10 +414,6 @@ gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *d
 struct tm
 *gtk_form_field_datetime_get_tm_from_str (const gchar *str, const gchar *format)
 {
-       /* TO DO
-        * check if it is a valid date/time
-     */
-
        struct tm *ret;
        gchar *new_str;
        gchar *new_format;
@@ -428,6 +424,7 @@ struct tm
        guint len_formatv;
        guint i;
        guint i_to;
+       GDate *date;
 
        g_return_val_if_fail (str != NULL, NULL);
 
@@ -517,6 +514,15 @@ struct tm
        g_free (new_format);
        g_free (new_str);
 
+       /* check if it is valid */
+       date = g_date_new_dmy (ret->tm_mday,
+                              ret->tm_mon + 1,
+                              ret->tm_year + 1900);
+       if (date == NULL || !g_date_valid (date))
+               {
+                       return NULL;
+               }
+
        return ret;
 }
 
@@ -579,7 +585,7 @@ GDate
                                              datetime->tm_mon + 1,
                                              datetime->tm_year + 1900);
 
-                       if (!g_date_valid (ret))
+                       if (ret == NULL || !g_date_valid (ret))
                                {
                                        ret = NULL;
                                }
@@ -751,3 +757,21 @@ static gchar
 
        return ret;
 }
+
+static gboolean
+gtk_form_field_datetime_is_valid (GtkFormFieldDateTime *field)
+{
+       gboolean ret;
+
+       GtkFormFieldDateTimePrivate *priv;
+
+       gchar *str_date;
+       struct tm *tm_date;
+
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (field);
+
+       str_date = gtk_form_field_datetime_get_value_stringify (GTK_FORM_FIELD (field));
+       tm_date = gtk_form_field_datetime_get_tm_from_str (str_date, priv->display_format);
+
+       return (tm_date != NULL);
+}