Skip to content

Commit

Permalink
Tracked time representation modifined with UI settings
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Sysoev, Vladimir committed Jan 17, 2025
1 parent 3b839f8 commit 39ad067
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/setting/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var UI = struct {
OnlyShowRelevantRepos bool
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
PreferredTimestampTense string
TrackedTimestampTense string

AmbiguousUnicodeDetection bool

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

AmbiguousUnicodeDetection: true,

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

if UI.TrackedTimestampTense != "mixed" && UI.TrackedTimestampTense != "hours" {
log.Fatal("ui.TRACKED_TIMESTAMP_TENSE must be either 'mixed' or 'hours'")
}

// 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
7 changes: 6 additions & 1 deletion modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ func NewFuncMap() template.FuncMap {
// time / number / format
"FileSize": base.FileSize,
"CountFmt": countFmt,
"Sec2Time": util.SecToTime,
"Sec2Time": func() func(any) string {
if setting.UI.TrackedTimestampTense == "hours" {
return util.SecToHours
}
return util.SecToTime
}(),

"TimeEstimateString": timeEstimateString,

Expand Down
19 changes: 19 additions & 0 deletions modules/util/sec_to_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ func SecToTime(durationVal any) string {
return strings.TrimRight(formattedTime, " ")
}

// SecToHours converts an amount of seconds to a human-readable hours string.
// This is sutable for planning and managing timesheets.
func SecToHours(durationVal any) string {
duration, _ := ToInt64(durationVal)

formattedTime := ""

// The following three variables are calculated without depending
// on the previous calculated variables.
hours := (duration / 3600)
minutes := (duration / 60) % 60

formattedTime = formatTime(hours, "hour", formattedTime)
formattedTime = formatTime(minutes, "minute", formattedTime)

// The formatTime() function always appends a space at the end. This will be trimmed
return strings.TrimRight(formattedTime, " ")
}

// formatTime appends the given value to the existing forammattedTime. E.g:
// formattedTime = "1 year"
// input: value = 3, name = "month"
Expand Down

0 comments on commit 39ad067

Please sign in to comment.