''# <summary>
''# Return how long in the past something happend
''# </summary>
''# <param name="input">The date of an event<event in UTC time</param>
''# <param name="append">append characters to the end of the string
''# example: "ago"<"suffixAgo"</param>
''# <returns>a logical string "10 mins ago"</returns>
''# <remarks>This function is primarily used in Views to format Model data.</remarks>
Public Shared Function GetDateRange(ByVal input As DateTime, Optional ByVal appendsuffixAgo As String = Nothing) As String
Dim SecondsAppartoutput As Integer = DateDiff(DateInterval.Second, input, Now)String
Dim isRecenttheDate As BooleanDateTime = Falsedt
Dim outputDateInterval As String
TimeSpan = DateTime.UtcNow - theDate
If SecondsAppart < 86400 Then
Dim SecondsAppart As Integer = Math.Floor(DateInterval.TotalSeconds)
Select CaseIf (SecondsAppart
< 86400) Then
If CaseSecondsAppart Is< <=59 1Then
: output = "1 sec " & append : isRecent = True
output = ("less than a minute " + suffixAgo)
Case Is <= 59 : output = DateDiff(DateInterval.Second, input,ElseIf Now)SecondsAppart &< "119 secsThen
" & append : isRecent = True
output = ("about a minute " + CasesuffixAgo)
Is <= 119 : output = "1 min " & append : isRecentElseIf =SecondsAppart True
< 3599 Then
Case Is <=output 3599= :String.Format("{0} outputminutes ={1}", DateDiffMath.Floor(DateInterval.Minute, inputTotalMinutes), NowsuffixAgo)
& " mins " & append : isRecent = True
ElseIf SecondsAppart < 7199 Then
Case Is <= 7199 : output = "1"about hran hour " &+ appendsuffixAgo
Else
Case Else : output = DateDiff(DateInterval.Hour, input, Now) & output = String.Format("{0} hrshours {1}", &Math.Floor(DateInterval.TotalHours), appendsuffixAgo)
End Select
If
Else
Dim DaysAppart As Integer = DateDiffMath.Floor(DateInterval.Day, input, NowTotalDays)
Select CaseIf DaysAppart
<= 1 Then
Case Is <= 1 : output = "1 day " & append"yesterday"
Case Is <= 6 : output = DateDiff(DateInterval.Day, input, Now) & "ElseIf daysDaysAppart "< &30 appendThen
Case Is <= 13 : output = "1String.Format("{0} weekdays {1}", &Math.Floor(DateInterval.TotalDays), appendsuffixAgo)
ElseIf CaseDaysAppart Is< <=60 30Then
: output = DateDiff(DateInterval.Weekday, input, Now) & " weeks " & append
output = "about a month " + suffixAgo
Case Is <= 60 : output = "1ElseIf monthDaysAppart "< &365 appendThen
Case Is <= 365 : output = DateDiff(DateIntervalString.Month, input, Now) & Format("{0} months {1}" & append
, Math.Floor(DateInterval.TotalDays / 30), suffixAgo)
CaseElseIf IsDaysAppart <=< 730 : output = "1 year " & appendThen
Case Else : output = DateDiff(DateInterval.Year, input, Now) &"about "a yearsyear " &+ appendsuffixAgo)
End SelectElse
End If
output If= isRecentString.Format("{0} Then
years {1}", Math.Floor(DateInterval.TotalDays / 365), suffixAgo)
Return "<span class=""recent-date"">" & output &End "</span>"If
ElseEnd If
Return output
End If
End Function