mirror of
https://github.com/containers/podman.git
synced 2025-06-03 20:33:20 +08:00
vendor containers/common@e27c30ee9b
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
21
vendor/github.com/go-openapi/strfmt/time.go
generated
vendored
21
vendor/github.com/go-openapi/strfmt/time.go
generated
vendored
@ -29,6 +29,12 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
)
|
||||
|
||||
var (
|
||||
// UnixZero sets the zero unix timestamp we want to compare against.
|
||||
// Unix 0 for an EST timezone is not equivalent to a UTC timezone.
|
||||
UnixZero = time.Unix(0, 0).UTC()
|
||||
)
|
||||
|
||||
func init() {
|
||||
dt := DateTime{}
|
||||
Default.Add("datetime", &dt, IsDateTime)
|
||||
@ -86,6 +92,9 @@ var (
|
||||
// NormalizeTimeForMarshal provides a normalization function on time befeore marshalling (e.g. time.UTC).
|
||||
// By default, the time value is not changed.
|
||||
NormalizeTimeForMarshal = func(t time.Time) time.Time { return t }
|
||||
|
||||
// DefaultTimeLocation provides a location for a time when the time zone is not encoded in the string (ex: ISO8601 Local variants).
|
||||
DefaultTimeLocation = time.UTC
|
||||
)
|
||||
|
||||
// ParseDateTime parses a string that represents an ISO8601 time or a unix epoch
|
||||
@ -95,7 +104,7 @@ func ParseDateTime(data string) (DateTime, error) {
|
||||
}
|
||||
var lastError error
|
||||
for _, layout := range DateTimeFormats {
|
||||
dd, err := time.Parse(layout, data)
|
||||
dd, err := time.ParseInLocation(layout, data, DefaultTimeLocation)
|
||||
if err != nil {
|
||||
lastError = err
|
||||
continue
|
||||
@ -123,6 +132,16 @@ func (t DateTime) String() string {
|
||||
return NormalizeTimeForMarshal(time.Time(t)).Format(MarshalFormat)
|
||||
}
|
||||
|
||||
// IsZero returns whether the date time is a zero value
|
||||
func (t DateTime) IsZero() bool {
|
||||
return time.Time(t).IsZero()
|
||||
}
|
||||
|
||||
// IsUnixZerom returns whether the date time is equivalent to time.Unix(0, 0).UTC().
|
||||
func (t DateTime) IsUnixZero() bool {
|
||||
return time.Time(t) == UnixZero
|
||||
}
|
||||
|
||||
// MarshalText implements the text marshaller interface
|
||||
func (t DateTime) MarshalText() ([]byte, error) {
|
||||
return []byte(t.String()), nil
|
||||
|
Reference in New Issue
Block a user