diff --git a/api/types/time/timestamp.go b/api/types/time/timestamp.go index 2a74b7a597..5fddd54163 100644 --- a/api/types/time/timestamp.go +++ b/api/types/time/timestamp.go @@ -95,19 +95,19 @@ func GetTimestamp(value string, reference time.Time) (string, error) { return fmt.Sprintf("%d.%09d", t.Unix(), int64(t.Nanosecond())), nil } -// ParseTimestamps returns seconds and nanoseconds from a timestamp that has the -// format "%d.%09d", time.Unix(), int64(time.Nanosecond())) -// if the incoming nanosecond portion is longer or shorter than 9 digits it is -// converted to nanoseconds. The expectation is that the seconds and -// seconds will be used to create a time variable. For example: +// ParseTimestamps returns seconds and nanoseconds from a timestamp that has +// the format ("%d.%09d", time.Unix(), int64(time.Nanosecond())). +// If the incoming nanosecond portion is longer than 9 digits it is truncated. +// The expectation is that the seconds and nanoseconds will be used to create a +// time variable. For example: // -// seconds, nanoseconds, err := ParseTimestamp("1136073600.000000001",0) -// if err == nil since := time.Unix(seconds, nanoseconds) +// seconds, nanoseconds, _ := ParseTimestamp("1136073600.000000001",0) +// since := time.Unix(seconds, nanoseconds) // -// returns seconds as def(aultSeconds) if value == "" -func ParseTimestamps(value string, def int64) (int64, int64, error) { +// returns seconds as defaultSeconds if value == "" +func ParseTimestamps(value string, defaultSeconds int64) (int64, int64, error) { if value == "" { - return def, 0, nil + return defaultSeconds, 0, nil } return parseTimestamp(value) } diff --git a/api/types/time/timestamp_test.go b/api/types/time/timestamp_test.go index 2535d895c6..a46bc63e5b 100644 --- a/api/types/time/timestamp_test.go +++ b/api/types/time/timestamp_test.go @@ -74,6 +74,8 @@ func TestParseTimestamps(t *testing.T) { {"1136073600", 0, 1136073600, 0, false}, {"1136073600.000000001", 0, 1136073600, 1, false}, {"1136073600.0000000010", 0, 1136073600, 1, false}, + {"1136073600.0000000001", 0, 1136073600, 0, false}, + {"1136073600.0000000009", 0, 1136073600, 0, false}, {"1136073600.00000001", 0, 1136073600, 10, false}, {"foo.bar", 0, 0, 0, true}, {"1136073600.bar", 0, 1136073600, 0, true},