Skip to content

Commit 39ad067

Browse files
author
Sysoev, Vladimir
committed
Tracked time representation modifined with UI settings
Tracked time in the issue represented not in the same manner as estimated. Because of estimated time viewed in hours it might be convinient to have tracked time represented in the same way. Managers love to compare estimation and spents ) Option TRACKED_TIMESTAMP_TENSE added to [ui] section. [ui] TRACKED_TIMESTAMP_TENSE='mixed|hours' Signed-off-by: Sysoev, Vladimir <[email protected]>
1 parent 3b839f8 commit 39ad067

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

modules/setting/ui.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var UI = struct {
3636
OnlyShowRelevantRepos bool
3737
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
3838
PreferredTimestampTense string
39+
TrackedTimestampTense string
3940

4041
AmbiguousUnicodeDetection bool
4142

@@ -89,6 +90,7 @@ var UI = struct {
8990
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
9091
ExploreDefaultSort: "recentupdate",
9192
PreferredTimestampTense: "mixed",
93+
TrackedTimestampTense: "mixed",
9294

9395
AmbiguousUnicodeDetection: true,
9496

@@ -155,6 +157,10 @@ func loadUIFrom(rootCfg ConfigProvider) {
155157
log.Fatal("ui.PREFERRED_TIMESTAMP_TENSE must be either 'mixed' or 'absolute'")
156158
}
157159

160+
if UI.TrackedTimestampTense != "mixed" && UI.TrackedTimestampTense != "hours" {
161+
log.Fatal("ui.TRACKED_TIMESTAMP_TENSE must be either 'mixed' or 'hours'")
162+
}
163+
158164
// OnlyShowRelevantRepos=false is important for many private/enterprise instances,
159165
// because many private repositories do not have "description/topic", users just want to search by their names.
160166
UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)

modules/templates/helper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ func NewFuncMap() template.FuncMap {
6969
// time / number / format
7070
"FileSize": base.FileSize,
7171
"CountFmt": countFmt,
72-
"Sec2Time": util.SecToTime,
72+
"Sec2Time": func() func(any) string {
73+
if setting.UI.TrackedTimestampTense == "hours" {
74+
return util.SecToHours
75+
}
76+
return util.SecToTime
77+
}(),
7378

7479
"TimeEstimateString": timeEstimateString,
7580

modules/util/sec_to_time.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ func SecToTime(durationVal any) string {
6666
return strings.TrimRight(formattedTime, " ")
6767
}
6868

69+
// SecToHours converts an amount of seconds to a human-readable hours string.
70+
// This is sutable for planning and managing timesheets.
71+
func SecToHours(durationVal any) string {
72+
duration, _ := ToInt64(durationVal)
73+
74+
formattedTime := ""
75+
76+
// The following three variables are calculated without depending
77+
// on the previous calculated variables.
78+
hours := (duration / 3600)
79+
minutes := (duration / 60) % 60
80+
81+
formattedTime = formatTime(hours, "hour", formattedTime)
82+
formattedTime = formatTime(minutes, "minute", formattedTime)
83+
84+
// The formatTime() function always appends a space at the end. This will be trimmed
85+
return strings.TrimRight(formattedTime, " ")
86+
}
87+
6988
// formatTime appends the given value to the existing forammattedTime. E.g:
7089
// formattedTime = "1 year"
7190
// input: value = 3, name = "month"

0 commit comments

Comments
 (0)