Convert hours, minutes and seconds into a time formatted string

This coding challenge will see you pass in the hours, minutes and seconds into a method and convert it to a time formatted string.

Start off with this method:

public class TimeFunctions {

	public string ConvertToTimeString(int hours, int minutes, int seconds)
	{
		if (
			hours < 0 || 
			minutes < 0 || 
			minutes > 59 || 
			seconds < 0 || 
			seconds > 59
			)
		{
			throw new ArgumentOutOfRangeException("Invalid parameters");
		}
	}

}

Go ahead and return the hours, minutes and seconds into a time formatted H:mm:ss string. 

For example, if you pass in hours = 1, minutes = 32 and seconds = 33, the method should return 1:32:33.

We are already throwing an exception if any of the parameters are out of range.

Important things to consider:

  • Include leading zeros on the minutes and seconds (but not the hours). So if you pass in hours = 1, minutes = 3 and seconds = 8, the function should return 1:03:08.
  • If the hours you pass in is 0, it should still return the number of hours as part of the string. So if you pass in hours = 0, minutes = 34 and seconds = 1, the function should return 0:34:01.