Recursive Minutes to Days, Hours, Minutes in C# (Humanize Time)

If you need to convert a lump sum of minutes into something a little easer for humans (people) to read then here it is:

Comments welcome.

private static string MinutesToHumanTime(int minutes)
{
	const int MINUTES_IN_DAY = 60 * 24;

	if (minutes >= MINUTES_IN_DAY)
	{
		var days_as_string = (minutes / MINUTES_IN_DAY).ToString() + " days ";

		return days_as_string + MinutesToHumanTime(minutes % MINUTES_IN_DAY);
	}
	else if (minutes >= 60)
	{
		var hours_as_string = (minutes / 60).ToString() + " hours ";

		return hours_as_string + MinutesToHumanTime(minutes % 60);
	}
	else
	{
		return minutes.ToString() + " minutes ";
	}
}

Comments (0)

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     twitter

About

[Insert Witty Saying Here]