]> source.dussan.org Git - gitea.git/commitdiff
Remove the "PHP" style formatting function
authorPeter Smit <peter@smitmail.eu>
Mon, 16 Feb 2015 12:44:27 +0000 (14:44 +0200)
committerPeter Smit <peter@smitmail.eu>
Mon, 16 Feb 2015 12:44:27 +0000 (14:44 +0200)
The "PHP" formatting function doesn't add anything, except an undocumented date format.

All usages in the templates have been replaced with DateFmtShort and DateFmtLong for convenience.

modules/base/template.go
modules/base/tool.go
templates/admin/auth/list.tmpl
templates/admin/org/list.tmpl
templates/admin/repo/list.tmpl
templates/admin/user/list.tmpl
templates/user/profile.tmpl
templates/user/settings/applications.tmpl
templates/user/settings/social.tmpl
templates/user/settings/sshkeys.tmpl

index f3fa138578997dc0af88018edb661a29b34dd586..0fd519e6c564ee26048248237a5b6f73c7af9a92 100644 (file)
@@ -126,8 +126,13 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
                return a + b
        },
        "ActionIcon": ActionIcon,
-       "DateFormat": DateFormat,
-       "List":       List,
+       "DateFmtLong": func(t time.Time) string {
+               return t.Format(time.RFC1123Z)
+       },
+       "DateFmtShort": func(t time.Time) string {
+               return t.Format("Jan 02, 2006")
+       },
+       "List": List,
        "Mail2Domain": func(mail string) string {
                if !strings.Contains(mail, "@") {
                        return "try.gogs.io"
index 5043364cecfbb2308b024e461b00119c519b4e3e..55e6dffd96b56560327079bc502ea2bf1cadd004 100644 (file)
@@ -126,7 +126,7 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool {
        retCode := CreateTimeLimitCode(data, minutes, start)
        if retCode == code && minutes > 0 {
                // check time is expired or not
-               before, _ := DateParse(start, "YmdHi")
+               before, _ := time.ParseInLocation("200601021504", start, time.Local)
                now := time.Now()
                if before.Add(time.Minute*time.Duration(minutes)).Unix() > now.Unix() {
                        return true
@@ -141,7 +141,7 @@ const TimeLimitCodeLength = 12 + 6 + 40
 // create a time limit code
 // code format: 12 length date time string + 6 minutes string + 40 sha1 encoded string
 func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string {
-       format := "YmdHi"
+       format := "200601021504"
 
        var start, end time.Time
        var startStr, endStr string
@@ -149,16 +149,16 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
        if startInf == nil {
                // Use now time create code
                start = time.Now()
-               startStr = DateFormat(start, format)
+               startStr = start.Format(format)
        } else {
                // use start string create code
                startStr = startInf.(string)
-               start, _ = DateParse(startStr, format)
-               startStr = DateFormat(start, format)
+               start, _ = time.ParseInLocation(format, startStr, time.Local)
+               startStr = start.Format(format)
        }
 
        end = start.Add(time.Minute * time.Duration(minutes))
-       endStr = DateFormat(end, format)
+       endStr = end.Format(format)
 
        // create sha1 encode string
        sh := sha1.New()
@@ -420,58 +420,3 @@ func Subtract(left interface{}, right interface{}) interface{} {
                return fleft + float64(rleft) - (fright + float64(rright))
        }
 }
-
-// DateFormat pattern rules.
-var datePatterns = []string{
-       // year
-       "Y", "2006", // A full numeric representation of a year, 4 digits   Examples: 1999 or 2003
-       "y", "06", //A two digit representation of a year   Examples: 99 or 03
-
-       // month
-       "m", "01", // Numeric representation of a month, with leading zeros 01 through 12
-       "n", "1", // Numeric representation of a month, without leading zeros   1 through 12
-       "M", "Jan", // A short textual representation of a month, three letters Jan through Dec
-       "F", "January", // A full textual representation of a month, such as January or March   January through December
-
-       // day
-       "d", "02", // Day of the month, 2 digits with leading zeros 01 to 31
-       "j", "2", // Day of the month without leading zeros 1 to 31
-
-       // week
-       "D", "Mon", // A textual representation of a day, three letters Mon through Sun
-       "l", "Monday", // A full textual representation of the day of the week  Sunday through Saturday
-
-       // time
-       "g", "3", // 12-hour format of an hour without leading zeros    1 through 12
-       "G", "15", // 24-hour format of an hour without leading zeros   0 through 23
-       "h", "03", // 12-hour format of an hour with leading zeros  01 through 12
-       "H", "15", // 24-hour format of an hour with leading zeros  00 through 23
-
-       "a", "pm", // Lowercase Ante meridiem and Post meridiem am or pm
-       "A", "PM", // Uppercase Ante meridiem and Post meridiem AM or PM
-
-       "i", "04", // Minutes with leading zeros    00 to 59
-       "s", "05", // Seconds, with leading zeros   00 through 59
-
-       // time zone
-       "T", "MST",
-       "P", "-07:00",
-       "O", "-0700",
-
-       // RFC 2822
-       "r", time.RFC1123Z,
-}
-
-// Parse Date use PHP time format.
-func DateParse(dateString, format string) (time.Time, error) {
-       replacer := strings.NewReplacer(datePatterns...)
-       format = replacer.Replace(format)
-       return time.ParseInLocation(format, dateString, time.Local)
-}
-
-// Date takes a PHP like date func to Go's time format.
-func DateFormat(t time.Time, format string) string {
-       replacer := strings.NewReplacer(datePatterns...)
-       format = replacer.Replace(format)
-       return t.Format(format)
-}
index aba516b8ebfd8971cc277af2c3a6727c1598e4a1..ec701a8f8c23e10c81113b71c79bf2317211598a 100644 (file)
@@ -34,8 +34,8 @@
                                                                    <td><a href="{{AppSubUrl}}/admin/auths/{{.Id}}">{{.Name}}</a></td>
                                                                    <td>{{.TypeString}}</td>
                                                                    <td><i class="fa fa{{if .IsActived}}-check{{end}}-square-o"></i></td>
-                                                                   <td><span title="{{DateFormat .Updated "r"}}">{{DateFormat .Updated "M d, Y"}}</span></td>
-                                                                   <td><span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span></td>
+                                                                   <td><span title="{{DateFmtLong .Updated}}">{{DateFmtShort .Updated}}</span></td>
+                                                                   <td><span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created}}</span></td>
                                                                    <td><a href="{{AppSubUrl}}/admin/auths/{{.Id}}"><i class="fa fa-pencil-square-o"></i></a></td>
                                                                </tr>
                                                                {{end}}
index b522dc08a3957db694878b3cff8265cc6bce76c7..ce5083a0aefb13ac51ff67ff6ba5cbb291ff3518 100644 (file)
@@ -35,7 +35,7 @@
                                                                    <td>{{.NumTeams}}</td>
                                                                    <td>{{.NumMembers}}</td>
                                                                    <td>{{.NumRepos}}</td>
-                                                                   <td><span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span></td>
+                                                                   <td><span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created}}</span></td>
                                                                </tr>
                                                                {{end}}
                                                            </tbody>
index 88e16a4337297ff22165f15b130b33432a5b6fd0..981e2ef72be7453e65ba7d97bb0237641b31a32e 100644 (file)
@@ -37,7 +37,7 @@
                                                                    <td>{{.NumWatches}}</td>
                                                                    <td>{{.NumStars}}</td>
                                                                    <td>{{.NumIssues}}</td>
-                                                                   <td><span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span></td>
+                                                                   <td><span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created}}</span></td>
                                                                </tr>
                                                                {{end}}
                                                            </tbody>
index d42d52910e615774b219561881c9109a795ebbc2..1dd5553eb53652bc4805ad8d16fec37fc02ccc21 100644 (file)
@@ -37,7 +37,7 @@
                                                                    <td><i class="fa fa{{if .IsActive}}-check{{end}}-square-o"></i></td>
                                                                    <td><i class="fa fa{{if .IsAdmin}}-check{{end}}-square-o"></i></td>
                                                                    <td>{{.NumRepos}}</td>
-                                                                   <td><span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span></td>
+                                                                   <td><span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created }}</span></td>
                                                                    <td><a href="{{AppSubUrl}}/admin/users/{{.Id}}"><i class="fa fa-pencil-square-o"></i></a></td>
                                                                </tr>
                                                                {{end}}
index 44c2212383e6767e5b7c9895e523651ae05e7e00..a18a8b50d6ac48ff93e9c51c11dd506ade2b8214 100644 (file)
@@ -28,7 +28,7 @@
                     {{if .Owner.Website}}
                     <li class="list-group-item"><i class="octicon octicon-link"></i>&nbsp;&nbsp;<a target="_blank" href="{{.Owner.Website}}">{{.Owner.Website}}</a></li>
                     {{end}}
-                    <li class="list-group-item"><i class="octicon octicon-clock"></i>&nbsp;&nbsp;{{.i18n.Tr "user.join_on"}} {{DateFormat .Owner.Created "M d, Y"}}</li>
+                    <li class="list-group-item"><i class="octicon octicon-clock"></i>&nbsp;&nbsp;{{.i18n.Tr "user.join_on"}} {{DateFmtShort .Owner.Created}}</li>
                 </ul>
                 <hr>
                 <ul class="list-no-style">
index ce74ef77663e3941b12eaf48f2b4f4e94d2aa041..2e766a3dc77927c3ef8e6ca55d0560f25e7ec80e 100644 (file)
@@ -22,7 +22,7 @@
                                 <i class="fa fa-send fa-2x left"></i>
                                 <div class="ssh-content left">
                                     <p><strong>{{.Name}}</strong></p>
-                                    <p class="activity"><i>{{$.i18n.Tr "settings.add_on"}} <span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span> —  <i class="octicon octicon-info"></i>{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}</i></p>
+                                    <p class="activity"><i>{{$.i18n.Tr "settings.add_on"}} <span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created}}</span> —  <i class="octicon octicon-info"></i>{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}</i></p>
                                 </div>
                                 <a href="{{AppSubUrl}}/user/settings/applications?remove={{.Id}}">
                                        <button class="btn btn-small btn-red btn-radius ssh-btn right">{{$.i18n.Tr "settings.delete_token"}}</button>
index b47f883e51172a4ffd6864d456aaac31ffaeda31..f2a30da7915c170cacffdea1940c7e1d28f690f4 100644 (file)
@@ -18,7 +18,7 @@
                                 <div class="ssh-content left">
                                     <p><strong>{{Oauth2Name .Type}}</strong></p>
                                     <p class="print">{{.Identity}}</p>
-                                    <p class="activity"><i>{{$.i18n.Tr "settings.add_on"}} <span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span> —  <i class="octicon octicon-info"></i>{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}</i></p>
+                                    <p class="activity"><i>{{$.i18n.Tr "settings.add_on"}} <span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created}}</span> —  <i class="octicon octicon-info"></i>{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}</i></p>
                                 </div>
                                 <a class="right btn btn-small btn-red btn-header btn-radius" href="{{AppSubUrl}}/user/settings/social?remove={{.Id}}">{{$.i18n.Tr "settings.unbind"}}</a>
                             </li>
index 48a4d343ae1c16be9ab66f453a6646e718270edb..42b76039eef3f3dc793f7d1d8bc9e67dc8816f74 100644 (file)
@@ -23,7 +23,7 @@
                                 <div class="ssh-content left">
                                     <p><strong>{{.Name}}</strong></p>
                                     <p class="print">{{.Fingerprint}}</p>
-                                    <p class="activity"><i>{{$.i18n.Tr "settings.add_on"}} <span title="{{DateFormat .Created "r"}}">{{DateFormat .Created "M d, Y"}}</span> —  <i class="octicon octicon-info"></i>{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} <span title="{{DateFormat .Updated "r"}}">{{DateFormat .Updated "M d, Y"}}</span>{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}</i></p>
+                                    <p class="activity"><i>{{$.i18n.Tr "settings.add_on"}} <span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created}}</span> —  <i class="octicon octicon-info"></i>{{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} <span title="{{DateFmtLong .Updated}}">{{DateFmtShort .Updated}}</span>{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}</i></p>
                                 </div>
                                 <form action="{{AppSubUrl}}/user/settings/ssh" method="post">
                                     {{$.CsrfTokenHtml}}