Skip to content

Commit

Permalink
Switch to PreferredTimestampTense
Browse files Browse the repository at this point in the history
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
  • Loading branch information
yardenshoham committed Dec 31, 2023
1 parent bbe69c3 commit 0504a8c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 46 deletions.
5 changes: 3 additions & 2 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,9 @@ LEVEL = Info
;; Default is "recentupdate", but you also have "alphabetically", "reverselastlogin", "newest", "oldest".
;EXPLORE_PAGING_DEFAULT_SORT = recentupdate
;;
;; Whether all timestamps should be rendered as absolute time (i.e. 1970-01-01, 11:59). Setting this to false means some timestamps would render as relative (i.e. 2 days ago).
;PREFER_ABSOLUTE_TIMESTAMPS = false
;; The tense all timestamps should be rendered as. Possible values are `absolute` time (i.e. 1970-01-01, 11:59) or `mixed`
;; which means some timestamps would render as relative (i.e. 2 days ago).
;PREFERRED_TIMESTAMP_TENSE = mixed

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 1 addition & 1 deletion docs/content/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
- `ONLY_SHOW_RELEVANT_REPOS`: **false**: Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid values are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest"
- `PREFER_ABSOLUTE_TIMESTAMPS`: **false**: Whether all timestamps should be rendered as absolute time (i.e. 1970-01-01, 11:59). Setting this to false means some timestamps would render as relative (i.e. 2 days ago).
- `PREFERRED_TIMESTAMP_TENSE`: **mixed**: The tense all timestamps should be rendered as. Possible values are `absolute` time (i.e. 1970-01-01, 11:59) or `mixed` which means some timestamps would render as relative (i.e. 2 days ago).

### UI - Admin (`ui.admin`)

Expand Down
88 changes: 47 additions & 41 deletions modules/setting/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@ import (
"time"

"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
)

// UI settings
var UI = struct {
ExplorePagingNum int
SitemapPagingNum int
IssuePagingNum int
RepoSearchPagingNum int
MembersPagingNum int
FeedMaxCommitNum int
FeedPagingNum int
PackagesPagingNum int
GraphMaxCommitNum int
CodeCommentLines int
ReactionMaxUserNum int
MaxDisplayFileSize int64
ShowUserEmail bool
DefaultShowFullName bool
DefaultTheme string
Themes []string
Reactions []string
ReactionsLookup container.Set[string] `ini:"-"`
CustomEmojis []string
CustomEmojisMap map[string]string `ini:"-"`
SearchRepoDescription bool
OnlyShowRelevantRepos bool
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
PreferAbsoluteTimestamps bool
ExplorePagingNum int
SitemapPagingNum int
IssuePagingNum int
RepoSearchPagingNum int
MembersPagingNum int
FeedMaxCommitNum int
FeedPagingNum int
PackagesPagingNum int
GraphMaxCommitNum int
CodeCommentLines int
ReactionMaxUserNum int
MaxDisplayFileSize int64
ShowUserEmail bool
DefaultShowFullName bool
DefaultTheme string
Themes []string
Reactions []string
ReactionsLookup container.Set[string] `ini:"-"`
CustomEmojis []string
CustomEmojisMap map[string]string `ini:"-"`
SearchRepoDescription bool
OnlyShowRelevantRepos bool
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
PreferredTimestampTense string

AmbiguousUnicodeDetection bool

Expand Down Expand Up @@ -68,23 +69,24 @@ var UI = struct {
Keywords string
} `ini:"ui.meta"`
}{
ExplorePagingNum: 20,
SitemapPagingNum: 20,
IssuePagingNum: 20,
RepoSearchPagingNum: 20,
MembersPagingNum: 20,
FeedMaxCommitNum: 5,
FeedPagingNum: 20,
PackagesPagingNum: 20,
GraphMaxCommitNum: 100,
CodeCommentLines: 4,
ReactionMaxUserNum: 10,
MaxDisplayFileSize: 8388608,
DefaultTheme: `gitea-auto`,
Themes: []string{`gitea-auto`, `gitea-light`, `gitea-dark`},
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
ExplorePagingNum: 20,
SitemapPagingNum: 20,
IssuePagingNum: 20,
RepoSearchPagingNum: 20,
MembersPagingNum: 20,
FeedMaxCommitNum: 5,
FeedPagingNum: 20,
PackagesPagingNum: 20,
GraphMaxCommitNum: 100,
CodeCommentLines: 4,
ReactionMaxUserNum: 10,
MaxDisplayFileSize: 8388608,
DefaultTheme: `gitea-auto`,
Themes: []string{`gitea-auto`, `gitea-light`, `gitea-dark`},
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
PreferredTimestampTense: "mixed",

AmbiguousUnicodeDetection: true,

Expand Down Expand Up @@ -143,6 +145,10 @@ func loadUIFrom(rootCfg ConfigProvider) {
UI.DefaultShowFullName = sec.Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
UI.SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true)

if UI.PreferredTimestampTense != "mixed" && UI.PreferredTimestampTense != "absolute" {
log.Fatal("ui.PREFERRED_TIMESTAMP_TENSE must be either 'mixed' or 'absolute'")
}

// OnlyShowRelevantRepos=false is important for many private/enterprise instances,
// because many private repositories do not have "description/topic", users just want to search by their names.
UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
Expand Down
2 changes: 1 addition & 1 deletion modules/timeutil/since.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func timeSinceUnix(then, now time.Time, lang translation.Locale) template.HTML {

// TimeSince renders relative time HTML given a time.Time
func TimeSince(then time.Time, lang translation.Locale) template.HTML {
if setting.UI.PreferAbsoluteTimestamps {
if setting.UI.PreferredTimestampTense == "absolute" {
return DateTime("full", then, `class="time-since"`)
}
return timeSinceUnix(then, time.Now(), lang)
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/components/DiffCommitSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export default {
<div class="gt-ellipsis text light-2">
{{ commit.committer_or_author_name }}
<span class="text right">
<!-- TODO: make this respect the PreferAbsoluteTimestamps setting -->
<!-- TODO: make this respect the PreferredTimestampTense setting -->
<relative-time class="time-since" prefix="" :datetime="commit.time" data-tooltip-content data-tooltip-interactive="true">{{ commit.time }}</relative-time>
</span>
</div>
Expand Down

0 comments on commit 0504a8c

Please sign in to comment.