mirror of
https://github.com/go-gitea/gitea
synced 2025-02-11 01:04:46 +00:00
Dear Gitea team, first of all, thanks for the great work you're doing with this project. I'm planning to introduce Gitea at a client site, and noticed that while there is time recording, there are no project-manager-friendly reports to actually make use of that data, as were also mentioned by others in #4870 #8684 and #13531. Since I had a little time last weekend, I had put together something that I hope to be a useful contribution to this great project (while of course useful for me too). This PR adds a new "Worktime" tab to the Organisation level. There is a date range selector (by default set to the current month), and there are three possible views: - by repository, - by milestone, and - by team member. Happy to receive any feedback! There are several possible future improvements of course (predefined date ranges, charts, a member time sheet, matrix of repos/members, etc) but I hope that even in this relatively simple state this would be useful to lots of people. <img width="1161" alt="Screen Shot 2022-05-25 at 22 12 58" src="https://user-images.githubusercontent.com/118010/170366976-af00c7af-c4f3-4117-86d7-00356d6797a5.png"> Keep up the good work! Kristof --------- Co-authored-by: user <user@kk-git1> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
// Copyright 2022 Gitea. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// SecToHours converts an amount of seconds to a human-readable hours string.
|
|
// This is stable for planning and managing timesheets.
|
|
// Here it only supports hours and minutes, because a work day could contain 6 or 7 or 8 hours.
|
|
// If the duration is less than 1 minute, it will be shown as seconds.
|
|
func SecToHours(durationVal any) string {
|
|
seconds, _ := ToInt64(durationVal)
|
|
hours := seconds / 3600
|
|
minutes := (seconds / 60) % 60
|
|
|
|
formattedTime := ""
|
|
formattedTime = formatTime(hours, "hour", formattedTime)
|
|
formattedTime = formatTime(minutes, "minute", formattedTime)
|
|
|
|
// The formatTime() function always appends a space at the end. This will be trimmed
|
|
if formattedTime == "" && seconds > 0 {
|
|
formattedTime = formatTime(seconds, "second", "")
|
|
}
|
|
return strings.TrimRight(formattedTime, " ")
|
|
}
|
|
|
|
// formatTime appends the given value to the existing forammattedTime. E.g:
|
|
// formattedTime = "1 year"
|
|
// input: value = 3, name = "month"
|
|
// output will be "1 year 3 months "
|
|
func formatTime(value int64, name, formattedTime string) string {
|
|
if value == 1 {
|
|
formattedTime = fmt.Sprintf("%s1 %s ", formattedTime, name)
|
|
} else if value > 1 {
|
|
formattedTime = fmt.Sprintf("%s%d %ss ", formattedTime, value, name)
|
|
}
|
|
return formattedTime
|
|
}
|