Castle.MonoRail.Framework.Helpers.DateFormatHelper.FriendlyFormatFromNow C# (CSharp) Méthode

FriendlyFormatFromNow() public méthode

Returns the difference from the specified date the the current date in a friendly string like "1 day ago"

TODO: Think about i18n

public FriendlyFormatFromNow ( System.DateTime date ) : String
date System.DateTime The date in the past (should be equal or less than now)
Résultat String
		public String FriendlyFormatFromNow(DateTime date)
		{
			TimeSpan now = new TimeSpan(DateTime.Now.Ticks);
			TimeSpan cur = new TimeSpan(date.Ticks);

			TimeSpan diff = now.Subtract(cur);

			if (diff.TotalSeconds == 0)
			{
				return "Just now";
			}

			if (diff.Days == 0)
			{
				if (diff.Hours == 0)
				{
					if (diff.Minutes == 0)
					{
						return String.Format("{0} second{1} ago", 
							diff.Seconds, diff.Seconds > 1 ? "s" : String.Empty);
					}
					else
					{
						return String.Format("{0} minute{1} ago", 
							diff.Minutes, diff.Minutes > 1 ? "s" : String.Empty);
					}
				}
				else
				{
					return String.Format("{0} hour{1} ago", 
						diff.Hours, diff.Hours > 1 ? "s" : String.Empty);
				}
			}
			else
			{
				return String.Format("{0} day{1} ago", 
					diff.Days, diff.Days > 1 ? "s" : String.Empty);
			}
		}