Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Jsonize() Date and Time serialization [patch]
Re: Jsonize() Date and Time serialization [patch] [message #57211 is a reply to message #57210] Sat, 12 June 2021 08:47 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
zsolt wrote on Fri, 11 June 2021 19:51
Quick correction:
This one would be safer for dates:
@ -328,12 +328,12 @@ template<> void Jsonize(JsonIO& io, Date& var)
 			return;
 		}
 		if(IsString(v)) {
-			String text = v;
+			String text = Filter(v.ToString(), CharFilterDigit);
 			if(text.GetCount() > 6) {
 				Date d;
 				d.year = ScanInt(text.Left(4));
 				d.month = ScanInt(text.Mid(4, 2));
-				d.day = ScanInt(text.Mid(6));
+				d.day = ScanInt(text.Mid(6,2));
 				if(d.IsValid()) {
 					var = d;
 					return;
@@ -346,7 +346,7 @@ template<> void Jsonize(JsonIO& io, Date& var)
 		if(IsNull(var))
 			io.Set(Null);
 		else
-			io.Set(Format("%04d%02d%02d", var.year, var.month, var.day));
+			io.Set(Format("%04d-%02d-%02d", var.year, var.month, var.day));
 }
 
 template<> void Jsonize(JsonIO& io, Time& var)
@@ -358,15 +358,15 @@ template<> void Jsonize(JsonIO& io, Time& var)
 			return;
 		}
 		if(IsString(v)) {
-			String text = v;
-			if(text.GetCount() > 15) {
+			String text = Filter(v.ToString(), CharFilterDigit);
+			if(text.GetCount() > 10) {//seconds may be missing
 				Time tm;
 				tm.year = ScanInt(text.Left(4));
 				tm.month = ScanInt(text.Mid(4, 2));
 				tm.day = ScanInt(text.Mid(6, 2));
-				tm.hour = ScanInt(text.Mid(9, 2));
-				tm.minute = ScanInt(text.Mid(12, 2));
-				tm.second = ScanInt(text.Mid(15));
+				tm.hour = ScanInt(text.Mid(8, 2));
+				tm.minute = ScanInt(text.Mid(10, 2));
+				tm.second = ScanInt(text.Mid(12, 2));
 				if(tm.IsValid()) {
 					var = tm;
 					return;
@@ -379,7 +379,7 @@ template<> void Jsonize(JsonIO& io, Time& var)
 		if(IsNull(var))
 			io.Set(Null);
 		else
-			io.Set(Format("%04d%02d%02d`T%02d:%02d:%02d",
+			io.Set(Format("%04d-%02d-%02d`T%02d:%02d:%02d",
 				          var.year, var.month, var.day, var.hour, var.minute, var.second));
 }
 


This is tough decision - backward incompatible change. At minimum we should make Jsonize recognize old format as well as new...

In any case, so far the Jsonize format was considered like "U++ private", it was not meant for "external" communication.

That said, I am OK with the change, as long as it able to read previous format...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: MSVS15x64: Compile Error C3256 C3259 C3250 in Fn.h findarg
Next Topic: How do I implement mouse hover in Ctrl based class
Goto Forum:
  


Current Time: Mon Aug 25 19:23:33 CEST 2025

Total time taken to generate the page: 0.06329 seconds