![dependabot[bot]](/assets/img/avatar_default.png)
Bumps the golang group with 6 updates in the / directory: | Package | From | To | | --- | --- | --- | | [github.com/Microsoft/hcsshim](https://github.com/Microsoft/hcsshim) | `0.12.7` | `0.12.9` | | [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) | `2.20.2` | `2.22.0` | | [github.com/onsi/gomega](https://github.com/onsi/gomega) | `1.34.2` | `1.36.0` | | [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) | `1.11.0` | `1.11.1` | | [github.com/safchain/ethtool](https://github.com/safchain/ethtool) | `0.4.1` | `0.5.9` | | [sigs.k8s.io/knftables](https://github.com/kubernetes-sigs/knftables) | `0.0.17` | `0.0.18` | Updates `github.com/Microsoft/hcsshim` from 0.12.7 to 0.12.9 - [Release notes](https://github.com/Microsoft/hcsshim/releases) - [Commits](https://github.com/Microsoft/hcsshim/compare/v0.12.7...v0.12.9) Updates `github.com/onsi/ginkgo/v2` from 2.20.2 to 2.22.0 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.20.2...v2.22.0) Updates `github.com/onsi/gomega` from 1.34.2 to 1.36.0 - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.34.2...v1.36.0) Updates `github.com/opencontainers/selinux` from 1.11.0 to 1.11.1 - [Release notes](https://github.com/opencontainers/selinux/releases) - [Commits](https://github.com/opencontainers/selinux/compare/v1.11.0...v1.11.1) Updates `github.com/safchain/ethtool` from 0.4.1 to 0.5.9 - [Release notes](https://github.com/safchain/ethtool/releases) - [Commits](https://github.com/safchain/ethtool/compare/v0.4.1...v0.5.9) Updates `golang.org/x/sys` from 0.26.0 to 0.27.0 - [Commits](https://github.com/golang/sys/compare/v0.26.0...v0.27.0) Updates `sigs.k8s.io/knftables` from 0.0.17 to 0.0.18 - [Changelog](https://github.com/kubernetes-sigs/knftables/blob/master/CHANGELOG.md) - [Commits](https://github.com/kubernetes-sigs/knftables/compare/v0.0.17...v0.0.18) --- updated-dependencies: - dependency-name: github.com/Microsoft/hcsshim dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/opencontainers/selinux dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/safchain/ethtool dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: sigs.k8s.io/knftables dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang ... Signed-off-by: dependabot[bot] <support@github.com>
114 lines
4.2 KiB
Go
114 lines
4.2 KiB
Go
// Go support for Protocol Buffers - Google's data interchange format
|
|
//
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// https://github.com/golang/protobuf
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are
|
|
// met:
|
|
//
|
|
// * Redistributions of source code must retain the above copyright
|
|
// notice, this list of conditions and the following disclaimer.
|
|
// * Redistributions in binary form must reproduce the above
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
// in the documentation and/or other materials provided with the
|
|
// distribution.
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
// contributors may be used to endorse or promote products derived from
|
|
// this software without specific prior written permission.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
package proto
|
|
|
|
// This file implements operations on google.protobuf.Timestamp.
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
// Seconds field of the earliest valid Timestamp.
|
|
// This is time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC).Unix().
|
|
minValidSeconds = -62135596800
|
|
// Seconds field just after the latest valid Timestamp.
|
|
// This is time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC).Unix().
|
|
maxValidSeconds = 253402300800
|
|
)
|
|
|
|
// validateTimestamp determines whether a Timestamp is valid.
|
|
// A valid timestamp represents a time in the range
|
|
// [0001-01-01, 10000-01-01) and has a Nanos field
|
|
// in the range [0, 1e9).
|
|
//
|
|
// If the Timestamp is valid, validateTimestamp returns nil.
|
|
// Otherwise, it returns an error that describes
|
|
// the problem.
|
|
//
|
|
// Every valid Timestamp can be represented by a time.Time, but the converse is not true.
|
|
func validateTimestamp(ts *timestamp) error {
|
|
if ts == nil {
|
|
return errors.New("timestamp: nil Timestamp")
|
|
}
|
|
if ts.Seconds < minValidSeconds {
|
|
return fmt.Errorf("timestamp: %#v before 0001-01-01", ts)
|
|
}
|
|
if ts.Seconds >= maxValidSeconds {
|
|
return fmt.Errorf("timestamp: %#v after 10000-01-01", ts)
|
|
}
|
|
if ts.Nanos < 0 || ts.Nanos >= 1e9 {
|
|
return fmt.Errorf("timestamp: %#v: nanos not in range [0, 1e9)", ts)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// TimestampFromProto converts a google.protobuf.Timestamp proto to a time.Time.
|
|
// It returns an error if the argument is invalid.
|
|
//
|
|
// Unlike most Go functions, if Timestamp returns an error, the first return value
|
|
// is not the zero time.Time. Instead, it is the value obtained from the
|
|
// time.Unix function when passed the contents of the Timestamp, in the UTC
|
|
// locale. This may or may not be a meaningful time; many invalid Timestamps
|
|
// do map to valid time.Times.
|
|
//
|
|
// A nil Timestamp returns an error. The first return value in that case is
|
|
// undefined.
|
|
func timestampFromProto(ts *timestamp) (time.Time, error) {
|
|
// Don't return the zero value on error, because corresponds to a valid
|
|
// timestamp. Instead return whatever time.Unix gives us.
|
|
var t time.Time
|
|
if ts == nil {
|
|
t = time.Unix(0, 0).UTC() // treat nil like the empty Timestamp
|
|
} else {
|
|
t = time.Unix(ts.Seconds, int64(ts.Nanos)).UTC()
|
|
}
|
|
return t, validateTimestamp(ts)
|
|
}
|
|
|
|
// TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
|
|
// It returns an error if the resulting Timestamp is invalid.
|
|
func timestampProto(t time.Time) (*timestamp, error) {
|
|
seconds := t.Unix()
|
|
nanos := int32(t.Sub(time.Unix(seconds, 0)))
|
|
ts := ×tamp{
|
|
Seconds: seconds,
|
|
Nanos: nanos,
|
|
}
|
|
if err := validateTimestamp(ts); err != nil {
|
|
return nil, err
|
|
}
|
|
return ts, nil
|
|
}
|