mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
Refactored, sorry.
This commit is contained in:
@@ -45,15 +45,13 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
*/
|
*/
|
||||||
def datetimeAgoRecentOnly(date: Date): String = {
|
def datetimeAgoRecentOnly(date: Date): String = {
|
||||||
val duration = new Date().getTime - date.getTime
|
val duration = new Date().getTime - date.getTime
|
||||||
val list = timeUnits.map(tuple => (duration / tuple._1, tuple._2)).filter(tuple => tuple._1 > 0)
|
timeUnits.find(tuple => duration / tuple._1 > 0) match {
|
||||||
if (list.isEmpty)
|
case Some((_, "month")) => s"on ${new SimpleDateFormat("d MMM", Locale.ENGLISH).format(date)}"
|
||||||
"just now"
|
case Some((_, "year")) => s"on ${new SimpleDateFormat("d MMM yyyy", Locale.ENGLISH).format(date)}"
|
||||||
else {
|
case Some((unitValue, unitString)) =>
|
||||||
list.head match {
|
val value = duration / unitValue
|
||||||
case (_, "month") => s"on ${new SimpleDateFormat("d MMM", Locale.ENGLISH).format(date)}"
|
s"${value} ${unitString}${if (value > 1) "s" else ""} ago"
|
||||||
case (_, "year") => s"on ${new SimpleDateFormat("d MMM yyyy", Locale.ENGLISH).format(date)}"
|
case None => "just now"
|
||||||
case (value, unitString) => s"${value} ${unitString}${if (value > 1) "s" else ""} ago"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user