An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Fix human-readable minute display https://github.com/siyuan-note/siyuan/pull/18617
OpaqueGlass6ceb9c3007b4
diff --git a/kernel/api/notebook_security_test.go b/kernel/api/notebook_security_test.goindex 048287d692..a94ea99b48 100644--- a/kernel/api/notebook_security_test.go+++ b/kernel/api/notebook_security_test.go@@ -86,6 +86,7 @@ func TestGetNotebookInfoHidesInvisibleNotebookFromReader(t *testing.T) {"1s": "1 second %s","xs": "%d seconds %s","1m": "1 minute %s",+ "xm": "%d minutes %s","xh": "%d hours %s","1h": "1 hour %s","1d": "1 day %s",diff --git a/kernel/util/time.go b/kernel/util/time.goindex bdb77aac3f..669860c23b 100644--- a/kernel/util/time.go+++ b/kernel/util/time.go@@ -228,7 +228,7 @@ func humanizeTimeMagnitudes(lang string) (labels map[string]any, magnitudes []hu{D: 2 * time.Second, Format: labels["1s"].(string), DivBy: 1},{D: time.Minute, Format: labels["xs"].(string), DivBy: time.Second},{D: 2 * time.Minute, Format: labels["1m"].(string), DivBy: 1},- {D: time.Hour, Format: labels["xh"].(string), DivBy: time.Minute},+ {D: time.Hour, Format: labels["xm"].(string), DivBy: time.Minute},{D: 2 * time.Hour, Format: labels["1h"].(string), DivBy: 1},{D: humanize.Day, Format: labels["xh"].(string), DivBy: time.Hour},{D: 2 * humanize.Day, Format: labels["1d"].(string), DivBy: 1},diff --git a/kernel/util/time_test.go b/kernel/util/time_test.gonew file mode 100644index 0000000000..f04f81f48f--- /dev/null+++ b/kernel/util/time_test.go@@ -0,0 +1,74 @@+// SiYuan - From thought to insight, with agents+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package util++import (+ "testing"+ "time"+)++func TestHumanizeRelTimeMinuteMagnitude(t *testing.T) {+ const lang = "humanize-relative-time-test"+ oldTimeLang, hadTimeLang := TimeLangs[lang]+ TimeLangs[lang] = map[string]any{+ "albl": "ago",+ "blbl": "from now",+ "now": "now",+ "1s": "1 second %s",+ "xs": "%d seconds %s",+ "1m": "1 minute %s",+ "xm": "%d minutes %s",+ "1h": "1 hour %s",+ "xh": "%d hours %s",+ "1d": "1 day %s",+ "xd": "%d days %s",+ "1w": "1 week %s",+ "xw": "%d weeks %s",+ "1M": "1 month %s",+ "xM": "%d months %s",+ "1y": "1 year %s",+ "2y": "2 years %s",+ "xy": "%d years %s",+ "max": "a long while %s",+ }+ t.Cleanup(func() {+ if hadTimeLang {+ TimeLangs[lang] = oldTimeLang+ } else {+ delete(TimeLangs, lang)+ }+ })++ start := time.Unix(0, 0)+ tests := []struct {+ name string+ duration time.Duration+ expected string+ }{+ {name: "two minutes", duration: 2 * time.Minute, expected: "2 minutes"},+ {name: "less than one hour", duration: time.Hour - time.Second, expected: "59 minutes"},+ {name: "one hour", duration: time.Hour, expected: "1 hour"},+ }+ for _, test := range tests {+ t.Run(test.name, func(t *testing.T) {+ actual := HumanizeRelTime(start, start.Add(test.duration), lang)+ if actual != test.expected {+ t.Fatalf("unexpected relative time: %q", actual)+ }+ })+ }+}