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

AlternativeFriendlyFormatFromNow() public méthode

Alternative representation of a difference between the specified date and now. If within 24hr it returns Today. If within 48hr it returns Yesterday. If within 40 days it returns x days ago and otherwise it returns x months ago

TODO: Think about i18n

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

			TimeSpan diff = now.Subtract(cur);

			if (diff.TotalHours <= 24)
			{
				return "Today";
			}
			else if (diff.TotalHours <= 48)
			{
				return "Yesterday";
			}
			else if (diff.TotalDays <= 40)
			{
				return String.Format("{0} days ago", diff.Days);
			}
			else 
			{
				return String.Format("{0} months ago", (diff.Days / 30));
			}
		}