mirror of
https://github.com/thegeeklab/drone-template-lib.git
synced 2024-11-16 01:40:42 +00:00
Merge pull request #3 from ltachet/datetime-type
datetime: use int64 instead of float64
This commit is contained in:
commit
8efa917a1f
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user