print times in local timezone (#217)
dont resolve location ahead of time fixup! use local timezone for all printed times fixup! use local timezone for all printed times use local timezone for all printed times Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/217 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
30c3aa4f5b
commit
03ec6d0eee
|
@ -83,7 +83,7 @@ func RunIssuesList(ctx *cli.Context) error {
|
||||||
string(issue.State),
|
string(issue.State),
|
||||||
author,
|
author,
|
||||||
mile,
|
mile,
|
||||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
print.FormatTime(issue.Updated),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ func runMilestoneIssueList(ctx *cli.Context) error {
|
||||||
string(issue.State),
|
string(issue.State),
|
||||||
kind,
|
kind,
|
||||||
name,
|
name,
|
||||||
issue.Updated.Format("2006-01-02 15:04:05"),
|
print.FormatTime(issue.Updated),
|
||||||
issue.Title,
|
issue.Title,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -72,7 +72,7 @@ func RunMilestonesList(ctx *cli.Context) error {
|
||||||
var deadline = ""
|
var deadline = ""
|
||||||
|
|
||||||
if m.Deadline != nil && !m.Deadline.IsZero() {
|
if m.Deadline != nil && !m.Deadline.IsZero() {
|
||||||
deadline = m.Deadline.Format("2006-01-02 15:04:05")
|
deadline = print.FormatTime(*m.Deadline)
|
||||||
}
|
}
|
||||||
|
|
||||||
item := []string{
|
item := []string{
|
||||||
|
|
|
@ -84,7 +84,7 @@ func RunPullsList(ctx *cli.Context) error {
|
||||||
string(pr.State),
|
string(pr.State),
|
||||||
author,
|
author,
|
||||||
mile,
|
mile,
|
||||||
pr.Updated.Format("2006-01-02 15:04:05"),
|
print.FormatTime(*pr.Updated),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func RunReleasesList(ctx *cli.Context) error {
|
||||||
[]string{
|
[]string{
|
||||||
release.TagName,
|
release.TagName,
|
||||||
release.Title,
|
release.Title,
|
||||||
release.PublishedAt.Format("2006-01-02 15:04:05"),
|
print.FormatTime(release.PublishedAt),
|
||||||
status,
|
status,
|
||||||
release.TarURL,
|
release.TarURL,
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,7 +18,7 @@ func IssueDetails(issue *gitea.Issue) {
|
||||||
issue.Title,
|
issue.Title,
|
||||||
issue.State,
|
issue.State,
|
||||||
issue.Poster.UserName,
|
issue.Poster.UserName,
|
||||||
issue.Created.Format("2006-01-02 15:04:05"),
|
FormatTime(issue.Created),
|
||||||
issue.Body,
|
issue.Body,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,6 @@ func MilestoneDetails(milestone *gitea.Milestone) {
|
||||||
fmt.Printf("\n%s\n", milestone.Description)
|
fmt.Printf("\n%s\n", milestone.Description)
|
||||||
}
|
}
|
||||||
if milestone.Deadline != nil && !milestone.Deadline.IsZero() {
|
if milestone.Deadline != nil && !milestone.Deadline.IsZero() {
|
||||||
fmt.Printf("\nDeadline: %s\n", milestone.Deadline.Format("2006-01-02 15:04:05"))
|
fmt.Printf("\nDeadline: %s\n", FormatTime(*milestone.Deadline))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ package print
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// formatSize get kb in int and return string
|
// formatSize get kb in int and return string
|
||||||
|
@ -23,3 +24,12 @@ func formatSize(kb int64) string {
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%d Tb", gb/1024)
|
return fmt.Sprintf("%d Tb", gb/1024)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FormatTime give a date-time in local timezone if available
|
||||||
|
func FormatTime(t time.Time) string {
|
||||||
|
location, err := time.LoadLocation("Local")
|
||||||
|
if err != nil {
|
||||||
|
return t.Format("2006-01-02 15:04 UTC")
|
||||||
|
}
|
||||||
|
return t.In(location).Format("2006-01-02 15:04")
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func PullDetails(pr *gitea.PullRequest) {
|
||||||
pr.Title,
|
pr.Title,
|
||||||
pr.State,
|
pr.State,
|
||||||
pr.Poster.UserName,
|
pr.Poster.UserName,
|
||||||
pr.Created.Format("2006-01-02 15:04:05"),
|
FormatTime(*pr.Created),
|
||||||
pr.Body,
|
pr.Body,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ package print
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -27,11 +26,6 @@ func TrackedTimesList(times []*gitea.TrackedTime, outputType string, from, until
|
||||||
var outputValues [][]string
|
var outputValues [][]string
|
||||||
var totalDuration int64
|
var totalDuration int64
|
||||||
|
|
||||||
localLoc, err := time.LoadLocation("Local") // local timezone for time formatting
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, t := range times {
|
for _, t := range times {
|
||||||
if !from.IsZero() && from.After(t.Created) {
|
if !from.IsZero() && from.After(t.Created) {
|
||||||
continue
|
continue
|
||||||
|
@ -45,7 +39,7 @@ func TrackedTimesList(times []*gitea.TrackedTime, outputType string, from, until
|
||||||
outputValues = append(
|
outputValues = append(
|
||||||
outputValues,
|
outputValues,
|
||||||
[]string{
|
[]string{
|
||||||
t.Created.In(localLoc).Format("2006-01-02 15:04:05"),
|
FormatTime(t.Created),
|
||||||
"#" + strconv.FormatInt(t.Issue.Index, 10),
|
"#" + strconv.FormatInt(t.Issue.Index, 10),
|
||||||
t.UserName,
|
t.UserName,
|
||||||
formatDuration(t.Time, outputType),
|
formatDuration(t.Time, outputType),
|
||||||
|
|
Loading…
Reference in New Issue