Skip to content
This repository was archived by the owner on Feb 22, 2021. It is now read-only.

Commit b6f73a4

Browse files
authored
allows setting time flags (-s/-u) to a unix timestamp (#18)
1 parent f4ccb6d commit b6f73a4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/time.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lib
22

33
import (
4+
"strconv"
45
"strings"
56
"time"
67
)
@@ -91,7 +92,15 @@ func GetTime(value string, reference time.Time) (time.Time, error) {
9192
}
9293

9394
if err != nil {
94-
return time.Unix(0, 0), err // was probably an RFC3339 like timestamp but the parser failed with an error
95+
if strings.Contains(value, "-") {
96+
return time.Unix(0, 0), err // was probably an RFC3339 like timestamp but the parser failed with an error
97+
}
98+
intVal, err := strconv.Atoi(value)
99+
if err != nil {
100+
return time.Unix(0, 0), err
101+
}
102+
103+
t = time.Unix(int64(intVal), 0)
95104
}
96105

97106
return t, nil

0 commit comments

Comments
 (0)