PC Review


Reply
Thread Tools Rate Thread

DateTimeFormat.MonthNames contains 13 items???

 
 
Jesse Houwing
Guest
Posts: n/a
 
      13th Jan 2010
Hmz...

I just found a little article on the Daily WTF and tried one of the
samples. And then I found that DateTimeFormat.MonthNames is actually 13
long... WHY?!

Is it to support different calendars? Is it to support 1 based indexes
in VB? I cannot wrap my head around it...

the article in question:
http://thedailywtf.com/Articles/Help...L-Helpers.aspx

The simplest solution I found:
public static string[] GetMonthNames(int startMonth)
{
var months = new
List<string>(DateTimeFormatInfo.CurrentInfo.MonthNames.Take(12));
return
months.Skip(startMonth).Concat(months.Take(startMonth)).ToArray();
}

--
Jesse Houwing
jesse.houwing at sogeti.nl
 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      13th Jan 2010
Jesse Houwing wrote:
> Hmz...
>
> I just found a little article on the Daily WTF and tried one of the
> samples. And then I found that DateTimeFormat.MonthNames is actually 13
> long... WHY?!
>
> Is it to support different calendars? Is it to support 1 based indexes
> in VB? I cannot wrap my head around it...


The documentation makes clear it's the former. From the documentation
for DateTimeFormatInfo.MonthNames:

When this property is set, the array must be
one-dimensional and must have exactly 13
elements. Calendar objects accommodate
calendars with 13 months.

Pete
 
Reply With Quote
 
Mihai N.
Guest
Posts: n/a
 
      14th Jan 2010
> I just found a little article on the Daily WTF and tried one of the
> samples. And then I found that DateTimeFormat.MonthNames is actually 13
> long... WHY?!
>
> Is it to support different calendars? Is it to support 1 based indexes
> in VB? I cannot wrap my head around it...



There are years with 13 months in some non-Gregorian calendars.
For instance the Hebrew calendar has a "leap month" in 7 years out of 13.


--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

 
Reply With Quote
 
Jesse Houwing
Guest
Posts: n/a
 
      14th Jan 2010
* Peter Duniho wrote, On 14-1-2010 0:58:
> Jesse Houwing wrote:
>> Hmz...
>>
>> I just found a little article on the Daily WTF and tried one of the
>> samples. And then I found that DateTimeFormat.MonthNames is actually
>> 13 long... WHY?!
>>
>> Is it to support different calendars? Is it to support 1 based indexes
>> in VB? I cannot wrap my head around it...

>
> The documentation makes clear it's the former. From the documentation
> for DateTimeFormatInfo.MonthNames:
>
> When this property is set, the array must be
> one-dimensional and must have exactly 13
> elements. Calendar objects accommodate
> calendars with 13 months.
>
> Pete


Makes sense... Though they could have returned an array with the correct
size without problems... Ohh well ...

--
Jesse Houwing
jesse.houwing at sogeti.nl
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      14th Jan 2010
Jesse Houwing wrote:
> Makes sense... Though they could have returned an array with the correct
> size


True. But…

> without problems...


Not necessarily. Second-guessing API design is fraught with error.

You (and I) have no idea what led to the "always 13 elements" decision.
It's entirely possible that requirement was inherited within .NET from
some factor outside their control, such as an unmanaged API, and perhaps
even a factor where it really does make more sense for the length of the
array to always be fixed.

I doubt that the existing design was chosen completely arbitrarily.

In any case, it is what it is.

Pete
 
Reply With Quote
 
Jehuda
Guest
Posts: n/a
 
      25th Feb 2010
It's very simple guys: look for calender reform at wikipedia and you'll understand. There are models of calendars based on 13 month instead of 12

---
frmsrcurl: http://msgroups.net/microsoft.public...tains-13-items
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateTimeFormat gh Microsoft ASP .NET 6 2nd Oct 2007 07:56 AM
DateTimeFormat issue in schema.ini file Radu Stanciu Microsoft Access External Data 2 29th Mar 2005 05:25 PM
WebApplication - CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern--Not Working!! Muralidhar Chennoju Microsoft C# .NET 0 6th Oct 2004 05:28 PM
DateTimeFormat Karunakararao Microsoft C# .NET 4 30th Sep 2004 01:45 PM
Array of MonthNames JMay Microsoft Excel Misc 5 14th Dec 2003 11:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:58 AM.