From 8736581784e6cb93da0820485ef6a02478143d59 Mon Sep 17 00:00:00 2001 From: dbera Date: Sat, 11 Nov 2006 02:17:54 +0000 Subject: [PATCH] DateTime.ParseExact is a mess in mcs (fixed in .Net-2.0). As a result 20060101090000, stored as date+time (in UTC, without timezone) was parsed as 2006-01-01:09:00:00-4, giving incorrect times in libbeagle (our C# clients converted the time to localtime 2006-01-01:05:00:00-4 and was saved). Now the datetime values are properly parsed and deserialized. ** NOTE: Probably I broke C# clients - namely beagle-search. I think search/Tiles/Utils.cs: NiceDatePattern and NiceVeryLongDate needs to do "dt = dt.Date;" instead of "dt = dt.ToLocalTime().Date;". Someone please verify and fix that. --- Util/StringFu.cs | 15 ++++++++++++--- tools/Query.cs | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Util/StringFu.cs b/Util/StringFu.cs index 1c7714ae..86de503a 100644 --- a/Util/StringFu.cs +++ b/Util/StringFu.cs @@ -41,11 +41,13 @@ namespace Beagle.Util { public const string UnindexedNamespace = "_unindexed:"; - private const String timeFormat = "yyyyMMddHHmmss"; + private const String TimeFormat = "yyyyMMddHHmmss"; + // FIXME: Fix all the UTC and timezone hack when switching to gmcs + private const String LocalTimeFormat = "yyyyMMddHHmmsszz"; static public string DateTimeToString (DateTime dt) { - return dt.ToString (timeFormat); + return dt.ToString (TimeFormat); } static public string DateTimeToYearMonthString (DateTime dt) @@ -63,7 +65,14 @@ namespace Beagle.Util { if (str == null || str == "") return new DateTime (); - return DateTime.ParseExact (str, timeFormat, CultureInfo.CurrentCulture); + str = string.Concat (str, "+00"); + // Uncomment next 3 lines to see what how 20061107173446 (which is stored in UTC) + // used to be parsed as 2006-11-07T17:34:46.0000000-05:00 + //DateTime dt = DateTime.ParseExact (str, LocalTimeFormat, CultureInfo.InvariantCulture); + //Console.WriteLine ("Parsed {0} as {1},{2}", str, dt, dt.ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz", CultureInfo.InvariantCulture)); + //return dt; + // If no timezone is present, parse_exact uses local time zone + return DateTime.ParseExact (str, LocalTimeFormat, CultureInfo.InvariantCulture); } static public string DateTimeToFuzzy (DateTime dt) diff --git a/tools/Query.cs b/tools/Query.cs index 52f35a0c..ce04fa65 100644 --- a/tools/Query.cs +++ b/tools/Query.cs @@ -87,7 +87,7 @@ class QueryTool { Console.WriteLine (" Src: {0}", hit.Source); Console.WriteLine ("Score: {0}", hit.Score); if (hit.ValidTimestamp) - Console.WriteLine (" Time: {0}", hit.Timestamp.ToLocalTime ()); + Console.WriteLine (" Time: {0}", hit.Timestamp); foreach (Property prop in hit.Properties) Console.WriteLine (" {0} = '{1}'", prop.Key, prop.Value); -- 2.11.4.GIT