From 3007f781dca83d883ee3edba3c4bbfb258a25143 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 12 Jun 2023 21:40:47 +0200 Subject: [PATCH 01/26] Add Sec2TrackedTime time-format-func As work-days/-weeks/-years ... differ from country and company, its not practicable to use it as time format --- modules/templates/helper.go | 13 ++++++----- modules/util/sec_to_time.go | 39 ++++++++++++++++++++++++++++---- modules/util/sec_to_time_test.go | 20 ++++++++++++++++ 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 2f2ef44049794..a568ab11d405d 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -66,12 +66,13 @@ func NewFuncMap() template.FuncMap { // ----------------------------------------------------------------- // time / number / format - "FileSize": base.FileSize, - "CountFmt": base.FormatNumberSI, - "TimeSince": timeutil.TimeSince, - "TimeSinceUnix": timeutil.TimeSinceUnix, - "DateTime": timeutil.DateTime, - "Sec2Time": util.SecToTime, + "FileSize": base.FileSize, + "CountFmt": base.FormatNumberSI, + "TimeSince": timeutil.TimeSince, + "TimeSinceUnix": timeutil.TimeSinceUnix, + "DateTime": timeutil.DateTime, + "Sec2Time": util.SecToTime, + "Sec2TrackedTime": util.Sec2TrackedTime, "LoadTimes": func(startTime time.Time) string { return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" }, diff --git a/modules/util/sec_to_time.go b/modules/util/sec_to_time.go index 017ed45f8c040..2798622592a75 100644 --- a/modules/util/sec_to_time.go +++ b/modules/util/sec_to_time.go @@ -9,11 +9,11 @@ import ( ) // SecToTime converts an amount of seconds to a human-readable string. E.g. -// 66s -> 1 minute 6 seconds -// 52410s -> 14 hours 33 minutes -// 563418 -> 6 days 12 hours +// 66s -> 1 minute 6 seconds +// 52410s -> 14 hours 33 minutes +// 563418 -> 6 days 12 hours // 1563418 -> 2 weeks 4 days -// 3937125s -> 1 month 2 weeks +// 3937125s -> 1 month 2 weeks // 45677465s -> 1 year 6 months func SecToTime(duration int64) string { formattedTime := "" @@ -77,3 +77,34 @@ func formatTime(value int64, name, formattedTime string) string { return formattedTime } + +// Sec2TrackedTime converts an amount of seconds to a human-readable string. E.g. +// 66s -> 1 minute 6 seconds +// 52410s -> 14 hours 33 minutes +// 563418s -> 156 hours 30 minutes +// 1563418s -> 434 hours 16 minutes +// 3937125s -> 1093 hours 38 minutes +// 45677465s -> 12688 hours 11 minutes +func Sec2TrackedTime(duration int64) string { + formattedTime := "" + + // The following three variables are calculated without depending + // on the previous calculated variables. + hours := (duration / 3600) + minutes := (duration / 60) % 60 + seconds := duration % 60 + + // Extract only the relevant information of the time + // If the time is greater than a year, it makes no sense to display seconds. + switch { + case hours > 0: + formattedTime = formatTime(hours, "hour", formattedTime) + formattedTime = formatTime(minutes, "minute", formattedTime) + default: + formattedTime = formatTime(minutes, "minute", formattedTime) + formattedTime = formatTime(seconds, "second", formattedTime) + } + + // The formatTime() function always appends a space at the end. This will be trimmed + return strings.TrimRight(formattedTime, " ") +} diff --git a/modules/util/sec_to_time_test.go b/modules/util/sec_to_time_test.go index 4d1213a52c05e..c9d553819c215 100644 --- a/modules/util/sec_to_time_test.go +++ b/modules/util/sec_to_time_test.go @@ -28,3 +28,23 @@ func TestSecToTime(t *testing.T) { assert.Equal(t, "11 months", SecToTime(year-25*day)) assert.Equal(t, "1 year 5 months", SecToTime(year+163*day+10*hour+11*minute+5*second)) } + +func TestSec2TrackedTime(t *testing.T) { + second := int64(1) + minute := 60 * second + hour := 60 * minute + day := 24 * hour + year := 365 * day + + assert.Equal(t, "1 minute 6 seconds", Sec2TrackedTime(minute+6*second)) + assert.Equal(t, "1 hour", Sec2TrackedTime(hour)) + assert.Equal(t, "1 hour", Sec2TrackedTime(hour+second)) + assert.Equal(t, "14 hours 33 minutes", Sec2TrackedTime(14*hour+33*minute+30*second)) + assert.Equal(t, "156 hours 30 minutes", Sec2TrackedTime(6*day+12*hour+30*minute+18*second)) + assert.Equal(t, "434 hours 16 minutes", Sec2TrackedTime((2*7+4)*day+2*hour+16*minute+58*second)) + assert.Equal(t, "672 hours", Sec2TrackedTime(4*7*day)) + assert.Equal(t, "696 hours", Sec2TrackedTime((4*7+1)*day)) + assert.Equal(t, "1093 hours 38 minutes", Sec2TrackedTime((6*7+3)*day+13*hour+38*minute+45*second)) + assert.Equal(t, "8160 hours", Sec2TrackedTime(year-25*day)) + assert.Equal(t, "12682 hours 11 minutes", Sec2TrackedTime(year+163*day+10*hour+11*minute+5*second)) +} From 3c4ab6c2d9a30d59e0825fc367858eb0e7dee676 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 12 Jun 2023 22:20:52 +0200 Subject: [PATCH 02/26] use in templates --- templates/repo/issue/milestones.tmpl | 2 +- templates/repo/issue/view_content/sidebar.tmpl | 2 +- templates/shared/issuelist.tmpl | 2 +- templates/user/dashboard/milestones.tmpl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index d7e782e20d62a..20d8323689e26 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -82,7 +82,7 @@ {{$.locale.PrettyNumber .NumOpenIssues}} {{$.locale.Tr "repo.issues.open_title"}} {{svg "octicon-check" 16 "gt-mr-3"}} {{$.locale.PrettyNumber .NumClosedIssues}} {{$.locale.Tr "repo.issues.closed_title"}} - {{if .TotalTrackedTime}}{{svg "octicon-clock"}} {{.TotalTrackedTime|Sec2Time}}{{end}} + {{if .TotalTrackedTime}}{{svg "octicon-clock"}} {{.TotalTrackedTime|Sec2TrackedTime}}{{end}} {{if .UpdatedUnix}}{{svg "octicon-clock"}} {{$.locale.Tr "repo.milestones.update_ago" (TimeSinceUnix .UpdatedUnix $.locale) | Safe}}{{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 23e2c18547cf5..14d8a874847c2 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -330,7 +330,7 @@ {{if gt (len .WorkingUsers) 0}}
- {{.locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime | Sec2Time) | Safe}} + {{.locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime|Sec2TrackedTime) | Safe}}
{{range $user, $trackedtime := .WorkingUsers}}
diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 8ae00a2ba944c..151366180236d 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -126,7 +126,7 @@ {{if .TotalTrackedTime}}
{{svg "octicon-clock" 16 "gt-mr-2"}} - {{.TotalTrackedTime | Sec2Time}} + {{.TotalTrackedTime | Sec2TrackedTime}}
{{end}} {{if .Assignees}} diff --git a/templates/user/dashboard/milestones.tmpl b/templates/user/dashboard/milestones.tmpl index 372d3c7b99f9a..a0d72fc041da9 100644 --- a/templates/user/dashboard/milestones.tmpl +++ b/templates/user/dashboard/milestones.tmpl @@ -102,7 +102,7 @@ {{svg "octicon-check" 16 "gt-mr-3"}} {{$.locale.PrettyNumber .NumClosedIssues}} {{$.locale.Tr "repo.issues.closed_title"}} {{if .TotalTrackedTime}} - {{svg "octicon-clock"}} {{.TotalTrackedTime|Sec2Time}} + {{svg "octicon-clock"}} {{.TotalTrackedTime|Sec2TrackedTime}} {{end}}
From 201e227ecc04669e3135ec612f20fc3ecddd2249 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 12 Jun 2023 21:27:05 +0200 Subject: [PATCH 03/26] Also apply it for sidebar in issue/pull view for single users --- models/issues/tracked_time.go | 6 +++--- models/issues/tracked_time_test.go | 12 ++++++------ templates/repo/issue/view_content/sidebar.tmpl | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index ac65d654f20a3..1fc32111ba34d 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -200,7 +200,7 @@ func addTime(ctx context.Context, user *user_model.User, issue *Issue, amount in } // TotalTimes returns the spent time for each user by an issue -func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string, error) { +func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]int64, error) { trackedTimes, err := GetTrackedTimes(db.DefaultContext, options) if err != nil { return nil, err @@ -211,7 +211,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string, totalTimesByUser[t.UserID] += t.Time } - totalTimes := make(map[*user_model.User]string) + totalTimes := make(map[*user_model.User]int64) // Fetching User and making time human readable for userID, total := range totalTimesByUser { user, err := user_model.GetUserByID(db.DefaultContext, userID) @@ -221,7 +221,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string, } return nil, err } - totalTimes[user] = util.SecToTime(total) + totalTimes[user] = total } return totalTimes, nil } diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go index 99b977cca5264..baa170b201265 100644 --- a/models/issues/tracked_time_test.go +++ b/models/issues/tracked_time_test.go @@ -86,8 +86,8 @@ func TestTotalTimes(t *testing.T) { assert.NoError(t, err) assert.Len(t, total, 1) for user, time := range total { - assert.Equal(t, int64(1), user.ID) - assert.Equal(t, "6 minutes 40 seconds", time) + assert.EqualValues(t, 1, user.ID) + assert.EqualValues(t, 400, time) } total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 2}) @@ -95,9 +95,9 @@ func TestTotalTimes(t *testing.T) { assert.Len(t, total, 2) for user, time := range total { if user.ID == 2 { - assert.Equal(t, "1 hour 1 minute", time) + assert.EqualValues(t, 3662, time) } else if user.ID == 1 { - assert.Equal(t, "20 seconds", time) + assert.EqualValues(t, 20, time) } else { assert.Error(t, assert.AnError) } @@ -107,8 +107,8 @@ func TestTotalTimes(t *testing.T) { assert.NoError(t, err) assert.Len(t, total, 1) for user, time := range total { - assert.Equal(t, int64(2), user.ID) - assert.Equal(t, "1 second", time) + assert.EqualValues(t, 2, user.ID) + assert.EqualValues(t, 1, time) } total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 4}) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 14d8a874847c2..0fada6ac90384 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -330,7 +330,7 @@ {{if gt (len .WorkingUsers) 0}}
- {{.locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime|Sec2TrackedTime) | Safe}} + {{.locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime | Sec2Time) | Safe}}
{{range $user, $trackedtime := .WorkingUsers}}
@@ -340,7 +340,7 @@
{{template "shared/user/authorlink" $user}}
- {{$trackedtime}} + {{$trackedtime|Sec2TrackedTime}}
From 645fe79af5741f0c831f25a5e86e680a8aee6955 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 12 Jun 2023 22:53:10 +0200 Subject: [PATCH 04/26] add --- templates/repo/issue/view_content/sidebar.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 0fada6ac90384..32d0e01b7889c 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -330,7 +330,7 @@ {{if gt (len .WorkingUsers) 0}}
- {{.locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime | Sec2Time) | Safe}} + {{.locale.Tr "repo.issues.time_spent_from_all_authors" ($.Issue.TotalTrackedTime|Sec2TrackedTime) | Safe}}
{{range $user, $trackedtime := .WorkingUsers}}
From 4690b36ea1658a16610dddc296ac5c78b3a64389 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 12 Jun 2023 23:12:26 +0200 Subject: [PATCH 05/26] also use it for timeline comments --- models/issues/stopwatch.go | 4 ++-- models/issues/tracked_time.go | 6 +++--- routers/web/repo/issue_timetrack.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/issues/stopwatch.go b/models/issues/stopwatch.go index c8cd5ad33f26a..b75383d192a0c 100644 --- a/models/issues/stopwatch.go +++ b/models/issues/stopwatch.go @@ -62,7 +62,7 @@ func (s Stopwatch) Seconds() int64 { // Duration returns a human-readable duration string based on local server time func (s Stopwatch) Duration() string { - return util.SecToTime(s.Seconds()) + return util.Sec2TrackedTime(s.Seconds()) } func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) { @@ -215,7 +215,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss Doer: user, Issue: issue, Repo: issue.Repo, - Content: util.SecToTime(timediff), + Content: util.Sec2TrackedTime(timediff), Type: CommentTypeStopTracking, TimeID: tt.ID, }); err != nil { diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index 1fc32111ba34d..03558fda74a79 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -176,7 +176,7 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim Issue: issue, Repo: issue.Repo, Doer: user, - Content: util.SecToTime(amount), + Content: util.Sec2TrackedTime(amount), Type: CommentTypeAddTimeManual, TimeID: t.ID, }); err != nil { @@ -254,7 +254,7 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { Issue: issue, Repo: issue.Repo, Doer: user, - Content: "- " + util.SecToTime(removedTime), + Content: "- " + util.Sec2TrackedTime(removedTime), Type: CommentTypeDeleteTimeManual, }); err != nil { return err @@ -283,7 +283,7 @@ func DeleteTime(t *TrackedTime) error { Issue: t.Issue, Repo: t.Issue.Repo, Doer: t.User, - Content: "- " + util.SecToTime(t.Time), + Content: "- " + util.Sec2TrackedTime(t.Time), Type: CommentTypeDeleteTimeManual, }); err != nil { return err diff --git a/routers/web/repo/issue_timetrack.go b/routers/web/repo/issue_timetrack.go index 7dc7d0797dc0c..2f81e4689091a 100644 --- a/routers/web/repo/issue_timetrack.go +++ b/routers/web/repo/issue_timetrack.go @@ -82,6 +82,6 @@ func DeleteTime(c *context.Context) { return } - c.Flash.Success(c.Tr("repo.issues.del_time_history", util.SecToTime(t.Time))) + c.Flash.Success(c.Tr("repo.issues.del_time_history", util.Sec2TrackedTime(t.Time))) c.Redirect(issue.Link()) } From 7d41418e734e191102c83ac72355af63e199b45f Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 19 Jun 2023 20:48:52 +0200 Subject: [PATCH 06/26] frontend: rm dep "pretty-ms" --- package-lock.json | 26 -------------------------- package.json | 1 - 2 files changed, 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index e808ccf2a8ffd..a04de9ddfa382 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,6 @@ "monaco-editor": "0.39.0", "monaco-editor-webpack-plugin": "7.0.1", "pdfobject": "2.2.12", - "pretty-ms": "8.0.0", "sortablejs": "1.15.0", "swagger-ui-dist": "5.0.0", "throttle-debounce": "5.0.0", @@ -8143,17 +8142,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/parse-ms": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-3.0.0.tgz", - "integrity": "sha512-Tpb8Z7r7XbbtBTrM9UhpkzzaMrqA2VXMT3YChzYltwV3P3pM6t8wl7TvpMnSTosz1aQAdVib7kdoys7vYOPerw==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/parse5": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", @@ -8560,20 +8548,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/pretty-ms": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-8.0.0.tgz", - "integrity": "sha512-ASJqOugUF1bbzI35STMBUpZqdfYKlJugy6JBziGi2EE+AL5JPJGSzvpeVXojxrr0ViUYoToUjb5kjSEGf7Y83Q==", - "dependencies": { - "parse-ms": "^3.0.0" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/printable-characters": { "version": "1.0.42", "resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz", diff --git a/package.json b/package.json index 0701862cc2a65..c8c815016344c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "monaco-editor": "0.39.0", "monaco-editor-webpack-plugin": "7.0.1", "pdfobject": "2.2.12", - "pretty-ms": "8.0.0", "sortablejs": "1.15.0", "swagger-ui-dist": "5.0.0", "throttle-debounce": "5.0.0", From 82bb7ddfbf07fe5633dbcd63b36b302258d0789f Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 19 Jun 2023 23:31:35 +0200 Subject: [PATCH 07/26] use Sec2TrackedTime for stowpatch init too --- templates/base/head_navbar.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index e46e276ed02e3..92de31d86070e 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -88,7 +88,7 @@ {{svg "octicon-issue-opened" 16 "gt-mr-3"}} {{.ActiveStopwatch.RepoSlug}}#{{.ActiveStopwatch.IssueIndex}} - {{if .ActiveStopwatch}}{{Sec2Time .ActiveStopwatch.Seconds}}{{end}} + {{if .ActiveStopwatch}}{{Sec2TrackedTime .ActiveStopwatch.Seconds}}{{end}}
From 99a50f16b1d09e7ee314ae0a2a949dbc084c8399 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 19 Jun 2023 23:57:52 +0200 Subject: [PATCH 08/26] port util.Sec2TrackedTime to javaScript --- web_src/js/utils/time.js | 27 +++++++++++++++++++++++++++ web_src/js/utils/time.test.js | 13 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 web_src/js/utils/time.js create mode 100644 web_src/js/utils/time.test.js diff --git a/web_src/js/utils/time.js b/web_src/js/utils/time.js new file mode 100644 index 0000000000000..14df2c76b7a16 --- /dev/null +++ b/web_src/js/utils/time.js @@ -0,0 +1,27 @@ +export function formatTrackedTime(duration) { + let formattedTime = ''; + + const hours = Math.floor(duration / 3600); + const minutes = Math.floor((duration / 60) % 60); + const seconds = duration % 60; + + if (hours > 0) { + formattedTime = formatTime(hours, 'hour', formattedTime); + formattedTime = formatTime(minutes, 'minute', formattedTime); + } else { + formattedTime = formatTime(minutes, 'minute', formattedTime); + formattedTime = formatTime(seconds, 'second', formattedTime); + } + + formattedTime = formattedTime.trimEnd(); + return formattedTime; +} + +function formatTime(value, name, formattedTime) { + if (value === 1) { + formattedTime = `${formattedTime}1 ${name} `; + } else if (value > 1) { + formattedTime = `${formattedTime}${value} ${name}s `; + } + return formattedTime; +} diff --git a/web_src/js/utils/time.test.js b/web_src/js/utils/time.test.js new file mode 100644 index 0000000000000..ec8991d0ee7df --- /dev/null +++ b/web_src/js/utils/time.test.js @@ -0,0 +1,13 @@ +import {test, expect} from 'vitest'; +import {formatTrackedTime} from './time.js'; + +test('formatTrackedTime', () => { + expect(formatTrackedTime('')).toEqual(''); + expect(formatTrackedTime('0')).toEqual(''); + expect(formatTrackedTime('66')).toEqual('1 minute 6 seconds'); + expect(formatTrackedTime('52410')).toEqual('14 hours 33 minutes'); + expect(formatTrackedTime('563418')).toEqual('156 hours 30 minutes'); + expect(formatTrackedTime('1563418')).toEqual('434 hours 16 minutes'); + expect(formatTrackedTime('3937125')).toEqual('1093 hours 38 minutes'); + expect(formatTrackedTime('45677465')).toEqual('12688 hours 11 minutes'); +}); From 4bbfa26c504e695661cdf23a1c450158c427fe0b Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Mon, 19 Jun 2023 23:32:18 +0200 Subject: [PATCH 09/26] create time.js in utils and use it --- web_src/js/features/stopwatch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/stopwatch.js b/web_src/js/features/stopwatch.js index f43014fec5b7d..d864f3175e97c 100644 --- a/web_src/js/features/stopwatch.js +++ b/web_src/js/features/stopwatch.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import prettyMilliseconds from 'pretty-ms'; +import {formatTrackedTime} from '../utils/time.js'; import {createTippy} from '../modules/tippy.js'; const {appSubUrl, csrfToken, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config; @@ -155,7 +155,7 @@ function updateStopwatchTime(seconds) { const start = Date.now(); const updateUi = () => { const delta = Date.now() - start; - const dur = prettyMilliseconds(secs * 1000 + delta, {compact: true}); + const dur = formatTrackedTime(secs * 1000 + delta); $stopwatch.text(dur); }; updateUi(); From acb7c3fe36ff31e931cb7910ea9f7dfac45cbd94 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 00:10:37 +0200 Subject: [PATCH 10/26] fix --- web_src/js/features/stopwatch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/stopwatch.js b/web_src/js/features/stopwatch.js index d864f3175e97c..39926cb16b6e2 100644 --- a/web_src/js/features/stopwatch.js +++ b/web_src/js/features/stopwatch.js @@ -154,8 +154,8 @@ function updateStopwatchTime(seconds) { const $stopwatch = $('.stopwatch-time'); const start = Date.now(); const updateUi = () => { - const delta = Date.now() - start; - const dur = formatTrackedTime(secs * 1000 + delta); + const delta = (Date.now() - start) / 1000; + const dur = formatTrackedTime(secs + delta); $stopwatch.text(dur); }; updateUi(); From 868ae8080b0d8ee2ac1b8d28a6bd751af7bc4f66 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 00:18:57 +0200 Subject: [PATCH 11/26] ignore ms --- web_src/js/utils/time.js | 3 ++- web_src/js/utils/time.test.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/web_src/js/utils/time.js b/web_src/js/utils/time.js index 14df2c76b7a16..1edf8040eeefc 100644 --- a/web_src/js/utils/time.js +++ b/web_src/js/utils/time.js @@ -1,6 +1,7 @@ -export function formatTrackedTime(duration) { +export function formatTrackedTime(durationSec) { let formattedTime = ''; + const duration = Math.floor(durationSec / 1); const hours = Math.floor(duration / 3600); const minutes = Math.floor((duration / 60) % 60); const seconds = duration % 60; diff --git a/web_src/js/utils/time.test.js b/web_src/js/utils/time.test.js index ec8991d0ee7df..d8b220622e0f1 100644 --- a/web_src/js/utils/time.test.js +++ b/web_src/js/utils/time.test.js @@ -10,4 +10,6 @@ test('formatTrackedTime', () => { expect(formatTrackedTime('1563418')).toEqual('434 hours 16 minutes'); expect(formatTrackedTime('3937125')).toEqual('1093 hours 38 minutes'); expect(formatTrackedTime('45677465')).toEqual('12688 hours 11 minutes'); + expect(formatTrackedTime(1.333)).toEqual('1 second'); + expect(formatTrackedTime(1.999)).toEqual('1 second'); }); From 64778073a4d91e8c7ec79f97c5f947993bc4cb19 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 01:02:22 +0200 Subject: [PATCH 12/26] use old format for API --- models/issues/stopwatch.go | 5 ----- services/convert/issue.go | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/models/issues/stopwatch.go b/models/issues/stopwatch.go index b75383d192a0c..a51f4cff7f072 100644 --- a/models/issues/stopwatch.go +++ b/models/issues/stopwatch.go @@ -60,11 +60,6 @@ func (s Stopwatch) Seconds() int64 { return int64(timeutil.TimeStampNow() - s.CreatedUnix) } -// Duration returns a human-readable duration string based on local server time -func (s Stopwatch) Duration() string { - return util.Sec2TrackedTime(s.Seconds()) -} - func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) { sw = new(Stopwatch) exists, err = db.GetEngine(ctx). diff --git a/services/convert/issue.go b/services/convert/issue.go index bcb1618e8faf3..42ab19165c720 100644 --- a/services/convert/issue.go +++ b/services/convert/issue.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" ) // ToAPIIssue converts an Issue to API format @@ -164,7 +165,7 @@ func ToStopWatches(sws []*issues_model.Stopwatch) (api.StopWatches, error) { result = append(result, api.StopWatch{ Created: sw.CreatedUnix.AsTime(), Seconds: sw.Seconds(), - Duration: sw.Duration(), + Duration: util.SecToTime(sw.Seconds()), IssueIndex: issue.Index, IssueTitle: issue.Title, RepoOwnerName: repo.OwnerName, From 848c0dd76867a1046faecffef5f82550273c0b01 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 01:03:12 +0200 Subject: [PATCH 13/26] store timestamp instead of string for CommentTypeStopTracking & CommentTypeAddTimeManual --- models/issues/stopwatch.go | 2 +- models/issues/tracked_time.go | 3 ++- modules/util/sec_to_time.go | 4 ++++ routers/web/repo/issue.go | 7 +++++++ templates/repo/issue/view_content/comments.tmpl | 4 ++-- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/models/issues/stopwatch.go b/models/issues/stopwatch.go index a51f4cff7f072..b9c2bb963ab27 100644 --- a/models/issues/stopwatch.go +++ b/models/issues/stopwatch.go @@ -210,7 +210,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss Doer: user, Issue: issue, Repo: issue.Repo, - Content: util.Sec2TrackedTime(timediff), + Content: fmt.Sprintf("|%d", timediff), Type: CommentTypeStopTracking, TimeID: tt.ID, }); err != nil { diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index f0c70be6d4b6c..7073670256caf 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -6,6 +6,7 @@ package issues import ( "context" "errors" + "fmt" "time" "code.gitea.io/gitea/models/db" @@ -176,7 +177,7 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim Issue: issue, Repo: issue.Repo, Doer: user, - Content: util.Sec2TrackedTime(amount), + Content: fmt.Sprintf("|%d", amount), Type: CommentTypeAddTimeManual, TimeID: t.ID, }); err != nil { diff --git a/modules/util/sec_to_time.go b/modules/util/sec_to_time.go index 2798622592a75..cd175b9b0c283 100644 --- a/modules/util/sec_to_time.go +++ b/modules/util/sec_to_time.go @@ -108,3 +108,7 @@ func Sec2TrackedTime(duration int64) string { // The formatTime() function always appends a space at the end. This will be trimmed return strings.TrimRight(formattedTime, " ") } + +func TimeToSec(time string) int64 { + return 1243 // TODO +} diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 49ba753a7d34e..be2548d89d09a 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1650,6 +1650,13 @@ func ViewIssue(ctx *context.Context) { comment.Type == issues_model.CommentTypeStopTracking { // drop error since times could be pruned from DB.. _ = comment.LoadTime() + // migrate old string based to timestamp on demand + if comment.Content[0] != '|' { + comment.Content = fmt.Sprint(util.TimeToSec(comment.Content)) + // TODO: decide if we should save them to db back so we don't need to write a migration and convert it over time + } else if comment.Content != "" { + comment.Content = comment.Content[1:] + } } if comment.Type == issues_model.CommentTypeClose || comment.Type == issues_model.CommentTypeMergePull { diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index bfcd292f44c32..781a13b9703e0 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -263,7 +263,7 @@ {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}}
{{svg "octicon-clock"}} - {{.Content}} + {{.Content|Sec2TrackedTime}}
{{else if eq .Type 14}} @@ -277,7 +277,7 @@ {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}}
{{svg "octicon-clock"}} - {{.Content}} + {{.Content|Sec2TrackedTime}}
{{else if eq .Type 15}} From 95caebf459139ada093fe21d765c9d19c813b497 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 06:57:24 +0200 Subject: [PATCH 14/26] store and use seconds for timeline time comments PS: we can not migrate back as the old value was a one-way conversion --- modules/util/sec_to_time.go | 4 ---- routers/web/repo/issue.go | 7 ++++--- templates/repo/issue/view_content/comments.tmpl | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/util/sec_to_time.go b/modules/util/sec_to_time.go index cd175b9b0c283..2798622592a75 100644 --- a/modules/util/sec_to_time.go +++ b/modules/util/sec_to_time.go @@ -108,7 +108,3 @@ func Sec2TrackedTime(duration int64) string { // The formatTime() function always appends a space at the end. This will be trimmed return strings.TrimRight(formattedTime, " ") } - -func TimeToSec(time string) int64 { - return 1243 // TODO -} diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index be2548d89d09a..1e5160a4eaea4 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1650,11 +1650,12 @@ func ViewIssue(ctx *context.Context) { comment.Type == issues_model.CommentTypeStopTracking { // drop error since times could be pruned from DB.. _ = comment.LoadTime() - // migrate old string based to timestamp on demand if comment.Content[0] != '|' { - comment.Content = fmt.Sprint(util.TimeToSec(comment.Content)) - // TODO: decide if we should save them to db back so we don't need to write a migration and convert it over time + // handle old time comments that have formatted text stored + comment.RenderedContent = comment.Content + comment.Content = "" } else if comment.Content != "" { + // else it's just a duration in seconds to pass on to the frontend comment.Content = comment.Content[1:] } } diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 781a13b9703e0..a57a5b1721103 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -263,7 +263,12 @@ {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}}
{{svg "octicon-clock"}} - {{.Content|Sec2TrackedTime}} + {{if .RenderedContent}} + {{/* compatibility with time comments made before v1.21 */}} + {{.RenderedContent}} + {{else}} + {{.Content|Sec2TrackedTime}} + {{end}}
{{else if eq .Type 14}} @@ -277,7 +282,12 @@ {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}}
{{svg "octicon-clock"}} - {{.Content|Sec2TrackedTime}} + {{if .RenderedContent}} + {{/* compatibility with time comments made before v1.21 */}} + {{.RenderedContent}} + {{else}} + {{.Content|Sec2TrackedTime}} + {{end}}
{{else if eq .Type 15}} From 4df03a346579fd013615244fffca1a0345046a47 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 15:32:58 +0200 Subject: [PATCH 15/26] store and use seconds for timeline time comments this will alow us to fully localize it later PS: we can not migrate back as the old value was a one-way conversion --- models/issues/tracked_time.go | 3 ++- templates/repo/issue/view_content/comments.tmpl | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index 698014afeba54..a16d0ac90bc0e 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -6,6 +6,7 @@ package issues import ( "context" "errors" + "fmt" "time" "code.gitea.io/gitea/models/db" @@ -176,7 +177,7 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim Issue: issue, Repo: issue.Repo, Doer: user, - Content: util.SecToTime(amount), + Content: fmt.Sprintf("|%d", amount), Type: CommentTypeAddTimeManual, TimeID: t.ID, }); err != nil { diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index bfcd292f44c32..a37ad8c60adb2 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -263,7 +263,12 @@ {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}}
{{svg "octicon-clock"}} - {{.Content}} + {{if .RenderedContent}} + {{/* compatibility with time comments made before v1.21 */}} + {{.RenderedContent}} + {{else}} + {{.Content|Sec2Time}} + {{end}}
{{else if eq .Type 14}} @@ -277,7 +282,12 @@ {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}}
{{svg "octicon-clock"}} - {{.Content}} + {{if .RenderedContent}} + {{/* compatibility with time comments made before v1.21 */}} + {{.RenderedContent}} + {{else}} + {{.Content|Sec2Time}} + {{end}}
{{else if eq .Type 15}} From c0e96f3bec75c4586bae8f8b362343d6f5ec0362 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 15:48:53 +0200 Subject: [PATCH 16/26] next --- models/issues/tracked_time.go | 4 ++-- routers/web/repo/issue.go | 17 +++++++++++++++++ templates/repo/issue/view_content/comments.tmpl | 7 ++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index a16d0ac90bc0e..023c0141860bc 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -255,7 +255,7 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { Issue: issue, Repo: issue.Repo, Doer: user, - Content: "- " + util.SecToTime(removedTime), + Content: fmt.Sprint(removedTime), Type: CommentTypeDeleteTimeManual, }); err != nil { return err @@ -284,7 +284,7 @@ func DeleteTime(t *TrackedTime) error { Issue: t.Issue, Repo: t.Issue.Repo, Doer: t.User, - Content: "- " + util.SecToTime(t.Time), + Content: fmt.Sprint(t.Time), Type: CommentTypeDeleteTimeManual, }); err != nil { return err diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 49ba753a7d34e..57168ac1989f1 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1650,6 +1650,23 @@ func ViewIssue(ctx *context.Context) { comment.Type == issues_model.CommentTypeStopTracking { // drop error since times could be pruned from DB.. _ = comment.LoadTime() + if comment.Content != "" { + if comment.Content[0] != '|' { + // handle old time comments that have formatted text stored + comment.RenderedContent = comment.Content + comment.Content = "" + } else { + // else it's just a duration in seconds to pass on to the frontend + comment.Content = comment.Content[1:] + } + } + } else if comment.Type == issues_model.CommentTypeDeleteTimeManual && comment.Content != "" { + if comment.Content[0] == '-' { + // handle old time comments that have formatted text stored + comment.RenderedContent = comment.Content + comment.Content = "" + } + // else it's just a duration in seconds to pass on to the frontend } if comment.Type == issues_model.CommentTypeClose || comment.Type == issues_model.CommentTypeMergePull { diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index a37ad8c60adb2..d9c9cda7a249d 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -686,7 +686,12 @@
{{svg "octicon-clock"}} - {{.Content}} + {{if .RenderedContent}} + {{/* compatibility with time comments made before v1.21 */}} + {{.RenderedContent}} + {{else}} + - {{.Content|Sec2Time}} + {{end}}
{{else if eq .Type 27}} From 5e0e77c3e54974d04e65c6c7997095d59e2e13a8 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 15:59:57 +0200 Subject: [PATCH 17/26] need helper until we convert time in frontend --- modules/templates/util_string.go | 6 ++++++ templates/repo/issue/view_content/comments.tmpl | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index 459380aee5312..02a2a630c3a5d 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -4,6 +4,7 @@ package templates import ( + "strconv" "strings" "code.gitea.io/gitea/modules/base" @@ -36,3 +37,8 @@ func (su *StringUtils) Join(a []string, sep string) string { func (su *StringUtils) EllipsisString(s string, max int) string { return base.EllipsisString(s, max) } + +func (su *StringUtils) ToInt(s string, max int) int64 { + i, _ := strconv.ParseInt(s, 10, 64) + return i +} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index d9c9cda7a249d..7e8e6bb61d1eb 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -267,7 +267,7 @@ {{/* compatibility with time comments made before v1.21 */}} {{.RenderedContent}} {{else}} - {{.Content|Sec2Time}} + {{.Content|StringUtils.ToInt|Sec2Time}} {{end}} @@ -286,7 +286,7 @@ {{/* compatibility with time comments made before v1.21 */}} {{.RenderedContent}} {{else}} - {{.Content|Sec2Time}} + {{.Content|StringUtils.ToInt|Sec2Time}} {{end}} @@ -690,7 +690,7 @@ {{/* compatibility with time comments made before v1.21 */}} {{.RenderedContent}} {{else}} - - {{.Content|Sec2Time}} + - {{.Content|StringUtils.ToInt|Sec2Time}} {{end}} From 3b4a0b81456ff4096cc45e94bcaa15a659807c5b Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 16:02:21 +0200 Subject: [PATCH 18/26] ... --- modules/templates/util_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index 02a2a630c3a5d..b19c45df5172e 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -38,7 +38,7 @@ func (su *StringUtils) EllipsisString(s string, max int) string { return base.EllipsisString(s, max) } -func (su *StringUtils) ToInt(s string, max int) int64 { +func (su *StringUtils) ToInt(s string) int64 { i, _ := strconv.ParseInt(s, 10, 64) return i } From b2cc1eed9699c19ac30edb16864d98213dfbba49 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 16:35:01 +0200 Subject: [PATCH 19/26] non breaking API --- services/convert/issue_comment.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/services/convert/issue_comment.go b/services/convert/issue_comment.go index 2810c6c9bc91b..476de0bb43e99 100644 --- a/services/convert/issue_comment.go +++ b/services/convert/issue_comment.go @@ -5,12 +5,14 @@ package convert import ( "context" + "strconv" issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" ) // ToComment converts a issues_model.Comment to the api.Comment format @@ -66,6 +68,22 @@ func ToTimelineComment(ctx context.Context, c *issues_model.Comment, doer *user_ return nil } + // for time tracking comments, we now store seconds + // so convert them for the API + if c.Content != "" { + if (c.Type == issues_model.CommentTypeAddTimeManual || + c.Type == issues_model.CommentTypeStopTracking) && + c.Content[0] == '|' { + i, _ := strconv.ParseInt(c.Content[1:], 10, 64) + c.Content = util.SecToTime(i) + } else if c.Type == issues_model.CommentTypeDeleteTimeManual { + if c.Content[0] != '-' { + i, _ := strconv.ParseInt(c.Content, 10, 64) + c.Content = "- " + util.SecToTime(i) + } + } + } + comment := &api.TimelineComment{ ID: c.ID, Type: c.Type.String(), From 99fbd23f1fcbae07428d0226ff5cd1f6dc57ba9a Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 16:38:01 +0200 Subject: [PATCH 20/26] code format --- services/convert/issue_comment.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/convert/issue_comment.go b/services/convert/issue_comment.go index 476de0bb43e99..15152e16f1780 100644 --- a/services/convert/issue_comment.go +++ b/services/convert/issue_comment.go @@ -76,11 +76,10 @@ func ToTimelineComment(ctx context.Context, c *issues_model.Comment, doer *user_ c.Content[0] == '|' { i, _ := strconv.ParseInt(c.Content[1:], 10, 64) c.Content = util.SecToTime(i) - } else if c.Type == issues_model.CommentTypeDeleteTimeManual { - if c.Content[0] != '-' { - i, _ := strconv.ParseInt(c.Content, 10, 64) - c.Content = "- " + util.SecToTime(i) - } + } else if c.Type == issues_model.CommentTypeDeleteTimeManual && + c.Content[0] != '-' { + i, _ := strconv.ParseInt(c.Content, 10, 64) + c.Content = "- " + util.SecToTime(i) } } From 81ba06a2da8ffa9e10965aef6d227c690f0eea44 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 20 Jun 2023 17:26:51 +0200 Subject: [PATCH 21/26] adjust test --- models/issues/tracked_time_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go index baa170b201265..37ba1cfdc4903 100644 --- a/models/issues/tracked_time_test.go +++ b/models/issues/tracked_time_test.go @@ -35,7 +35,7 @@ func TestAddTime(t *testing.T) { assert.Equal(t, int64(3661), tt.Time) comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddTimeManual, PosterID: 3, IssueID: 1}) - assert.Equal(t, "1 hour 1 minute", comment.Content) + assert.Equal(t, "|3661", comment.Content) } func TestGetTrackedTimes(t *testing.T) { From e61e1eb27bbace6972f3bf41cb5aa112e1f41396 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Fri, 23 Jun 2023 17:28:17 +0200 Subject: [PATCH 22/26] clean --- modules/templates/util_string.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index b19c45df5172e..459380aee5312 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -4,7 +4,6 @@ package templates import ( - "strconv" "strings" "code.gitea.io/gitea/modules/base" @@ -37,8 +36,3 @@ func (su *StringUtils) Join(a []string, sep string) string { func (su *StringUtils) EllipsisString(s string, max int) string { return base.EllipsisString(s, max) } - -func (su *StringUtils) ToInt(s string) int64 { - i, _ := strconv.ParseInt(s, 10, 64) - return i -} From 358cb5eff3128c8548ab4c32221e04f45a87c6af Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Fri, 23 Jun 2023 18:06:52 +0200 Subject: [PATCH 23/26] wip --- models/user/setting_keys.go | 2 ++ routers/web/user/setting/profile.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/models/user/setting_keys.go b/models/user/setting_keys.go index 72b3974eee435..0c4e1ee49f47b 100644 --- a/models/user/setting_keys.go +++ b/models/user/setting_keys.go @@ -14,4 +14,6 @@ const ( UserActivityPubPrivPem = "activitypub.priv_pem" // UserActivityPubPubPem is user's public key UserActivityPubPubPem = "activitypub.pub_pem" + // SettingsKeyTrackedTimeMaxUnit set how tracked time values are converted from seconds to sting + SettingsKeyTrackedTimeMaxUnit = "tracked_time.max_unit" ) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 47066d5e384ef..5cbc85cac3f9c 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -351,6 +351,12 @@ func Appearance(ctx *context.Context) { return forms.IsUserHiddenCommentTypeGroupChecked(commentTypeGroup, hiddenCommentTypes) } + ctx.Data["TrackedTimeMaxUnit"], err = user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyTrackedTimeMaxUnit, "year") // TODO: make default set via system? + if err != nil { + ctx.ServerError("GetUserSetting", err) + return + } + ctx.HTML(http.StatusOK, tplSettingsAppearance) } From bbdd894993cca83620c1758bb9ca1f37d31d3c5f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 21 Oct 2023 00:09:26 +0200 Subject: [PATCH 24/26] Update filters.tmpl --- templates/repo/issue/filters.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/filters.tmpl b/templates/repo/issue/filters.tmpl index 1d200e23b7a7f..2c864ae732606 100644 --- a/templates/repo/issue/filters.tmpl +++ b/templates/repo/issue/filters.tmpl @@ -9,7 +9,7 @@ {{end}} From cc1419148f71137d04ff91ec1bf1673c26c10a2f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 21 Oct 2023 00:10:31 +0200 Subject: [PATCH 25/26] Update list.tmpl --- templates/repo/issue/list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 012b613fbf879..6a8b0daa6f223 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -39,7 +39,7 @@ {{end}} From 311ac33cf2b9c78466bb01a01b4dc203100293f7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 21 Oct 2023 00:11:28 +0200 Subject: [PATCH 26/26] Update milestone_issues.tmpl --- templates/repo/issue/milestone_issues.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index ea19518efac83..bd99d1f2f5a7d 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -49,7 +49,7 @@ {{if .TotalTrackedTime}}
{{svg "octicon-clock"}} - {{.TotalTrackedTime | Sec2Time}} + {{.TotalTrackedTime | Sec2TrackedTime}}
{{end}}