[mapguide-commits] r8303 - in branches/2.6/MgDev/Common: Foundation/System MapGuideCommon/Controller

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jul 16 05:03:49 PDT 2014


Author: jng
Date: 2014-07-16 05:03:49 -0700 (Wed, 16 Jul 2014)
New Revision: 8303

Modified:
   branches/2.6/MgDev/Common/Foundation/System/Util.cpp
   branches/2.6/MgDev/Common/Foundation/System/Util.h
   branches/2.6/MgDev/Common/MapGuideCommon/Controller/HtmlController.cpp
Log:
#2467: Fix MgOutOfRangeException in v2.6 QUERYMAPFEATURES when working with dates pre-1970. The default ToXmlString() cannot handle dates before unix epoch. The fix is to manually write out the MgDateTime in yyyy-mm-dd hh:mm:ss format. This submission includes a new MgUtil::PadLeft() method to assist in writing out dates in this particular format.

Modified: branches/2.6/MgDev/Common/Foundation/System/Util.cpp
===================================================================
--- branches/2.6/MgDev/Common/Foundation/System/Util.cpp	2014-07-11 02:17:44 UTC (rev 8302)
+++ branches/2.6/MgDev/Common/Foundation/System/Util.cpp	2014-07-16 12:03:49 UTC (rev 8303)
@@ -1253,3 +1253,9 @@
         className  = qualifiedClassName.substr(index + 1);
     }
 }
+
+void MgUtil::PadLeft(REFSTRING str, const size_t numChars, wchar_t ch)
+{
+    if (numChars > str.size())
+        str.insert(0, numChars - str.size(), ch);
+}
\ No newline at end of file

Modified: branches/2.6/MgDev/Common/Foundation/System/Util.h
===================================================================
--- branches/2.6/MgDev/Common/Foundation/System/Util.h	2014-07-11 02:17:44 UTC (rev 8302)
+++ branches/2.6/MgDev/Common/Foundation/System/Util.h	2014-07-16 12:03:49 UTC (rev 8303)
@@ -538,6 +538,8 @@
     ///
     static bool GetLinuxMemoryStatus(MgLinuxMemoryStatus* pMemoryStatus);
 
+    static void PadLeft(REFSTRING str, const size_t numChars, wchar_t ch);
+
     static void Int32ToLocaleSpecificString(INT32 val, string& str);
 
     static void Int32ToString(INT32 val, string& str);

Modified: branches/2.6/MgDev/Common/MapGuideCommon/Controller/HtmlController.cpp
===================================================================
--- branches/2.6/MgDev/Common/MapGuideCommon/Controller/HtmlController.cpp	2014-07-11 02:17:44 UTC (rev 8302)
+++ branches/2.6/MgDev/Common/MapGuideCommon/Controller/HtmlController.cpp	2014-07-16 12:03:49 UTC (rev 8303)
@@ -583,7 +583,41 @@
                             {
                                 Ptr<MgDateTime> dt = reader->GetDateTime(i);
                                 xmlOut.append(L"<Value>");
-                                xmlOut.append(dt->ToXmlString());
+                                //ToXmlString() won't work with dates before Jan 1, 1970, so use yyyy-mm-dd hh:mm:ss
+                                STRING dateStr;
+                                STRING str;
+                                if (dt->IsDate())
+                                {
+                                    MgUtil::Int32ToString(dt->GetYear(), str);
+                                    dateStr += str;
+                                    MgUtil::Int32ToString(dt->GetMonth(), str);
+                                    dateStr += L"-";
+                                    MgUtil::PadLeft(str, 2, L'0');
+                                    dateStr += str;
+                                    MgUtil::Int32ToString(dt->GetDay(), str);
+                                    dateStr += L"-";
+                                    MgUtil::PadLeft(str, 2, L'0');
+                                    dateStr += str;
+                                }
+                                if (dt->IsTime())
+                                {
+                                    if (dt->IsDate())
+                                    {
+                                        dateStr += L" ";
+                                    }
+                                    MgUtil::Int32ToString(dt->GetHour(), str);
+                                    MgUtil::PadLeft(str, 2, L'0');
+                                    dateStr += str;
+                                    MgUtil::Int32ToString(dt->GetMinute(), str);
+                                    dateStr += L":";
+                                    MgUtil::PadLeft(str, 2, L'0');
+                                    dateStr += str;
+                                    MgUtil::Int32ToString(dt->GetSecond(), str);
+                                    dateStr += L":";
+                                    MgUtil::PadLeft(str, 2, L'0');
+                                    dateStr += str;
+                                }
+                                xmlOut.append(dateStr);
                                 xmlOut.append(L"</Value>\n");
                             }
                             break;



More information about the mapguide-commits mailing list