summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/francoispqt/gojay/decode_time.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-08-10 00:29:54 +0200
committerGitHub <noreply@github.com>2020-08-10 00:29:54 +0200
commit4e50fd864921c556988c919269448efdb90fa961 (patch)
treea3625f03f8de3c4f3841364000a4ea3aa42c1533 /vendor/github.com/francoispqt/gojay/decode_time.go
parentdfdffa0027334e55ce213fc6eb62206dbf48baf6 (diff)
downloadmatterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.gz
matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.bz2
matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.zip
Use mattermost v5 module (#1192)
Diffstat (limited to 'vendor/github.com/francoispqt/gojay/decode_time.go')
-rw-r--r--vendor/github.com/francoispqt/gojay/decode_time.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/github.com/francoispqt/gojay/decode_time.go b/vendor/github.com/francoispqt/gojay/decode_time.go
new file mode 100644
index 00000000..68f906d7
--- /dev/null
+++ b/vendor/github.com/francoispqt/gojay/decode_time.go
@@ -0,0 +1,53 @@
+package gojay
+
+import (
+ "time"
+)
+
+// DecodeTime decodes time with the given format
+func (dec *Decoder) DecodeTime(v *time.Time, format string) error {
+ if dec.isPooled == 1 {
+ panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder"))
+ }
+ return dec.decodeTime(v, format)
+}
+
+func (dec *Decoder) decodeTime(v *time.Time, format string) error {
+ if format == time.RFC3339 {
+ var ej = make(EmbeddedJSON, 0, 20)
+ if err := dec.decodeEmbeddedJSON(&ej); err != nil {
+ return err
+ }
+ if err := v.UnmarshalJSON(ej); err != nil {
+ return err
+ }
+ return nil
+ }
+ var str string
+ if err := dec.decodeString(&str); err != nil {
+ return err
+ }
+ tt, err := time.Parse(format, str)
+ if err != nil {
+ return err
+ }
+ *v = tt
+ return nil
+}
+
+// Add Values functions
+
+// AddTime decodes the JSON value within an object or an array to a *time.Time with the given format
+func (dec *Decoder) AddTime(v *time.Time, format string) error {
+ return dec.Time(v, format)
+}
+
+// Time decodes the JSON value within an object or an array to a *time.Time with the given format
+func (dec *Decoder) Time(v *time.Time, format string) error {
+ err := dec.decodeTime(v, format)
+ if err != nil {
+ return err
+ }
+ dec.called |= 1
+ return nil
+}