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

3

11

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?

Ufo answered 13/5, 2011 at 12:24 Comment(5)
Purely a guess, however lunar calendars (e.g., Jewish) have a leap month inserted every so many years because of considerably shorter months.Prizewinner
Oh, and if it's Friday 13th on the 13th month, don't even switch your PC on.Porism
@leppie Note that calendars and dates are a slippery slope, so your "interesting"... beware, here there be dragons :)Fertility
@Lasse V. Karlsen: I tend to avoid any conversations containing the words 'posix time' ;pCoward
Clearly it's for the underappreciated month of Dodecember.Akmolinsk
F
13

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.

Farthingale answered 13/5, 2011 at 12:28 Comment(0)
T
7

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.

Tardif answered 13/5, 2011 at 12:28 Comment(0)
U
-2

I guess it is used to determine the leap day in the julian calendar ( http://en.wikipedia.org/wiki/Julian_calendar ). As most of use use Gregorian calender just do not worry.

Urinate answered 13/5, 2011 at 12:29 Comment(1)
-1: No, it ios for Lunar calendars that add an extra month form time to time to avoid drifting too far form the solar year.Encourage

© 2022 - 2024 — McMap. All rights reserved.