print times in local timezone #217

Merged
6543 merged 5 commits from noerw/tea:local-time into master 2020-10-05 12:23:41 +00:00
10 changed files with 29 additions and 9 deletions
Showing only changes of commit fab5ad1762 - Show all commits

View File

@ -83,7 +83,7 @@ func RunIssuesList(ctx *cli.Context) error {
string(issue.State),
author,
mile,
issue.Updated.Format("2006-01-02 15:04:05"),
print.FormatTime(issue.Updated),
},
)
}

View File

@ -137,7 +137,7 @@ func runMilestoneIssueList(ctx *cli.Context) error {
string(issue.State),
kind,
name,
issue.Updated.Format("2006-01-02 15:04:05"),
print.FormatTime(issue.Updated),
issue.Title,
},
)

View File

@ -72,7 +72,7 @@ func RunMilestonesList(ctx *cli.Context) error {
var deadline = ""
if m.Deadline != nil && !m.Deadline.IsZero() {
deadline = m.Deadline.Format("2006-01-02 15:04:05")
deadline = print.FormatTime(*m.Deadline)
}
item := []string{

View File

@ -84,7 +84,7 @@ func RunPullsList(ctx *cli.Context) error {
string(pr.State),
author,
mile,
pr.Updated.Format("2006-01-02 15:04:05"),
print.FormatTime(*pr.Updated),
},
)
}

View File

@ -65,7 +65,7 @@ func RunReleasesList(ctx *cli.Context) error {
[]string{
release.TagName,
release.Title,
release.PublishedAt.Format("2006-01-02 15:04:05"),
print.FormatTime(release.PublishedAt),
status,
release.TarURL,
},

View File

@ -18,7 +18,7 @@ func IssueDetails(issue *gitea.Issue) {
issue.Title,
issue.State,
issue.Poster.UserName,
issue.Created.Format("2006-01-02 15:04:05"),
FormatTime(issue.Created),
issue.Body,
)
out, err := glamour.Render(in, getGlamourTheme())

View File

@ -12,6 +12,7 @@ import (
// MilestoneDetails print an milestone formatted to stdout
func MilestoneDetails(milestone *gitea.Milestone) {
// TODO: glamour, issue counts
fmt.Printf("%s\n",
milestone.Title,
)
@ -19,6 +20,6 @@ func MilestoneDetails(milestone *gitea.Milestone) {
fmt.Printf("\n%s\n", milestone.Description)
}
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))
}
}

View File

@ -6,10 +6,21 @@ package print
import (
"fmt"
"time"
"github.com/muesli/termenv"
)
var (
location *time.Location
)
func init() {
// get local timezone for time formatting. we ignore the error
// and handle that case in FormatTime().
location, _ = time.LoadLocation("Local")
}
func getGlamourTheme() string {
if termenv.HasDarkBackground() {
return "dark"
@ -32,3 +43,11 @@ func formatSize(kb int64) string {
}
return fmt.Sprintf("%d Tb", gb/1024)
}
// FormatTime give a date-time in local timezone if available
func FormatTime(t time.Time) string {
if location == nil {
return t.Format("2006-01-02 15:04 UTC")
}
return t.In(location).Format("2006-01-02 15:04")
}

View File

@ -18,7 +18,7 @@ func PullDetails(pr *gitea.PullRequest) {
pr.Title,
pr.State,
pr.Poster.UserName,
pr.Created.Format("2006-01-02 15:04:05"),
FormatTime(*pr.Created),
pr.Body,
)
out, err := glamour.Render(in, getGlamourTheme())

View File

@ -45,7 +45,7 @@ func TrackedTimesList(times []*gitea.TrackedTime, outputType string, from, until
outputValues = append(
outputValues,
[]string{
t.Created.In(localLoc).Format("2006-01-02 15:04:05"),
FormatTime(t.Created.In(localLoc)),
"#" + strconv.FormatInt(t.Issue.Index, 10),
t.UserName,
formatDuration(t.Time, outputType),