[Mono-bugs] [Bug 47753][Nor] New - DateTime.ToString() produces different output on Mono versus .NET

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 26 May 2004 09:17:15 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by atsushi@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=47753

--- shadow/47753	2004-05-26 09:17:15.000000000 -0400
+++ shadow/47753.tmp.13175	2004-05-26 09:17:15.000000000 -0400
@@ -0,0 +1,124 @@
+Bug#: 47753
+Product: Mono: Class Libraries
+Version: unspecified
+OS: Suse 8.2
+OS Details: 
+Status: RESOLVED   
+Resolution: FIXED
+Severity: Unknown
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mathpup@mylinuxisp.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DateTime.ToString() produces different output on Mono versus .NET
+
+Description of Problem: 
+ 
+When using the DateTime.ToString(string format) with the single-letter format 
+specifiers, such as "G", "T", or "t", .NET includes an AM/PM designator whereas Mono 
+does not.  
+ 
+For example, the MS docs claim that "T" format corresponds to the format pattern 
+of "HH:mm:ss", but the former produces "2:14:20 AM", whereas the latter produces 
+"02:14:20". This is only one example. "G" formatting, by extension, suffers the same 
+problem. 
+ 
+This seems to be one of the cases where .NET differs from the ECMA spec (and their 
+own docs). And I suspect that the only real way to fix it is to write some comparison 
+tests and check Mono's output versus .NET.  
+ 
+Although this bug might seem cosmetic, it has the potential affect round-tripping of 
+data. It also could cause problems with any of the DateTime.ParseExact() methods. 
+ 
+ 
+ 
+ 
+Steps to reproduce the problem: 
+1. mcs datetime.cs 
+2. mono datetime.exe 
+3. Repeat under .NET 
+ 
+ 
+Actual Results: 
+ 
+Under Mono: 
+ 
+02:14:20 
+02:14:20 
+ 
+ 
+Under Rotor/.NET 
+ 
+2:14:20 AM 
+02:14:20 
+ 
+ 
+Expected Results: 
+ 
+ 
+ 
+How often does this happen?  
+ 
+Always 
+ 
+ 
+Additional Information: 
+ 
+ 
+Test case: 
+ 
+using System; 
+ 
+public class Testing 
+{ 
+    public static void Main() 
+    { 
+        DateTime d = new DateTime(2003, 8, 20, 2, 14, 20, 0); 
+        Console.WriteLine(d.ToString("T", null)); 
+        Console.WriteLine(d.ToString("HH:mm:ss", null));              
+    } 
+}
+
+------- Additional Comments From gonzalo@ximian.com  2003-08-20 06:33 -------
+See also bug 47720
+
+------- Additional Comments From kem@leoninedev.com  2003-11-21 14:35 -------
+The problem is with the 'h' formatter used in the ToString() method.
+In MS .NET, the ToString("h:mm:ss tt") for 12:00am return "12:00:00
+AM" where as Mono returns "0:00:00 AM".
+
+The question is where does the class library determine where 12:00 AM
+is 00:00 or 12:00?
+
+Example program:
+
+using System;
+namespace Test1
+{
+  class Class1
+  {
+    static void Main(string [] args)
+    {
+      DateTime dt;
+      dt = DateTime.Parse("11/12/2003 00:00");
+      Console.WriteLine("Now: " + dt.ToString("h:mm:ss tt"));
+    }
+  }
+}
+
+
+------- Additional Comments From atsushi@ximian.com  2004-05-26 09:17 -------
+Now it should be fixed. You will have to update mono runtime. 
+
+Note that it would be better to set the exact culture into you want to
+test (since MS.NET gets your culture from your system, but mono tries
+to get through LANG environment).
+
+System.Threading.Thread.CurrentThread.CurrentCulture = new
+System.Globalization.CultureInfo (your-culture-name);
+
+Reopen if it still doesn't work fine.