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;
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));
}
/**
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;
guint len_formatv;
guint i;
guint i_to;
+ GDate *date;
g_return_val_if_fail (str != NULL, NULL);
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;
}
datetime->tm_mon + 1,
datetime->tm_year + 1900);
- if (!g_date_valid (ret))
+ if (ret == NULL || !g_date_valid (ret))
{
ret = NULL;
}
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);
+}