summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorJonas Östanbäck <cez81@users.noreply.github.com>2017-05-29 09:35:47 +0200
committerBo-Yi Wu <appleboy.tw@gmail.com>2017-05-29 02:35:47 -0500
commitb93568cce4717abd97f1f92341ce9fdf331a7e98 (patch)
tree9234c805be991b8d1876bb4641d07b1f6f1251c8 /modules/base
parente0c6ab2d44d17b72a7ea6f8b4c829c42baeaae3b (diff)
downloadgitea-b93568cce4717abd97f1f92341ce9fdf331a7e98.tar.gz
gitea-b93568cce4717abd97f1f92341ce9fdf331a7e98.zip
xxx_active_code_live setting in printed in hours and minutes instead … (#1814)
* xxx_active_code_live setting in printed in hours and minutes instead of just hours * Update app.ini description of xxx_code_lives settings
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go7
-rw-r--r--modules/base/tool_test.go14
2 files changed, 21 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 32987a0b8b..3fe5a3d84f 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -277,6 +277,13 @@ func computeTimeDiff(diff int64) (int64, string) {
return diff, diffStr
}
+// MinutesToFriendly returns a user friendly string with number of minutes
+// converted to hours and minutes.
+func MinutesToFriendly(minutes int) string {
+ duration := time.Duration(minutes) * time.Minute
+ return TimeSincePro(time.Now().Add(-duration))
+}
+
// TimeSincePro calculates the time interval and generate full user-friendly string.
func TimeSincePro(then time.Time) string {
return timeSincePro(then, time.Now())
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index 43d4df32f7..bd9c6e276e 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -167,6 +167,20 @@ func TestComputeTimeDiff(t *testing.T) {
test(3*Year, "3 years", 0, Year-1)
}
+func TestMinutesToFriendly(t *testing.T) {
+ // test that a number of minutes yields the expected string
+ test := func(expected string, minutes int) {
+ actual := MinutesToFriendly(minutes)
+ assert.Equal(t, expected, actual)
+ }
+ test("1 minute", 1)
+ test("2 minutes", 2)
+ test("1 hour", 60)
+ test("1 hour, 1 minute", 61)
+ test("1 hour, 2 minutes", 62)
+ test("2 hours", 120)
+}
+
func TestTimeSince(t *testing.T) {
assert.Equal(t, "now", timeSince(BaseDate, BaseDate, "en"))