Home > Development > But … what does it do?

But … what does it do?

One for the C# developers; another sample of the code previously described here and here. Without running the function below, describe exactly the format of its input parameter, the expected output, and what the hell the developer was thinking at the time.

 //get date in ddmmyyyy format
 public static string ddmmyyyyDate(string strdate)
    {

        const string pattern = "^(?<Day>\\d{1,2})(\\/)(?<Month>\\d{1,2})(\\/)"
                       + "(?<Year>\\d{4})$";

        System.Text.RegularExpressions.MatchCollection mc =
                       default(System.Text.RegularExpressions.MatchCollection);

        mc = System.Text.RegularExpressions.Regex.Matches(strdate, pattern);

        if (mc.Count > 0)
        {
            string strMonth = mc[0].Groups["Month"].Value.PadLeft(2, '0');
            string strDay = mc[0].Groups["Day"].Value.PadLeft(2, '0');
            string strYear = mc[0].Groups["Year"].Value;

            string strDateNew = strMonth + "/" + strDay + "/" + strYear;
            return strDateNew;
        }
        else
        {
            return strdate;
        }
    }

For completeness, the code also has another function ‘mmddyyyyDate’ with exactly the same signature and content.

Advertisements
Categories: Development Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: