summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/sys/unix/timestruct.go
diff options
context:
space:
mode:
authorDuco van Amstel <helcaraxan@gmail.com>2018-11-18 00:28:29 +0000
committerDuco van Amstel <helcaraxan@gmail.com>2018-11-18 01:10:15 +0000
commit692bb8faa7c4000953b0622a77126193f8fd0383 (patch)
treeb0966b9aa86eb8d02d423221bed21893959de4eb /vendor/golang.org/x/sys/unix/timestruct.go
parent455a0fc2394ea52955ed386663ded9a9dceab83f (diff)
downloadmatterbridge-msglm-692bb8faa7c4000953b0622a77126193f8fd0383.tar.gz
matterbridge-msglm-692bb8faa7c4000953b0622a77126193f8fd0383.tar.bz2
matterbridge-msglm-692bb8faa7c4000953b0622a77126193f8fd0383.zip
Upgrade logrus / testify to stable versions
Diffstat (limited to 'vendor/golang.org/x/sys/unix/timestruct.go')
-rw-r--r--vendor/golang.org/x/sys/unix/timestruct.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/vendor/golang.org/x/sys/unix/timestruct.go b/vendor/golang.org/x/sys/unix/timestruct.go
index 139fbbeb..4a672f56 100644
--- a/vendor/golang.org/x/sys/unix/timestruct.go
+++ b/vendor/golang.org/x/sys/unix/timestruct.go
@@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package unix
+import "time"
+
// TimespecToNsec converts a Timespec value into a number of
// nanoseconds since the Unix epoch.
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
@@ -22,6 +24,24 @@ func NsecToTimespec(nsec int64) Timespec {
return setTimespec(sec, nsec)
}
+// TimeToTimespec converts t into a Timespec.
+// On some 32-bit systems the range of valid Timespec values are smaller
+// than that of time.Time values. So if t is out of the valid range of
+// Timespec, it returns a zero Timespec and ERANGE.
+func TimeToTimespec(t time.Time) (Timespec, error) {
+ sec := t.Unix()
+ nsec := int64(t.Nanosecond())
+ ts := setTimespec(sec, nsec)
+
+ // Currently all targets have either int32 or int64 for Timespec.Sec.
+ // If there were a new target with floating point type for it, we have
+ // to consider the rounding error.
+ if int64(ts.Sec) != sec {
+ return Timespec{}, ERANGE
+ }
+ return ts, nil
+}
+
// TimevalToNsec converts a Timeval value into a number of nanoseconds
// since the Unix epoch.
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }