summaryrefslogtreecommitdiff
path: root/teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
committerMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
commite9c24f4af7ed56760f6db7941827d09f6db9020b (patch)
tree62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go
parent58d5e7cfda4781d8a57ec52aefd02983835c301a (diff)
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go')
-rw-r--r--teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go b/teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go
new file mode 100644
index 0000000..6f99e34
--- /dev/null
+++ b/teleirc/matterbridge/vendor/github.com/francoispqt/gojay/encode_time.go
@@ -0,0 +1,68 @@
+package gojay
+
+import (
+ "time"
+)
+
+// EncodeTime encodes a *time.Time to JSON with the given format
+func (enc *Encoder) EncodeTime(t *time.Time, format string) error {
+ if enc.isPooled == 1 {
+ panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
+ }
+ _, _ = enc.encodeTime(t, format)
+ _, err := enc.Write()
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+// encodeInt encodes an int to JSON
+func (enc *Encoder) encodeTime(t *time.Time, format string) ([]byte, error) {
+ enc.writeByte('"')
+ enc.buf = t.AppendFormat(enc.buf, format)
+ enc.writeByte('"')
+ return enc.buf, nil
+}
+
+// AddTimeKey adds an *time.Time to be encoded with the given format, must be used inside an object as it will encode a key
+func (enc *Encoder) AddTimeKey(key string, t *time.Time, format string) {
+ enc.TimeKey(key, t, format)
+}
+
+// TimeKey adds an *time.Time to be encoded with the given format, must be used inside an object as it will encode a key
+func (enc *Encoder) TimeKey(key string, t *time.Time, format string) {
+ if enc.hasKeys {
+ if !enc.keyExists(key) {
+ return
+ }
+ }
+ enc.grow(10 + len(key))
+ r := enc.getPreviousRune()
+ if r != '{' {
+ enc.writeTwoBytes(',', '"')
+ } else {
+ enc.writeByte('"')
+ }
+ enc.writeStringEscape(key)
+ enc.writeBytes(objKeyStr)
+ enc.buf = t.AppendFormat(enc.buf, format)
+ enc.writeByte('"')
+}
+
+// AddTime adds an *time.Time to be encoded with the given format, must be used inside a slice or array encoding (does not encode a key)
+func (enc *Encoder) AddTime(t *time.Time, format string) {
+ enc.Time(t, format)
+}
+
+// Time adds an *time.Time to be encoded with the given format, must be used inside a slice or array encoding (does not encode a key)
+func (enc *Encoder) Time(t *time.Time, format string) {
+ enc.grow(10)
+ r := enc.getPreviousRune()
+ if r != '[' {
+ enc.writeByte(',')
+ }
+ enc.writeByte('"')
+ enc.buf = t.AppendFormat(enc.buf, format)
+ enc.writeByte('"')
+}