2020-09-23 15:49:59 -04:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
package print
|
2020-09-23 15:49:59 -04:00
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-05 08:23:32 -04:00
|
|
|
"time"
|
2020-09-30 01:11:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// formatSize get kb in int and return string
|
|
|
|
func formatSize(kb int64) string {
|
2020-09-23 15:49:59 -04:00
|
|
|
if kb < 1024 {
|
|
|
|
return fmt.Sprintf("%d Kb", kb)
|
|
|
|
}
|
|
|
|
mb := kb / 1024
|
|
|
|
if mb < 1024 {
|
|
|
|
return fmt.Sprintf("%d Mb", mb)
|
|
|
|
}
|
|
|
|
gb := mb / 1024
|
|
|
|
if gb < 1024 {
|
|
|
|
return fmt.Sprintf("%d Gb", gb)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%d Tb", gb/1024)
|
|
|
|
}
|
2020-10-05 08:23:32 -04:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|