diff pkg/common/time.go @ 4162:8c5df0f3562e

Made 'golint' and 'staticcheck' happy with common package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 02 Aug 2019 17:53:18 +0200
parents 80bdcd137a1d
children d6710d29516b
line wrap: on
line diff
--- a/pkg/common/time.go	Fri Aug 02 17:14:13 2019 +0200
+++ b/pkg/common/time.go	Fri Aug 02 17:53:18 2019 +0200
@@ -23,15 +23,25 @@
 	// time.RFC3339 equals "simplified ISO format as defined by ECMA-262"
 	//   https://tc39.github.io/ecma262/#sec-date-time-string-format
 	// and "SHOULD be used in new protocols on the Internet." (RFC section 5.6)
-	TimeFormat           = time.RFC3339
-	TimeFormatMicro      = "2006-01-02T15:04:05.999Z07:00"
+
+	// TimeFormat is the preferred time format represention in gemma.
+	TimeFormat = time.RFC3339
+	// TimeFormatMicro is the same as TimeFormat but also
+	// contains 3 digits for micro seconds.
+	// This is useful for e.g. times in imports and the
+	// respective logs.
+	TimeFormatMicro = "2006-01-02T15:04:05.999Z07:00"
+	// TimeFormatMicroLocal is the same as TimeFormatMicro but
+	// w/o the timezone. Only used for tolerant parsing.
 	TimeFormatMicroLocal = "2006-01-02T15:04:05.000"
-	DateFormat           = "2006-01-02"
+	// DateFormat represents the preferred date format in Gemma.
+	DateFormat = "2006-01-02"
 )
 
 // TimeParser is a list of time formats.
 type TimeParser []string
 
+// ParseTime parses the time formats known to Gemma.
 var ParseTime = TimeParser{
 	TimeFormat,
 	TimeFormatMicro,
@@ -56,6 +66,12 @@
 	return t, err
 }
 
+// InterpolateTime returns a function that linearly interpolates the
+// time between t1 and t2 for given value m1 to m2.
+// If m1 is given to the returned function t1 is returned.
+// If m2 is given to the returned function t2 is returned.
+// Values between m1 and m2 will result in the proportional
+// time between t1 and t2.
 func InterpolateTime(t1 time.Time, m1 float64, t2 time.Time, m2 float64) func(float64) time.Time {
 
 	// f(m1) = t1