1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Refactor DateUtils and merge TimeSince (#32409)

Follow #32383 and #32402
This commit is contained in:
wxiaoguang
2024-11-04 19:30:00 +08:00
committed by GitHub
parent 61be51e56b
commit b068dbd40e
74 changed files with 241 additions and 228 deletions

View File

@@ -24,7 +24,7 @@
<div class="meta">
<span class="text light grey muted-links">
{{if not $.Page.Repository}}{{.Repo.FullName}}{{end}}#{{.Index}}
{{$timeStr := TimeSinceUnix .GetLastEventTimestamp ctx.Locale}}
{{$timeStr := DateUtils.TimeSince .GetLastEventTimestamp}}
{{if .OriginalAuthor}}
{{ctx.Locale.Tr .GetLastEventLabelFake $timeStr .OriginalAuthor}}
{{else if gt .Poster.ID 0}}

View File

@@ -30,7 +30,7 @@
<progress class="milestone-progress-big" value="{{.Milestone.Completeness}}" max="100"></progress>
<div class="tw-flex tw-gap-4">
<div classs="tw-flex tw-items-center">
{{$closedDate:= TimeSinceUnix .Milestone.ClosedDateUnix ctx.Locale}}
{{$closedDate:= DateUtils.TimeSince .Milestone.ClosedDateUnix}}
{{if .IsClosed}}
{{svg "octicon-clock"}} {{ctx.Locale.Tr "repo.milestones.closed" $closedDate}}
{{else}}
@@ -38,7 +38,7 @@
{{if .Milestone.DeadlineString}}
<span{{if .IsOverdue}} class="text red"{{end}}>
{{svg "octicon-calendar"}}
{{ctx.DateUtils.AbsoluteShort (.Milestone.DeadlineString|ctx.DateUtils.ParseLegacy)}}
{{DateUtils.AbsoluteShort (.Milestone.DeadlineString|DateUtils.ParseLegacy)}}
</span>
{{else}}
{{svg "octicon-calendar"}}

View File

@@ -47,19 +47,19 @@
{{if .UpdatedUnix}}
<div class="flex-text-block">
{{svg "octicon-clock"}}
{{ctx.Locale.Tr "repo.milestones.update_ago" (TimeSinceUnix .UpdatedUnix ctx.Locale)}}
{{ctx.Locale.Tr "repo.milestones.update_ago" (DateUtils.TimeSince .UpdatedUnix)}}
</div>
{{end}}
<div class="flex-text-block">
{{if .IsClosed}}
{{$closedDate:= TimeSinceUnix .ClosedDateUnix ctx.Locale}}
{{$closedDate:= DateUtils.TimeSince .ClosedDateUnix}}
{{svg "octicon-clock" 14}}
{{ctx.Locale.Tr "repo.milestones.closed" $closedDate}}
{{else}}
{{if .DeadlineString}}
<span class="flex-text-inline {{if .IsOverdue}}text red{{end}}">
{{svg "octicon-calendar" 14}}
{{ctx.DateUtils.AbsoluteShort (.DeadlineString|ctx.DateUtils.ParseLegacy)}}
{{DateUtils.AbsoluteShort (.DeadlineString|DateUtils.ParseLegacy)}}
</span>
{{else}}
{{svg "octicon-calendar" 14}}

View File

@@ -6,7 +6,7 @@
<input type="hidden" id="issueIndex" value="{{.Issue.Index}}">
<input type="hidden" id="type" value="{{.IssueType}}">
{{$createdStr:= TimeSinceUnix .Issue.CreatedUnix ctx.Locale}}
{{$createdStr:= DateUtils.TimeSince .Issue.CreatedUnix}}
<div class="issue-content-left comment-list prevent-before-timeline">
<div class="ui timeline">
<div id="{{.Issue.HashTag}}" class="timeline-item comment first">

View File

@@ -1,7 +1,7 @@
{{template "base/alert"}}
{{range .Issue.Comments}}
{{if call $.ShouldShowCommentType .Type}}
{{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
{{$createdStr:= DateUtils.TimeSince .CreatedUnix}}
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF,
5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 8 = MILESTONE_CHANGE,
@@ -137,7 +137,7 @@
{{else if eq .RefAction 2}}
{{$refTr = "repo.issues.ref_reopening_from"}}
{{end}}
{{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
{{$createdStr:= DateUtils.TimeSince .CreatedUnix}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge">{{svg "octicon-bookmark"}}</span>
{{template "shared/user/avatarlink" dict "user" .Poster}}
@@ -296,7 +296,7 @@
{{template "shared/user/avatarlink" dict "user" .Poster}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
{{$dueDate := ctx.DateUtils.AbsoluteLong (.Content|ctx.DateUtils.ParseLegacy)}}
{{$dueDate := DateUtils.AbsoluteLong (.Content|DateUtils.ParseLegacy)}}
{{ctx.Locale.Tr "repo.issues.due_date_added" $dueDate $createdStr}}
</span>
</div>
@@ -308,8 +308,8 @@
{{template "shared/user/authorlink" .Poster}}
{{$parsedDeadline := StringUtils.Split .Content "|"}}
{{if eq (len $parsedDeadline) 2}}
{{$to := ctx.DateUtils.AbsoluteLong ((index $parsedDeadline 0)|ctx.DateUtils.ParseLegacy)}}
{{$from := ctx.DateUtils.AbsoluteLong ((index $parsedDeadline 1)|ctx.DateUtils.ParseLegacy)}}
{{$to := DateUtils.AbsoluteLong ((index $parsedDeadline 0)|DateUtils.ParseLegacy)}}
{{$from := DateUtils.AbsoluteLong ((index $parsedDeadline 1)|DateUtils.ParseLegacy)}}
{{ctx.Locale.Tr "repo.issues.due_date_modified" $to $from $createdStr}}
{{end}}
</span>
@@ -320,7 +320,7 @@
{{template "shared/user/avatarlink" dict "user" .Poster}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
{{$dueDate := ctx.DateUtils.AbsoluteLong (.Content|ctx.DateUtils.ParseLegacy)}}
{{$dueDate := DateUtils.AbsoluteLong (.Content|DateUtils.ParseLegacy)}}
{{ctx.Locale.Tr "repo.issues.due_date_remove" $dueDate $createdStr}}
</span>
</div>

View File

@@ -54,7 +54,7 @@
<div id="code-comments-{{$comment.ID}}" class="comment-code-cloud ui segment{{if $resolved}} tw-hidden{{end}}">
<div class="ui comments tw-mb-0">
{{range .comments}}
{{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
{{$createdSubStr:= DateUtils.TimeSince .CreatedUnix}}
<div class="comment code-comment" id="{{.HashTag}}">
<div class="content comment-container">
<div class="header comment-header">

View File

@@ -206,7 +206,7 @@
{{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash $prUnit.PullRequestsConfig.AllowFastForwardOnly}}
{{$hasPendingPullRequestMergeTip := ""}}
{{if .HasPendingPullRequestMerge}}
{{$createdPRMergeStr := TimeSinceUnix .PendingPullRequestMerge.CreatedUnix ctx.Locale}}
{{$createdPRMergeStr := DateUtils.TimeSince .PendingPullRequestMerge.CreatedUnix}}
{{$hasPendingPullRequestMergeTip = ctx.Locale.Tr "repo.pulls.auto_merge_has_pending_schedule" .PendingPullRequestMerge.Doer.Name $createdPRMergeStr}}
{{end}}
<div class="divider"></div>

View File

@@ -368,7 +368,7 @@
<div class="tw-flex tw-justify-between tw-items-center">
<div class="due-date {{if .Issue.IsOverdue}}text red{{end}}" {{if .Issue.IsOverdue}}data-tooltip-content="{{ctx.Locale.Tr "repo.issues.due_date_overdue"}}"{{end}}>
{{svg "octicon-calendar" 16 "tw-mr-2"}}
{{ctx.DateUtils.AbsoluteLong .Issue.DeadlineUnix}}
{{DateUtils.AbsoluteLong .Issue.DeadlineUnix}}
</div>
<div>
{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}

View File

@@ -63,7 +63,7 @@
{{$baseHref = HTMLFormat `<a href="%s">%s</a>` .BaseBranchLink $baseHref}}
{{end}}
{{if .Issue.PullRequest.HasMerged}}
{{$mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix ctx.Locale}}
{{$mergedStr:= DateUtils.TimeSince .Issue.PullRequest.MergedUnix}}
{{if .Issue.OriginalAuthor}}
{{.Issue.OriginalAuthor}}
<span class="pull-desc">{{ctx.Locale.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr}}</span>
@@ -111,7 +111,7 @@
</span>
{{end}}
{{else}}
{{$createdStr:= TimeSinceUnix .Issue.CreatedUnix ctx.Locale}}
{{$createdStr:= DateUtils.TimeSince .Issue.CreatedUnix}}
<span class="time-desc">
{{if .Issue.OriginalAuthor}}
{{ctx.Locale.Tr "repo.issues.opened_by_fake" $createdStr .Issue.OriginalAuthor}}