(ref #519) Change datetime formats

This commit is contained in:
Shintaro Murakami
2014-10-18 23:21:47 +09:00
parent 8764910553
commit e33dd9008b
21 changed files with 85 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
package view package view
import java.util.{Date, TimeZone} import java.util.{Locale, Date, TimeZone}
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import play.twirl.api.Html import play.twirl.api.Html
import util.StringUtil import util.StringUtil
@@ -15,6 +15,49 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
*/ */
def datetime(date: Date): String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) def datetime(date: Date): String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)
val timeUnits = List(
(1000L, "second"),
(1000L * 60, "minute"),
(1000L * 60 * 60, "hour"),
(1000L * 60 * 60 * 24, "day"),
(1000L * 60 * 60 * 24 * 30, "month"),
(1000L * 60 * 60 * 24 * 365, "year")
).reverse
/**
* Format java.util.Date to "x {seconds/minutes/hours/days/months/years} ago"
*/
def datetimeAgo(date: Date): String = {
val duration = new Date().getTime - date.getTime
timeUnits.find(tuple => duration / tuple._1 > 0) match {
case Some((unitValue, unitString)) =>
val value = duration / unitValue
s"${value} ${unitString}${if (value > 1) "s" else ""} ago"
case None => "just now"
}
}
/**
*
* Format java.util.Date to "x {seconds/minutes/hours/days} ago"
* If duration over 1 month, format to "d MMM (yyyy)"
*
*/
def datetimeAgoRecentOnly(date: Date): String = {
val duration = new Date().getTime - date.getTime
val list = timeUnits.map(tuple => (duration / tuple._1, tuple._2)).filter(tuple => tuple._1 > 0)
if (list.isEmpty)
"just now"
else {
list.head match {
case (_, "month") => s"on ${new SimpleDateFormat("d MMM", Locale.ENGLISH).format(date)}"
case (_, "year") => s"on ${new SimpleDateFormat("d MMM yyyy", Locale.ENGLISH).format(date)}"
case (value, unitString) => s"${value} ${unitString}${if (value > 1) "s" else ""} ago"
}
}
}
/** /**
* Format java.util.Date to "yyyy-MM-dd'T'hh:mm:ss'Z'". * Format java.util.Date to "yyyy-MM-dd'T'hh:mm:ss'Z'".
*/ */

View File

@@ -25,7 +25,7 @@
@if(repository.repository.description.isDefined){ @if(repository.repository.description.isDefined){
<div>@repository.repository.description</div> <div>@repository.repository.description</div>
} }
<div><span class="muted small">Last updated: @datetime(repository.repository.lastActivityDate)</span></div> <div><span class="muted small">Updated @helper.html.datetimeago(repository.repository.lastActivityDate)</span></div>
</div> </div>
</div> </div>
} }

View File

@@ -165,7 +165,7 @@
#@issue.issueId #@issue.issueId
</span> </span>
<div class="small muted" style="margin-left: 20px;"> <div class="small muted" style="margin-left: 20px;">
Opened by @user(issue.openedUserName, styleClass="username") @datetime(issue.registeredDate)&nbsp; Opened by @user(issue.openedUserName, styleClass="username") @helper.html.datetimeago(issue.registeredDate)&nbsp;
@if(commentCount > 0){ @if(commentCount > 0){
<i class="icon-comment"></i><a href="@path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a> <i class="icon-comment"></i><a href="@path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a>
} }

View File

@@ -86,7 +86,7 @@
} }
</div> </div>
<div class="small muted" style="margin-left: 20px;"> <div class="small muted" style="margin-left: 20px;">
@avatarLink(issue.openedUserName, 20) by @user(issue.openedUserName, styleClass="username") @datetime(issue.registeredDate)&nbsp; @avatarLink(issue.openedUserName, 20) by @user(issue.openedUserName, styleClass="username") @helper.html.datetimeago(issue.registeredDate)&nbsp;
@if(commentCount > 0){ @if(commentCount > 0){
<i class="icon-comment"></i><a href="@path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a> <i class="icon-comment"></i><a href="@path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">@commentCount @plural(commentCount, "comment")</a>
} }

View File

@@ -62,7 +62,7 @@
@detailActivity(activity: model.Activity, image: String) = { @detailActivity(activity: model.Activity, image: String) = {
<div class="activity-icon-large"><img src="@assets/common/images/@image"/></div> <div class="activity-icon-large"><img src="@assets/common/images/@image"/></div>
<div class="activity-content"> <div class="activity-content">
<div class="muted small">@datetime(activity.activityDate)</div> <div class="muted small">@helper.html.datetimeago(activity.activityDate)</div>
<div class="strong"> <div class="strong">
@avatar(activity.activityUserName, 16) @avatar(activity.activityUserName, 16)
@activityMessage(activity.message) @activityMessage(activity.message)
@@ -76,7 +76,7 @@
@customActivity(activity: model.Activity, image: String)(additionalInfo: Any) = { @customActivity(activity: model.Activity, image: String)(additionalInfo: Any) = {
<div class="activity-icon-large"><img src="@assets/common/images/@image"/></div> <div class="activity-icon-large"><img src="@assets/common/images/@image"/></div>
<div class="activity-content"> <div class="activity-content">
<div class="muted small">@datetime(activity.activityDate)</div> <div class="muted small">@helper.html.datetimeago(activity.activityDate)</div>
<div class="strong"> <div class="strong">
@avatar(activity.activityUserName, 16) @avatar(activity.activityUserName, 16)
@activityMessage(activity.message) @activityMessage(activity.message)
@@ -91,7 +91,7 @@
<div> <div>
@avatar(activity.activityUserName, 16) @avatar(activity.activityUserName, 16)
@activityMessage(activity.message) @activityMessage(activity.message)
<span class="muted small">@datetime(activity.activityDate)</span> <span class="muted small">@helper.html.datetimeago(activity.activityDate)</span>
</div> </div>
</div> </div>
} }

View File

@@ -0,0 +1,10 @@
@(latestUpdatedDate: java.util.Date,
recentOnly: Boolean = true)
@import view.helpers._
<span data-toggle="tooltip" title="@datetime(latestUpdatedDate)">
@if(recentOnly){
@datetimeAgoRecentOnly(latestUpdatedDate)
}else{
@datetimeAgo(latestUpdatedDate)
}
</span>

View File

@@ -8,7 +8,7 @@
<div class="issue-avatar-image">@avatar(issue.openedUserName, 48)</div> <div class="issue-avatar-image">@avatar(issue.openedUserName, 48)</div>
<div class="box issue-comment-box"> <div class="box issue-comment-box">
<div class="box-header-small"> <div class="box-header-small">
@user(issue.openedUserName, styleClass="username strong") <span class="muted">commented on @datetime(issue.registeredDate)</span> @user(issue.openedUserName, styleClass="username strong") <span class="muted">commented @helper.html.datetimeago(issue.registeredDate)</span>
<span class="pull-right"> <span class="pull-right">
@if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){ @if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){
<a href="#" data-issue-id="@issue.issueId"><i class="icon-pencil"></i></a> <a href="#" data-issue-id="@issue.issueId"><i class="icon-pencil"></i></a>
@@ -32,7 +32,7 @@
} else { } else {
@if(pullreq.isEmpty){ referenced the issue } else { referenced the pull request } @if(pullreq.isEmpty){ referenced the issue } else { referenced the pull request }
} }
on @datetime(comment.registeredDate) @helper.html.datetimeago(comment.registeredDate)
</span> </span>
<span class="pull-right"> <span class="pull-right">
@if(comment.action != "commit" && comment.action != "merge" && comment.action != "refer" && @if(comment.action != "commit" && comment.action != "merge" && comment.action != "refer" &&
@@ -70,7 +70,7 @@
} else { } else {
<span class="label label-info monospace">@pullreq.map(_.userName):@pullreq.map(_.branch)</span> to <span class="label label-info monospace">@pullreq.map(_.requestUserName):@pullreq.map(_.requestBranch)</span> <span class="label label-info monospace">@pullreq.map(_.userName):@pullreq.map(_.branch)</span> to <span class="label label-info monospace">@pullreq.map(_.requestUserName):@pullreq.map(_.requestBranch)</span>
} }
@datetime(comment.registeredDate) @helper.html.datetimeago(comment.registeredDate)
</div> </div>
} }
@if(comment.action == "close" || comment.action == "close_comment"){ @if(comment.action == "close" || comment.action == "close_comment"){
@@ -78,9 +78,9 @@
<span class="label label-important">Closed</span> <span class="label label-important">Closed</span>
@avatar(comment.commentedUserName, 20) @avatar(comment.commentedUserName, 20)
@if(issue.isPullRequest){ @if(issue.isPullRequest){
@user(comment.commentedUserName, styleClass="username strong") closed the pull request @datetime(comment.registeredDate) @user(comment.commentedUserName, styleClass="username strong") closed the pull request @helper.html.datetimeago(comment.registeredDate)
} else { } else {
@user(comment.commentedUserName, styleClass="username strong") closed the issue @datetime(comment.registeredDate) @user(comment.commentedUserName, styleClass="username strong") closed the issue @helper.html.datetimeago(comment.registeredDate)
} }
</div> </div>
} }
@@ -88,14 +88,14 @@
<div class="small issue-comment-action"> <div class="small issue-comment-action">
<span class="label label-success">Reopened</span> <span class="label label-success">Reopened</span>
@avatar(comment.commentedUserName, 20) @avatar(comment.commentedUserName, 20)
@user(comment.commentedUserName, styleClass="username strong") reopened the issue @datetime(comment.registeredDate) @user(comment.commentedUserName, styleClass="username strong") reopened the issue @helper.html.datetimeago(comment.registeredDate)
</div> </div>
} }
@if(comment.action == "delete_branch"){ @if(comment.action == "delete_branch"){
<div class="small issue-comment-action"> <div class="small issue-comment-action">
<span class="label">Deleted</span> <span class="label">Deleted</span>
@avatar(comment.commentedUserName, 20) @avatar(comment.commentedUserName, 20)
@user(comment.commentedUserName, styleClass="username strong") deleted the <span class="label label-info monospace">@pullreq.map(_.requestBranch)</span> branch @datetime(comment.registeredDate) @user(comment.commentedUserName, styleClass="username strong") deleted the <span class="label label-info monospace">@pullreq.map(_.requestBranch)</span> branch @helper.html.datetimeago(comment.registeredDate)
</div> </div>
} }
} }

View File

@@ -28,7 +28,7 @@
<span class="label label-success issue-status">Open</span> <span class="label label-success issue-status">Open</span>
} }
<span class="muted"> <span class="muted">
@user(issue.openedUserName, styleClass="username strong") opened this issue on @datetime(issue.registeredDate) - @defining( @user(issue.openedUserName, styleClass="username strong") opened this issue @helper.html.datetimeago(issue.registeredDate) - @defining(
comments.filter( _.action.contains("comment") ).size comments.filter( _.action.contains("comment") ).size
){ count => ){ count =>
@count @plural(count, "comment") @count @plural(count, "comment")

View File

@@ -203,7 +203,7 @@
} }
</span> </span>
<div class="small muted" style="margin-left: 40px; margin-top: 5px;"> <div class="small muted" style="margin-left: 40px; margin-top: 5px;">
#@issue.issueId opened by @user(issue.openedUserName, styleClass="username") @datetime(issue.registeredDate) #@issue.issueId opened @helper.html.datetimeago(issue.registeredDate) by @user(issue.openedUserName, styleClass="username")
@milestone.map { milestone => @milestone.map { milestone =>
<span style="margin: 20px;"><a href="@condition.copy(milestoneId = Some(Some(1))).toURL" class="username"><img src="@assets/common/images/milestone.png"> @milestone</a></span> <span style="margin: 20px;"><a href="@condition.copy(milestoneId = Some(Some(1))).toURL" class="username"><img src="@assets/common/images/milestone.png"> @milestone</a></span>
} }

View File

@@ -34,7 +34,7 @@
<a href="@url(repository)/issues?milestone=@milestone.milestoneId&state=open" class="milestone-title">@milestone.title</a> <a href="@url(repository)/issues?milestone=@milestone.milestoneId&state=open" class="milestone-title">@milestone.title</a>
<div style="margin-top: 6px"> <div style="margin-top: 6px">
@if(milestone.closedDate.isDefined){ @if(milestone.closedDate.isDefined){
<span class="muted">Closed @datetime(milestone.closedDate.get)</span> <span class="muted">Closed @helper.html.datetimeago(milestone.closedDate.get)</span>
} else { } else {
@milestone.dueDate.map { dueDate => @milestone.dueDate.map { dueDate =>
@if(isPast(dueDate)){ @if(isPast(dueDate)){

View File

@@ -20,7 +20,7 @@
<span class="label label-info">Merged</span> <span class="label label-info">Merged</span>
@user(comment.commentedUserName, styleClass="username strong") merged @commits.size @plural(commits.size, "commit") @user(comment.commentedUserName, styleClass="username strong") merged @commits.size @plural(commits.size, "commit")
into <code>@pullreq.userName:@pullreq.branch</code> from <code>@pullreq.requestUserName:@pullreq.requestBranch</code> into <code>@pullreq.userName:@pullreq.branch</code> from <code>@pullreq.requestUserName:@pullreq.requestBranch</code>
at @datetime(comment.registeredDate) @helper.html.datetimeago(comment.registeredDate)
}.getOrElse { }.getOrElse {
<span class="label label-important">Closed</span> <span class="label label-important">Closed</span>
@user(issue.openedUserName, styleClass="username strong") wants to merge @commits.size @plural(commits.size, "commit") @user(issue.openedUserName, styleClass="username strong") wants to merge @commits.size @plural(commits.size, "commit")

View File

@@ -34,7 +34,7 @@
<div class="pull-left"> <div class="pull-left">
@avatar(latestCommit, 20) @avatar(latestCommit, 20)
@user(latestCommit.authorName, latestCommit.authorEmailAddress, "username strong") @user(latestCommit.authorName, latestCommit.authorEmailAddress, "username strong")
<span class="muted">@datetime(latestCommit.commitTime)</span> <span class="muted">@helper.html.datetimeago(latestCommit.commitTime)</span>
<a href="@url(repository)/commit/@latestCommit.id" class="commit-message">@link(latestCommit.summary, repository)</a> <a href="@url(repository)/commit/@latestCommit.id" class="commit-message">@link(latestCommit.summary, repository)</a>
</div> </div>
<div class="btn-group pull-right"> <div class="btn-group pull-right">

View File

@@ -22,7 +22,7 @@
} }
</td> </td>
<td> <td>
@datetime(latestUpdateDate) @helper.html.datetimeago(latestUpdateDate, false)
</td> </td>
<td> <td>
@if(repository.repository.defaultBranch == branchName){ @if(repository.repository.defaultBranch == branchName){

View File

@@ -68,13 +68,13 @@
<div class="author"> <div class="author">
@avatar(commit, 20) @avatar(commit, 20)
<span>@user(commit.authorName, commit.authorEmailAddress, "username strong")</span> <span>@user(commit.authorName, commit.authorEmailAddress, "username strong")</span>
<span class="muted">authored on @datetime(commit.authorTime)</span> <span class="muted">authored @helper.html.datetimeago(commit.authorTime)</span>
</div> </div>
@if(commit.isDifferentFromAuthor) { @if(commit.isDifferentFromAuthor) {
<div class="committer"> <div class="committer">
<span class="icon-arrow-right"></span> <span class="icon-arrow-right"></span>
<span>@user(commit.committerName, commit.committerEmailAddress, "username strong")</span> <span>@user(commit.committerName, commit.committerEmailAddress, "username strong")</span>
<span class="muted"> committed on @datetime(commit.commitTime)</span> <span class="muted"> committed @helper.html.datetimeago(commit.commitTime)</span>
</div> </div>
} }
</div> </div>

View File

@@ -58,11 +58,11 @@
} }
<div class="small"> <div class="small">
@user(commit.authorName, commit.authorEmailAddress, "username") @user(commit.authorName, commit.authorEmailAddress, "username")
<span class="muted">authored @datetime(commit.authorTime)</span> <span class="muted">authored @helper.html.datetimeago(commit.authorTime)</span>
@if(commit.isDifferentFromAuthor) { @if(commit.isDifferentFromAuthor) {
<span class="icon-arrow-right" style="margin-top : -2px ;"></span> <span class="icon-arrow-right" style="margin-top : -2px ;"></span>
@user(commit.committerName, commit.committerEmailAddress, "username") @user(commit.committerName, commit.committerEmailAddress, "username")
<span class="muted">committed @datetime(commit.authorTime)</span> <span class="muted">committed @helper.html.datetimeago(commit.authorTime)</span>
} }
</div> </div>
</div> </div>

View File

@@ -47,13 +47,13 @@
<div class="author"> <div class="author">
@avatar(latestCommit, 20) @avatar(latestCommit, 20)
<span>@user(latestCommit.authorName, latestCommit.authorEmailAddress, "username strong")</span> <span>@user(latestCommit.authorName, latestCommit.authorEmailAddress, "username strong")</span>
<span class="muted"> authored on @datetime(latestCommit.authorTime)</span> <span class="muted"> authored @helper.html.datetimeago(latestCommit.authorTime)</span>
</div> </div>
@if(latestCommit.isDifferentFromAuthor) { @if(latestCommit.isDifferentFromAuthor) {
<div class="committer"> <div class="committer">
<span class="icon-arrow-right"></span> <span class="icon-arrow-right"></span>
<span>@user(latestCommit.committerName, latestCommit.committerEmailAddress, "username strong")</span> <span>@user(latestCommit.committerName, latestCommit.committerEmailAddress, "username strong")</span>
<span class="muted"> committed on @datetime(latestCommit.commitTime)</span> <span class="muted"> committed @helper.html.datetimeago(latestCommit.commitTime)</span>
</div> </div>
} }
</div> </div>
@@ -106,7 +106,7 @@
<a href="@url(repository)/commit/@file.commitId" class="commit-message">@link(file.message, repository)</a> <a href="@url(repository)/commit/@file.commitId" class="commit-message">@link(file.message, repository)</a>
[@user(file.author, file.mailAddress)] [@user(file.author, file.mailAddress)]
</td> </td>
<td style="text-align: right;">@datetime(file.time)</td> <td style="text-align: right;">@helper.html.datetimeago(file.time, false)</td>
</tr> </tr>
} }
</table> </table>

View File

@@ -14,7 +14,7 @@
@repository.tags.reverse.map { tag => @repository.tags.reverse.map { tag =>
<tr> <tr>
<td><a href="@url(repository)/tree/@encodeRefName(tag.name)">@tag.name</a></td> <td><a href="@url(repository)/tree/@encodeRefName(tag.name)">@tag.name</a></td>
<td>@datetime(tag.time)</td> <td>@helper.html.datetimeago(tag.time, false)</td>
<td class="monospace"><a href="@url(repository)/commit/@tag.id">@tag.id.substring(0, 10)</a></td> <td class="monospace"><a href="@url(repository)/commit/@tag.id">@tag.id.substring(0, 10)</a></td>
<td> <td>
<a href="@url(repository)/archive/@{encodeRefName(tag.name)}.zip">ZIP</a> <a href="@url(repository)/archive/@{encodeRefName(tag.name)}.zip">ZIP</a>

View File

@@ -16,7 +16,7 @@
@files.drop((page - 1) * CodeLimit).take(CodeLimit).map { file => @files.drop((page - 1) * CodeLimit).take(CodeLimit).map { file =>
<div> <div>
<h5><a href="@url(repository)/blob/@repository.repository.defaultBranch/@file.path">@file.path</a></h5> <h5><a href="@url(repository)/blob/@repository.repository.defaultBranch/@file.path">@file.path</a></h5>
<div class="small muted">Latest commit at @datetime(file.lastModified)</div> <div class="small muted">Last commited @helper.html.datetimeago(file.lastModified)</div>
<pre class="prettyprint linenums:@file.highlightLineNumber" style="padding-left: 25px;">@Html(file.highlightText)</pre> <pre class="prettyprint linenums:@file.highlightLineNumber" style="padding-left: 25px;">@Html(file.highlightText)</pre>
</div> </div>
} }

View File

@@ -22,7 +22,7 @@
} }
<div class="small muted"> <div class="small muted">
Opened by <a href="@url(issue.openedUserName)" class="username">@issue.openedUserName</a> Opened by <a href="@url(issue.openedUserName)" class="username">@issue.openedUserName</a>
at @datetime(issue.registeredDate) @helper.html.datetimeago(issue.registeredDate)
@if(issue.commentCount > 0){ @if(issue.commentCount > 0){
&nbsp;&nbsp;<i class="icon-comment"></i><span class="strong">@issue.commentCount</span> @plural(issue.commentCount, "comment") &nbsp;&nbsp;<i class="icon-comment"></i><span class="strong">@issue.commentCount</span> @plural(issue.commentCount, "comment")
} }

View File

@@ -36,7 +36,7 @@
<td width="0%"><input type="checkbox" name="commitId" value="@commit.id"></td> <td width="0%"><input type="checkbox" name="commitId" value="@commit.id"></td>
<td>@avatar(commit, 20)&nbsp;@user(commit.authorName, commit.authorEmailAddress)</td> <td>@avatar(commit, 20)&nbsp;@user(commit.authorName, commit.authorEmailAddress)</td>
<td width="80%"> <td width="80%">
<span class="muted">@datetime(commit.authorTime):</span>&nbsp;@commit.shortMessage <span class="muted">@helper.html.datetimeago(commit.authorTime):</span>&nbsp;@commit.shortMessage
</td> </td>
</tr> </tr>
} }

View File

@@ -12,7 +12,7 @@
<li> <li>
<h1 class="wiki-title">@pageName</h1> <h1 class="wiki-title">@pageName</h1>
<div class="small"> <div class="small">
<span class="muted"><strong>@page.committer</strong> edited this page at @datetime(page.time)</span> <span class="muted"><strong>@page.committer</strong> edited this page @helper.html.datetimeago(page.time)</span>
</div> </div>
</li> </li>
<li class="pull-right"> <li class="pull-right">