[gxml] GomDate: Fixed parsing some dates



commit dad1d02162ca6319b076957dc4e23f0c3125658b
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Mar 27 17:27:19 2017 -0600

    GomDate: Fixed parsing some dates

 gxml/GomProperty.vala          |   15 ++++++++++++++-
 test/GomSerializationTest.vala |   10 ++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/gxml/GomProperty.vala b/gxml/GomProperty.vala
index 34ec9a6..b999391 100644
--- a/gxml/GomProperty.vala
+++ b/gxml/GomProperty.vala
@@ -382,7 +382,20 @@ public class GXml.GomDate : GomBaseProperty {
     }
     set {
       _value = Date ();
-      _value.set_parse (value);
+      if ("-" in value) {
+        string[] dp = value.split ("-");
+        if (dp.length == 3) {
+          int y = int.parse (dp[0]);
+          int m = int.parse (dp[1]);
+          int d = int.parse (dp[2]);
+          _value.set_dmy ((DateDay) d, (DateMonth) m, (DateYear) y);
+          if (!_value.valid ())
+            warning (_("Invalid Date for property: "+value));
+        } else
+          warning (_("Invalid format for Date property: "+value));
+      } else {
+        _value.set_parse (value);
+      }
       if (!_value.valid ())
         warning (_("Invalid Date for property: "+value));
     }
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 855359e..9972808 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -491,12 +491,14 @@ class GomSerializationTest : GXmlTest  {
       assert (t.pay_date.get_date ().valid ());
       assert (t.pay_date.value != null);
       assert (t.pay_date.value == "2023-03-10");
+      t.pay_date.value = "2075-3-17";
+      assert (t.pay_date.get_date ().valid ());
+      assert (t.pay_date.value != null);
+      assert (t.pay_date.value == "2075-03-17");
       s = t.to_string ();
       assert (s != null);
-#if DEBUG
-      GLib.message ("DOC:"+s);
-#endif
-      assert ("PayDate=\"2023-03-10\"" in s);
+      message (t.pay_date.value);
+      assert ("PayDate=\"2075-03-17\"" in s);
     });
     Test.add_func ("/gxml/gom-serialization/read/property-date", () => {
     try {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]