From dad1d02162ca6319b076957dc4e23f0c3125658b Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Mon, 27 Mar 2017 17:27:19 -0600 Subject: [PATCH] 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 34ec9a66..b999391f 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 855359e2..9972808c 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 { -- GitLab