Some date routines I found swept under the rug. How they got into the code-base I don't know, but there was only one C# developer on the project when I joined, so I waited until he left.
public static string GetDTZ(DateTime inDT)
{
string rString = "";
rString += inDT.Year;
rString += FixDigits(inDT.Month, 2);
rString += FixDigits(inDT.Day, 2);
rString += "T";
rString += FixDigits(inDT.Hour, 2);
rString += FixDigits(inDT.Minute, 2);
rString += FixDigits(inDT.Second, 2);
rString += "Z";
return rString;
}
public static string GetMonthName(int inMonth)
{
string[] months = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
return months[inMonth % 13];
}
public static string GetDateName(int inNumber)
{
string[] nos = {"", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth",
"tenth", "eleventh", "twelfth", "thirteeth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth",
"twenty", "twenty first", "twenty second", "twenty third", "twenty fourth", "twenty fifth", "twenty sixth", "twenty seventh", "twenty eigth", "twenty ninth",
"thirty", "thirty first", "thirty second", "thirty third", "thirty fourth", "thirty fifth", "thirty sixth", "thirty seventh", "thirty eigth", "thirty ninth",
"forty", "forty first", "forty second", "forty third", "forty fourth", "forty fifth", "forty sixth", "forty seventh", "forty eigth", "forty ninth",
"fifty", "fifty first", "fifty second", "fifty third", "fifty fourth", "fifty fifth", "fifty sixth", "fifty seventh", "fifty eigth", "fifty ninth",
"sixty", "sixty first", "sixty second", "sixty third", "sixty fourth", "sixty fifth", "sixty sixth", "sixty seventh", "sixty eigth", "sixty ninth",
"seventy", "seventy first", "seventy second", "seventy third", "seventy fourth", "seventy fifth", "seventy sixth", "seventy seventh", "seventy eigth", "seventy ninth",
"eighty", "eighty first", "eighty second", "eighty third", "eighty fourth", "eighty fifth", "eighty sixth", "eighty seventh", "eighty eigth", "eighty ninth",
"ninety", "ninety first", "ninety second", "ninety third", "ninety fourth", "ninety fifth", "ninety sixth", "ninety seventh", "ninety eigth", "ninety ninth"
};
string outString = "";
if (inNumber > 0 && inNumber < 100)
{
outString += nos[inNumber];
}
return outString;
}
public static string GetDayShortString(int inDay)
{
string[] days = {"", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th",
"17th", "18th", "19th", "20th", "21th", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st", "32nd"};
return days[inDay % 33];
}
|