[Mono-list] Patch for DataTime.cs
Elan Feingold
efeingold@mn.rr.com
Thu, 27 Feb 2003 11:45:52 -0600
This is a multi-part message in MIME format.
------=_NextPart_000_008E_01C2DE55.C86A20A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
A few things:=20
- FileTime is expressed in Universal time, and as such must be converted
before subtracting the magic offset (patch 1)
- Strings in the format "2003-02-27T10:05:03-11:00" (note the timezone
at the end) *must* be parsed by DateTime.Parse() for compatibility with
Microsoft. This came up in my work with XML [de]serialization, which
I'll send a patch for shortly (patch 1)
- The date time format patterns didn't match MS output (patch 2)
I've been running my test program (also included) on XP and Linux to get
them to match.
Also, a question. Whenever I run any .NET program under Mono, always I
get three characters of garbage printed at the start "=EF=BB=BF" (not =
sure if
these will show up in email). Any ideas?
Best regards,
-elan
------=_NextPart_000_008E_01C2DE55.C86A20A0
Content-Type: application/octet-stream;
name="patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="patch"
Index: class/corlib/System/DateTime.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mcs/class/corlib/System/DateTime.cs,v=0A=
retrieving revision 1.30=0A=
diff -u -r1.30 DateTime.cs=0A=
--- class/corlib/System/DateTime.cs 28 Jan 2003 15:28:13 -0000 1.30=0A=
+++ class/corlib/System/DateTime.cs 27 Feb 2003 17:38:43 -0000=0A=
@@ -486,6 +486,11 @@=0A=
public static DateTime Parse (string s, IFormatProvider fp, =
DateTimeStyles styles)
{
string[] formats =3D {
+ // For compatibility with MS's CLR, this format (which
+ // doesn't have a one-letter equivalent) is parsed
+ // too. It's important because it's used in XML
+ // serialization.
+ "yyyy-MM-ddTHH:mm:sszzzzzz",
// Full date and time
"F", "G", "r", "s", "u", "U",
// Full date and time, but no seconds
@@ -991,7 +996,7 @@=0A=
throw new ArgumentOutOfRangeException("file time is not valid");
}
=09
- return(ticks.Ticks - w32file_epoch);
+ return(ToUniversalTime().Ticks - w32file_epoch);
}
=20
public string ToLongDateString()
------=_NextPart_000_008E_01C2DE55.C86A20A0
Content-Type: text/plain;
name="testDate.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="testDate.cs"
using System;=0A=
using System.IO;=0A=
using System.Text;=0A=
using System.Globalization;=0A=
using System.Runtime.CompilerServices;=0A=
=0A=
public class MainClass=0A=
{=0A=
static void Main ()=0A=
{=0A=
String date =3D "2003-02-27T10:05:03-11:00";=0A=
=0A=
string format =3D "yyyy-MM-ddTHH:mm:sszzzzzz";=0A=
DateTime newNow =3D DateTime.ParseExact(date, format, null);=0A=
=0A=
Console.WriteLine("*** ParseExact ***");=0A=
Console.WriteLine("Date.Exact: [{0}]", newNow.ToString());=0A=
Console.WriteLine("ToFileTime: [{0}]", newNow.ToFileTime());=0A=
Console.WriteLine("Ticks: [{0}]", newNow.Ticks);=0A=
=0A=
Console.WriteLine("FromFileTime: [{0}]", =0A=
=
DateTime.FromFileTime(newNow.ToFileTime()).ToString());=0A=
=0A=
Console.WriteLine("\n*** Parse ***");=0A=
newNow =3D DateTime.Parse(date);=0A=
Console.WriteLine("Date.Parse: [{0}]", newNow.ToString());=0A=
Console.WriteLine("ToFileTime: [{0}]", newNow.ToFileTime());=0A=
Console.WriteLine("Ticks: [{0}]", newNow.Ticks);=0A=
=0A=
Console.WriteLine("FromFileTime: [{0}]", =0A=
=
DateTime.FromFileTime(newNow.ToFileTime()).ToString());=0A=
=0A=
}=0A=
}=0A=
------=_NextPart_000_008E_01C2DE55.C86A20A0
Content-Type: application/octet-stream;
name="patch2"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="patch2"
Index: class/corlib/System.Globalization/DateTimeFormatInfo.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/mono/mcs/class/corlib/System.Globalization/DateTimeFormatInfo.cs,v=0A=
retrieving revision 1.4=0A=
diff -b -u -r1.4 DateTimeFormatInfo.cs=0A=
--- class/corlib/System.Globalization/DateTimeFormatInfo.cs 12 Jun 2002 =
11:02:53 -0000 1.4=0A=
+++ class/corlib/System.Globalization/DateTimeFormatInfo.cs 27 Feb 2003 =
17:45:05 -0000=0A=
@@ -92,13 +92,13 @@=0A=
=09
_TimeSeparator =3D ":";=0A=
=09
- _ShortDatePattern =3D "MM/dd/yyyy";=0A=
+ _ShortDatePattern =3D "%M/dd/yyyy";
=09
_LongDatePattern =3D "dddd, dd MMMM yyyy";=0A=
=09
- _ShortTimePattern =3D "HH:mm";=0A=
+ _ShortTimePattern =3D "%h:mm tt";
=09
- _LongTimePattern =3D "HH:mm:ss";=0A=
+ _LongTimePattern =3D "%h:mm:ss tt";
=09
_MonthDayPattern =3D "MMMM dd";=0A=
=09
------=_NextPart_000_008E_01C2DE55.C86A20A0--