The formatting order of dates is one of the most complex and divisive issues the world faces today. Some of us vehemently argue that Month/Day/Year is appropriate, considering that's how we say dates out loud. Others loudly proclaim that Day/Month/Year is best, because it puts the terms in ascending order of the duration they represent.
Enough is enough. Computers can resolve this dispute simply and fairly. Your code, a complete function or program, will take a date string delimited by slashes, e.g. 12/1/2015
. Note this is the exact format, without leading zeroes and with a four-digit year at the end.
- If it's definitely Month/Day/Year, e.g.
10/31/1998
, output a text representation of that date in this exact format, with the full month name, day, and year:October 31, 1998
- If it's definitely Day/Month/Year, e.g.
25/12/1989
, output the same sort of text representation:December 25, 1989
. - If it's ambiguous whether it's Month/Day/Year or Day/Month/Year, output a date that resolves the ambiguity by combining the two possible dates as follows:
- Create a new month name by taking the first half of the name of the earlier month and append the second half of the later month. For months with odd length, the first half gets the extra letter. To be explicit, the first halves of the months are
Janu
,Febr
,Mar
,Apr
,Ma
,Ju
,Ju
,Aug
,Septe
,Octo
,Nove
, andDece
and the second halves are thereforeary
,uary
,ch
,il
,y
,ne
,ly
,ust
,mber
,ber
,mber
, andmber
. - Calculate the day by averaging the two possible days, taking the floor when the average is not an integer.
- Output the text representation of this date, e.g. for
10/8/2011
, outputAugber 9, 2011
.
- Create a new month name by taking the first half of the name of the earlier month and append the second half of the later month. For months with odd length, the first half gets the extra letter. To be explicit, the first halves of the months are
If the input date cannot be Month/Day/Year or Day/Month/Year (e.g. 13/13/2013
or even 2/30/2002
), any behavior is acceptable. This code golf, shortest code wins!
Test cases:
10/31/1998
gives October 31, 1998
25/12/1989
gives December 25, 1989
10/8/2011
gives Augber 9, 2011
8/5/1957
gives Maust 6, 1957
9/12/2012
(oddly enough) gives September 10, 2012
1/1/2000
gives January 1, 2000
without leading zeroes and with a four-digit year at the end
impliesyear >= 1000
\$\endgroup\$