aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author无闻 <joe2010xtmf@163.com>2014-08-01 00:15:06 -0400
committer无闻 <joe2010xtmf@163.com>2014-08-01 00:15:06 -0400
commit568c9b353ec1e18fceef4bd8e9897adf115c295d (patch)
tree8190c6902e200aea1eae5c51eaf2fd9fed2e9243
parentdabf5b057c358655d8635ed6ec8666660abeb92b (diff)
parent91480f3791f266369c343c539f8eeec245fa969a (diff)
downloadgitea-568c9b353ec1e18fceef4bd8e9897adf115c295d.tar.gz
gitea-568c9b353ec1e18fceef4bd8e9897adf115c295d.zip
Merge pull request #311 from nuss-justin/issue/281
Fix #281. Add mouse-over precise time and on-click switch listener.
-rw-r--r--conf/app.ini6
-rw-r--r--modules/base/tool.go9
-rw-r--r--modules/setting/setting.go53
-rw-r--r--public/js/app.js14
4 files changed, 80 insertions, 2 deletions
diff --git a/conf/app.ini b/conf/app.ini
index a6f048efbc..ac1c6a3ba9 100644
--- a/conf/app.ini
+++ b/conf/app.ini
@@ -186,6 +186,12 @@ MAX_SIZE = 32
; Max number of files per upload. Defaults to 10
MAX_FILES = 10
+[time]
+; Specifies the format for fully outputed dates. Defaults to RFC1123
+; Special supported values are ANSIC, UnixDate, RubyDate, RFC822, RFC822Z, RFC850, RFC1123, RFC1123Z, RFC3339, RFC3339Nano, Kitchen, Stamp, StampMilli, StampMicro and StampNano
+; For more information about the format see http://golang.org/pkg/time/#pkg-constants
+FORMAT =
+
[log]
ROOT_PATH =
; Either "console", "file", "conn", "smtp" or "database", default is "console"
diff --git a/modules/base/tool.go b/modules/base/tool.go
index a2a155d61f..eb0ac9e5bf 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -12,6 +12,7 @@ import (
"encoding/hex"
"fmt"
"hash"
+ "html/template"
"math"
"strings"
"time"
@@ -241,8 +242,7 @@ func TimeSincePro(then time.Time) string {
return strings.TrimPrefix(timeStr, ", ")
}
-// TimeSince calculates the time interval and generate user-friendly string.
-func TimeSince(then time.Time, lang string) string {
+func timeSince(then time.Time, lang string) string {
now := time.Now()
lbl := i18n.Tr(lang, "tool.ago")
@@ -292,6 +292,11 @@ func TimeSince(then time.Time, lang string) string {
}
}
+// TimeSince calculates the time interval and generate user-friendly string.
+func TimeSince(t time.Time, lang string) template.HTML {
+ return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`, t.Format(setting.TimeFormat), timeSince(t, lang)))
+}
+
const (
Byte = 1
KByte = Byte * 1024
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 24d041eae5..717aeaf6a4 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"strings"
+ "time"
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig"
@@ -77,6 +78,9 @@ var (
AttachmentMaxFiles int
AttachmentEnabled bool
+ // Time settings.
+ TimeFormat string
+
// Cache settings.
CacheAdapter string
CacheInternal int
@@ -183,6 +187,55 @@ func NewConfigContext() {
AttachmentMaxFiles = Cfg.MustInt("attachment", "MAX_FILES", 10)
AttachmentEnabled = Cfg.MustBool("attachment", "ENABLE", true)
+ TimeFormat = Cfg.MustValue("time", "FORMAT", time.RFC1123)
+
+ switch TimeFormat {
+ case "ANSIC":
+ TimeFormat = time.ANSIC
+
+ case "UnixDate":
+ TimeFormat = time.UnixDate
+
+ case "RubyDate":
+ TimeFormat = time.RubyDate
+
+ case "RFC822":
+ TimeFormat = time.RFC822
+
+ case "RFC822Z":
+ TimeFormat = time.RFC822Z
+
+ case "RFC850":
+ TimeFormat = time.RFC850
+
+ case "RFC1123":
+ TimeFormat = time.RFC1123
+
+ case "RFC1123Z":
+ TimeFormat = time.RFC1123Z
+
+ case "RFC3339":
+ TimeFormat = time.RFC3339
+
+ case "RFC3339Nano":
+ TimeFormat = time.RFC3339Nano
+
+ case "Kitchen":
+ TimeFormat = time.Kitchen
+
+ case "Stamp":
+ TimeFormat = time.Stamp
+
+ case "StampMilli":
+ TimeFormat = time.StampMilli
+
+ case "StampMicro":
+ TimeFormat = time.StampMicro
+
+ case "StampNano":
+ TimeFormat = time.StampNano
+ }
+
if err = os.MkdirAll(AttachmentPath, os.ModePerm); err != nil {
log.Fatal(4, "Could not create directory %s: %s", AttachmentPath, err)
}
diff --git a/public/js/app.js b/public/js/app.js
index 9451407b1e..2069c1e8d2 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -1120,6 +1120,18 @@ function initOrganization() {
console.log("init script : organization done");
}
+function initTimeSwitch() {
+ $(".time-since[title]").on("click", function() {
+ var $this = $(this);
+
+ var title = $this.attr("title");
+ var text = $this.text();
+
+ $this.text(title);
+ $this.attr("title", text);
+ });
+}
+
(function ($) {
$(function () {
initCore();
@@ -1148,6 +1160,8 @@ function initOrganization() {
if ($('#body-nav').hasClass("org-nav")) {
initOrganization();
}
+
+ initTimeSwitch();
});
})(jQuery);