msgstr ""
"Project-Id-Version: libzakform 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-05-01 09:58+0200\n"
+"POT-Creation-Date: 2017-05-01 11:19+0200\n"
"PO-Revision-Date: 2016-01-02 12:44+0200\n"
"Last-Translator: Andrea Zagli <azagli@libero.it>\n"
"Language-Team: Italian <tp@lists.linux.it>\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: ../src/commons.c:89
+#: ../src/commons.c:90
msgid "lesser than"
msgstr "minore di"
-#: ../src/commons.c:93
+#: ../src/commons.c:94
msgid "lesser or equal to"
msgstr "minore o uguale a"
-#: ../src/commons.c:97
+#: ../src/commons.c:98
msgid "equal to"
msgstr "uguale a"
-#: ../src/commons.c:101
+#: ../src/commons.c:102
msgid "different from"
msgstr "diverso da"
-#: ../src/commons.c:105
+#: ../src/commons.c:106
msgid "greater than"
msgstr "maggiore di"
-#: ../src/commons.c:109
+#: ../src/commons.c:110
msgid "greater or equal to"
msgstr "maggiore o uguale a"
-#: ../src/commons.c:113
+#: ../src/commons.c:114
msgid "NOT SUPPORTED"
msgstr "NON SUPPORTATO"
msgid "Invalid value"
msgstr "Valore non valido"
+#: ../src/formelementvalidatordate.c:364
+#, c-format
+msgid "Value must be %s %s"
+msgstr "Il valore deve essere %s %s"
+
#: ../src/formvalidatorcompare.c:253 ../src/formvalidatorcomparedate.c:266
#, c-format
msgid "«%s» must be %s «%s»"
#include <config.h>
#endif
+#include <glib/gi18n-lib.h>
+
#include <libzakutils/libzakutils.h>
#include "formelementvalidator.h"
typedef struct _ZakFormElementValidatorDatePrivate ZakFormElementValidatorDatePrivate;
struct _ZakFormElementValidatorDatePrivate
{
+ ZakFormCompareType compare_type;
+ gchar *compare_value;
gchar *format;
};
return zak_form_element_validator_date;
}
+/**
+ * zak_form_element_validator_date_set_compare_type:
+ * @validator:
+ * @type:
+ *
+ */
+void
+zak_form_element_validator_date_set_compare_type (ZakFormElementValidatorDate *validator, ZakFormCompareType type)
+{
+ ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (validator);
+
+ priv->compare_type = type;
+}
+
+/**
+ * zak_form_element_validator_date_get_compare_type:
+ * @validator:
+ *
+ */
+ZakFormCompareType
+zak_form_element_validator_date_get_compare_type (ZakFormElementValidatorDate *validator)
+{
+ ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (validator);
+
+ return priv->compare_type;
+}
+
+/**
+ * zak_form_element_validator_date_set_compare_value:
+ * @validator:
+ * @value:
+ *
+ */
+void
+zak_form_element_validator_date_set_compare_value (ZakFormElementValidatorDate *validator, const gchar *value)
+{
+ ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (validator);
+
+ if (priv->compare_value != NULL)
+ {
+ g_free (priv->compare_value);
+ priv->compare_value = NULL;
+ }
+
+ if (value != NULL)
+ {
+ priv->compare_value = g_strdup (value);
+ }
+}
+
+/**
+ * zak_form_element_validator_date_get_compare_value:
+ * @validator:
+ *
+ */
+gchar
+*zak_form_element_validator_date_get_compare_value (ZakFormElementValidatorDate *validator)
+{
+ gchar *ret;
+
+ ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (validator);
+
+ if (priv->compare_value == NULL)
+ {
+ ret = NULL;
+ }
+ else
+ {
+ ret = g_strdup (priv->compare_value);
+ }
+
+ return ret;
+}
+
/**
* zak_form_element_validator_date_set_format:
* @validator:
static gboolean
zak_form_element_validator_date_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
{
+ gchar *prop;
+
ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (ZAK_FORM_ELEMENT_VALIDATOR_DATE (validator));
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type_comp");
+ zak_form_element_validator_date_set_compare_type (ZAK_FORM_ELEMENT_VALIDATOR_DATE (validator), zak_form_get_compare_type_from_string (prop));
+ g_free (prop);
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"value_comp");
+ zak_form_element_validator_date_set_compare_value (ZAK_FORM_ELEMENT_VALIDATOR_DATE (validator), prop);
+ g_free (prop);
+
zak_form_element_validator_date_set_format (ZAK_FORM_ELEMENT_VALIDATOR_DATE (validator), (gchar *)xmlNodeGetContent (xnode));
return TRUE;
gboolean ret;
gchar *_value;
GDateTime *gdt;
+ GDateTime *gdt_compare;
+
+ gint comp;
+ gchar *msg;
ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (validator_date);
g_return_val_if_fail (value != NULL, FALSE);
+ gdt = NULL;
+ gdt_compare = NULL;
+
_value = g_strstrip (g_strdup (value));
if (g_strcmp0 (_value, "") == 0)
{
gdt = zak_utils_get_gdatetime_from_string (_value, priv->format);
ret = (gdt != NULL);
+ if (ret
+ && priv->compare_type > ZAK_FORM_COMPARE_TYPE_NONE)
+ {
+ if (g_strcmp0 (priv->compare_value, "@now") == 0)
+ {
+ GDateTime *gdt_tmp;
+ gchar *gdt_str;
+
+ gdt_tmp = g_date_time_new_now_local ();
+ gdt_str = zak_utils_gdatetime_format (gdt_tmp, priv->format);
+ gdt_compare = zak_utils_get_gdatetime_from_string (gdt_str, priv->format);
+
+ g_free (gdt_str);
+ g_date_time_unref (gdt_tmp);
+ }
+ else
+ {
+ gdt_compare = zak_utils_get_gdatetime_from_string (priv->compare_value, priv->format);
+ }
+
+ if (gdt_compare != NULL)
+ {
+ comp = g_date_time_compare (gdt, gdt_compare);
+ switch (comp)
+ {
+ case -1:
+ ret = (priv->compare_type == ZAK_FORM_COMPARE_TYPE_LESSER
+ || priv->compare_type == ZAK_FORM_COMPARE_TYPE_NOT_EQUAL);
+ break;
+
+ case 0:
+ ret = (priv->compare_type == ZAK_FORM_COMPARE_TYPE_LESSER_EQUAL
+ || priv->compare_type == ZAK_FORM_COMPARE_TYPE_EQUAL
+ || priv->compare_type == ZAK_FORM_COMPARE_TYPE_GREATER_EQUAL);
+ break;
+
+ case 1:
+ ret = (priv->compare_type == ZAK_FORM_COMPARE_TYPE_GREATER
+ || priv->compare_type == ZAK_FORM_COMPARE_TYPE_NOT_EQUAL);
+ break;
+ };
+
+ if (!ret)
+ {
+ msg = g_strdup_printf (_("Value must be %s %s"),
+ zak_form_get_compare_type_stringify (priv->compare_type),
+ zak_utils_gdatetime_format (gdt_compare, priv->format));
+ zak_form_element_validator_set_message (validator_date, msg);
+ g_free (msg);
+ }
+
+ g_date_time_unref (gdt_compare);
+ }
+
+ }
+
if (gdt != NULL)
{
g_date_time_unref (gdt);