Merge pull request #3 from ltachet/datetime-type

datetime: use int64 instead of float64
This commit is contained in:
Thomas Boerger 2020-07-20 08:29:15 +02:00 committed by GitHub
commit 8efa917a1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -55,22 +55,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

@ -20,7 +20,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",
@ -31,8 +31,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)
}
}
}