[Mono-dev] : DateTime.Parse patch

Eyal Alaluf eyala at mainsoft.com
Thu Aug 16 08:46:29 EDT 2007

Hi, Atsushi.

Thanks to your remark I checked again and saw that MS behaviour is to
decide upon the month day and year order according to the
ShortDatePattern in all cases.
When I wrote the code I thought that 'yyyy/MM/dd' didn't indicate the
order but I was wrong.
So actually, the switch is not necessary. Instead checking if 'd'
appears before 'M' is enough.
I actually went ahead and modified the
culture.DateTimeFormat.ShortDatePattern and this modification overrode
the decision if 1/10 is Oct 1st or Jan 10th.
This brought up another complication since I didn't consider the order
of the year according to this pattern and if it says 'yyyy/MM/dd' then
'01/02/03' actually means '2001 Feb 3rd' and 'dd/MM/yyyy' would spit
'2003 Feb 1st'.
I am adding the year logic and will prepare next week a new patch.


-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Atsushi
Sent: 16 August 2007 05:19
To: Eyal Alaluf
Cc: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-dev] : DateTime.Parse patch


I like the effort to improve DateTime.Parse(), but I think your
approach is broken. The switch-case that looks at 
DateTimeFormatInfo.CultureID could be problematic especially
when a DateTimeFormatInfo is cloned and then its format strings
are modified (note that there are setters on DateTimeFormatInfo

Atsushi Eno

Eyal Alaluf wrote:
> Hi, all.
> Attached is a patch for the infamous DateTime.Parse method.
> The current logic for Parse is to try all the culture date time
> and then try some special formats in invariant culture.
> This solution is not sufficient because it is not very compatible with
> MS behavior, it is difficult to maintain and is very inefficient.
> The current patch aims to improve all of these issues. The patch
> two sets of formats 'date' only formats and 'time' only formats.
> The Parse method will check all the date formats for a match. If the
> date format matches the string beginning it will combine it with all
> time formats. It will check similarly all the time formats and match
> them the date formats.
> Only if this fails it will look at all the culture date formats
> the TrypParse negative flow still very slow). This is done because
> additional effort is required to define the culture specific
> The result is that many more formats are recognizable by
> and that it is easier to add formats if necessary.
> In different flows the patch improves performance by a factor of 3-5
> times on Mono.
> Please review and provide feedback since this is a fairly major change
> to a really sensitive spot.
> Eyal.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com

More information about the Mono-devel-list mailing list