added share list page
This commit is contained in:
39
helpers/helpers.go
Normal file
39
helpers/helpers.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func HumanDiff(diff float64) string {
|
||||
units := []string{"", "K", "M", "G", "T"}
|
||||
i := 0
|
||||
for diff >= 1000 && i < len(units)-1 {
|
||||
diff /= 1000
|
||||
i++
|
||||
}
|
||||
return fmt.Sprintf("%.2f%s", diff, units[i])
|
||||
}
|
||||
|
||||
func ParseCreateDate(createdate string) time.Time {
|
||||
parts := strings.Split(createdate, ",")
|
||||
if len(parts) == 2 {
|
||||
sec, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||
nsec, _ := strconv.ParseInt(parts[1], 10, 64)
|
||||
return time.Unix(sec, nsec)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func FormatCreateDate(createdate string) string {
|
||||
parts := strings.Split(createdate, ",")
|
||||
if len(parts) == 2 {
|
||||
sec, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||
nsec, _ := strconv.ParseInt(parts[1], 10, 64)
|
||||
t := time.Unix(sec, nsec)
|
||||
return t.Format(time.DateTime)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user