Browse Source

Merge pull request #43790 from samuelkarp/timestamp-godoc

timestamp: clarify doc for ParseTimestamp
Sebastiaan van Stijn 3 years ago
parent
commit
be628115ba
2 changed files with 12 additions and 10 deletions
  1. 10 10
      api/types/time/timestamp.go
  2. 2 0
      api/types/time/timestamp_test.go

+ 10 - 10
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
 	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 == "" {
 	if value == "" {
-		return def, 0, nil
+		return defaultSeconds, 0, nil
 	}
 	}
 	return parseTimestamp(value)
 	return parseTimestamp(value)
 }
 }

+ 2 - 0
api/types/time/timestamp_test.go

@@ -74,6 +74,8 @@ func TestParseTimestamps(t *testing.T) {
 		{"1136073600", 0, 1136073600, 0, false},
 		{"1136073600", 0, 1136073600, 0, false},
 		{"1136073600.000000001", 0, 1136073600, 1, false},
 		{"1136073600.000000001", 0, 1136073600, 1, false},
 		{"1136073600.0000000010", 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},
 		{"1136073600.00000001", 0, 1136073600, 10, false},
 		{"foo.bar", 0, 0, 0, true},
 		{"foo.bar", 0, 0, 0, true},
 		{"1136073600.bar", 0, 1136073600, 0, true},
 		{"1136073600.bar", 0, 1136073600, 0, true},