gboolean
gtk_form_field_datetime_is_empty (GtkFormField *field)
{
- gboolean ret;
-
g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), TRUE);
- return !gtk_form_field_datetime_is_valid_datetime (GTK_FORM_FIELD_DATETIME (field));
+ return (g_strcmp0 (gtk_form_field_datetime_get_value_stringify (GTK_FORM_FIELD (field)), "") == 0);
}
/**
GtkFormFieldDateTimePrivate *priv;
+ gchar *str_value;
GDateTime *gdatetime;
- struct tm *tm_value;
-
gchar *min_value;
- struct tm *tm_min_value;
+ GDateTime *gdt_min_value;
gchar *max_value;
- struct tm *tm_max_value;
+ GDateTime *gdt_max_value;
+ GDateTime *gdt_tmp;
g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), FALSE);
priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
- gdatetime = gtk_form_field_datetime_get_gdatetime_from_str (gtk_form_field_datetime_get_value_stringify (field), priv->display_format);
- if (gdatetime == NULL)
+ ret = FALSE;
+
+ str_value = gtk_form_field_datetime_get_value_stringify (field);
+ if (g_strcmp0 (str_value, "") == 0)
{
- return FALSE;
+ return TRUE;
}
- ret = TRUE;
-
- tm_value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field), priv->display_format);
+ gdatetime = gtk_form_field_datetime_get_gdatetime_from_str (str_value, priv->display_format);
- if (tm_value != NULL)
+ if (gdatetime != NULL)
{
+ ret = TRUE;
min_value = NULL;
max_value = NULL;
{
if (g_strcasecmp (min_value, "now") == 0)
{
- time_t tt;
- tt = time (NULL);
-
- tm_min_value = g_memdup (localtime (&tt), sizeof (struct tm));
+ gdt_tmp = g_date_time_new_now_local ();
if (priv->type == GTK_FORM_FIELD_DATETIME_TYPE_DATE)
{
- tm_min_value->tm_hour = 0;
- tm_min_value->tm_min = 0;
- tm_min_value->tm_sec = 0;
+ gdt_min_value = g_date_time_new_local (g_date_time_get_year (gdt_tmp),
+ g_date_time_get_month (gdt_tmp),
+ g_date_time_get_day_of_month (gdt_tmp),
+ 0, 0, 0.0);
}
else if (priv->type == GTK_FORM_FIELD_DATETIME_TYPE_TIME)
{
- tm_min_value->tm_year = 0;
- tm_min_value->tm_mon = 0;
- tm_min_value->tm_mday = 0;
+ gdt_min_value = g_date_time_new_local (1, 1, 1,
+ g_date_time_get_hour (gdt_tmp),
+ g_date_time_get_minute (gdt_tmp),
+ g_date_time_get_seconds (gdt_tmp));
}
+ gdt_min_value = g_date_time_ref (gdt_tmp);
+ g_date_time_unref (gdt_tmp);
}
else
{
- tm_min_value = gtk_form_field_datetime_get_tm_from_str (min_value,
+ gdt_min_value = gtk_form_field_datetime_get_gdatetime_from_str (min_value,
gtk_form_field_datetime_get_str_format (GTK_FORM_FIELD_DATETIME (field)));
}
- if (tm_min_value != NULL)
+ if (gdt_min_value != NULL)
{
- time_t tt_min_value;
- time_t tt_value;
-
- tt_min_value = mktime (tm_min_value);
- tt_value = mktime (tm_value);
-
- ret = (difftime (tt_min_value, tt_value) <= 0);
+ ret = (g_date_time_compare (gdatetime, gdt_min_value) >= 0);
- g_free (tm_min_value);
+ g_date_time_unref (gdt_min_value);
}
}
{
if (g_strcasecmp (max_value, "now") == 0)
{
- time_t tt;
- tt = time (NULL);
-
- tm_max_value = g_memdup (localtime (&tt), sizeof (struct tm));
+ gdt_tmp = g_date_time_new_now_local ();
if (priv->type == GTK_FORM_FIELD_DATETIME_TYPE_DATE)
{
- tm_max_value->tm_hour = 0;
- tm_max_value->tm_min = 0;
- tm_max_value->tm_sec = 0;
+ gdt_max_value = g_date_time_new_local (g_date_time_get_year (gdt_tmp),
+ g_date_time_get_month (gdt_tmp),
+ g_date_time_get_day_of_month (gdt_tmp),
+ 0, 0, 0.0);
}
else if (priv->type == GTK_FORM_FIELD_DATETIME_TYPE_TIME)
{
- tm_max_value->tm_year = 0;
- tm_max_value->tm_mon = 0;
- tm_max_value->tm_mday = 0;
+ gdt_max_value = g_date_time_new_local (1, 1, 1,
+ g_date_time_get_hour (gdt_tmp),
+ g_date_time_get_minute (gdt_tmp),
+ g_date_time_get_seconds (gdt_tmp));
}
+ gdt_max_value = g_date_time_ref (gdt_tmp);
+ g_date_time_unref (gdt_tmp);
}
else
{
- tm_max_value = gtk_form_field_datetime_get_tm_from_str (max_value,
+ gdt_max_value = gtk_form_field_datetime_get_gdatetime_from_str (max_value,
gtk_form_field_datetime_get_str_format (GTK_FORM_FIELD_DATETIME (field)));
}
- if (tm_max_value != NULL)
+ if (gdt_max_value != NULL)
{
- time_t tt_max_value;
- time_t tt_value;
-
- tt_max_value = mktime (tm_max_value);
- tt_value = mktime (tm_value);
-
- ret = (difftime (tt_max_value, tt_value) >= 0);
+ ret = (g_date_time_compare (gdatetime, gdt_max_value) <= 0);
- g_free (tm_max_value);
+ g_date_time_unref (gdt_max_value);
}
}
- g_free (tm_value);
+ g_date_time_unref (gdatetime);
}
return ret;