datetime: use int64 instead of float64

This commit is contained in:
Lucille Tachet 2018-08-01 11:05:11 +02:00
parent 5748d3149f
commit d56ed15f86
2 changed files with 8 additions and 8 deletions

View File

@ -46,22 +46,22 @@ func init() {
raymond.RegisterHelpers(funcs)
}
func toDuration(started, finished float64) string {
func toDuration(started, finished int64) string {
return fmt.Sprint(time.Duration(finished-started) * time.Second)
}
func toDatetime(timestamp float64, layout, zone string) string {
func toDatetime(timestamp int64, layout, zone string) string {
if len(zone) == 0 {
return time.Unix(int64(timestamp), 0).Format(layout)
return time.Unix(timestamp, 0).Format(layout)
}
loc, err := time.LoadLocation(zone)
if err != nil {
return time.Unix(int64(timestamp), 0).Local().Format(layout)
return time.Unix(timestamp, 0).Local().Format(layout)
}
return time.Unix(int64(timestamp), 0).In(loc).Format(layout)
return time.Unix(timestamp, 0).In(loc).Format(layout)
}
func isSuccess(conditional bool, options *raymond.Options) string {

View File

@ -22,7 +22,7 @@ import (
)
func TestToDuration(t *testing.T) {
from := float64(time.Date(2017, time.November, 15, 23, 0, 0, 0, time.UTC).Unix())
from := time.Date(2017, time.November, 15, 23, 0, 0, 0, time.UTC).Unix()
vals := map[int64]string{
time.Date(2018, time.November, 15, 23, 0, 0, 0, time.UTC).Unix(): "8760h0m0s",
@ -33,8 +33,8 @@ func TestToDuration(t *testing.T) {
}
for input, want := range vals {
if got := toDuration(from, float64(input)); got != want {
t.Errorf("Want transform %f-%f to %s, got %s", from, float64(input), want, got)
if got := toDuration(from, input); got != want {
t.Errorf("Want transform %d-%d to %s, got %s", from, input, want, got)
}
}
}