Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetMonthName: Valid values are between 1 and 13, inclusive. Why?

I accidentally passed 0 into DateTimeFormatInfo's GetMonthName method:

DateTimeFormatInfo info = new DateTimeFormatInfo();
var monthName = info.GetMonthName(0);

and got a System.ArgumentOutOfRangeException with this error message: Valid values are between 1 and 13, inclusive.

Passing in 1 through to 12 return "January" through to "December" but passing in 13 returns an empty string.

I can see why month numbers are not zero indexed, but what's month 13 for?

like image 826
Andy Avatar asked May 13 '11 12:05

Andy


2 Answers

It's because calendar objects can accomodate 13 months (to handle calendars based on lunar months), see MSDN:

http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx

Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.

like image 171
Jackson Pope Avatar answered Nov 05 '22 19:11

Jackson Pope


According to MSDN

Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.

like image 36
SirViver Avatar answered Nov 05 '22 19:11

SirViver