hack/pin-dependency.sh github.com/go-openapi/validate v0.19.5
This commit is contained in:
67
vendor/github.com/go-openapi/strfmt/time.go
generated
vendored
67
vendor/github.com/go-openapi/strfmt/time.go
generated
vendored
@@ -16,15 +16,14 @@ package strfmt
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/globalsign/mgo/bson"
|
||||
"github.com/mailru/easyjson/jlexer"
|
||||
"github.com/mailru/easyjson/jwriter"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -56,12 +55,14 @@ const (
|
||||
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
|
||||
// RFC3339Micro represents a ISO8601 format to micro instead of to nano
|
||||
RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
|
||||
// ISO8601LocalTime represents a ISO8601 format to ISO8601 in local time (no timezone)
|
||||
ISO8601LocalTime = "2006-01-02T15:04:05"
|
||||
// DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6
|
||||
DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$`
|
||||
)
|
||||
|
||||
var (
|
||||
dateTimeFormats = []string{RFC3339Micro, RFC3339Millis, time.RFC3339, time.RFC3339Nano}
|
||||
dateTimeFormats = []string{RFC3339Micro, RFC3339Millis, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime}
|
||||
rxDateTime = regexp.MustCompile(DateTimePattern)
|
||||
// MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds)
|
||||
MarshalFormat = RFC3339Millis
|
||||
@@ -79,7 +80,6 @@ func ParseDateTime(data string) (DateTime, error) {
|
||||
lastError = err
|
||||
continue
|
||||
}
|
||||
lastError = nil
|
||||
return DateTime(dd), nil
|
||||
}
|
||||
return DateTime{}, lastError
|
||||
@@ -144,54 +144,47 @@ func (t DateTime) Value() (driver.Value, error) {
|
||||
|
||||
// MarshalJSON returns the DateTime as JSON
|
||||
func (t DateTime) MarshalJSON() ([]byte, error) {
|
||||
var w jwriter.Writer
|
||||
t.MarshalEasyJSON(&w)
|
||||
return w.BuildBytes()
|
||||
}
|
||||
|
||||
// MarshalEasyJSON writes the DateTime to a easyjson.Writer
|
||||
func (t DateTime) MarshalEasyJSON(w *jwriter.Writer) {
|
||||
w.String(time.Time(t).Format(MarshalFormat))
|
||||
return json.Marshal(time.Time(t).Format(MarshalFormat))
|
||||
}
|
||||
|
||||
// UnmarshalJSON sets the DateTime from JSON
|
||||
func (t *DateTime) UnmarshalJSON(data []byte) error {
|
||||
l := jlexer.Lexer{Data: data}
|
||||
t.UnmarshalEasyJSON(&l)
|
||||
return l.Error()
|
||||
}
|
||||
|
||||
// UnmarshalEasyJSON sets the DateTime from a easyjson.Lexer
|
||||
func (t *DateTime) UnmarshalEasyJSON(in *jlexer.Lexer) {
|
||||
if data := in.String(); in.Ok() {
|
||||
tt, err := ParseDateTime(data)
|
||||
if err != nil {
|
||||
in.AddError(err)
|
||||
return
|
||||
}
|
||||
*t = tt
|
||||
if string(data) == jsonNull {
|
||||
return nil
|
||||
}
|
||||
|
||||
var tstr string
|
||||
if err := json.Unmarshal(data, &tstr); err != nil {
|
||||
return err
|
||||
}
|
||||
tt, err := ParseDateTime(tstr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = tt
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBSON returns the DateTime as a bson.M{} map.
|
||||
func (t *DateTime) GetBSON() (interface{}, error) {
|
||||
return bson.M{"data": t.String()}, nil
|
||||
func (t DateTime) MarshalBSON() ([]byte, error) {
|
||||
return bson.Marshal(bson.M{"data": t.String()})
|
||||
}
|
||||
|
||||
// SetBSON sets the DateTime from raw bson data
|
||||
func (t *DateTime) SetBSON(raw bson.Raw) error {
|
||||
func (t *DateTime) UnmarshalBSON(data []byte) error {
|
||||
var m bson.M
|
||||
if err := raw.Unmarshal(&m); err != nil {
|
||||
if err := bson.Unmarshal(data, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if data, ok := m["data"].(string); ok {
|
||||
var err error
|
||||
*t, err = ParseDateTime(data)
|
||||
return err
|
||||
rd, err := ParseDateTime(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = rd
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("couldn't unmarshal bson raw value as Duration")
|
||||
return errors.New("couldn't unmarshal bson bytes value as Date")
|
||||
}
|
||||
|
||||
// DeepCopyInto copies the receiver and writes its value into out.
|
||||
|
Reference in New Issue
Block a user