-
Notifications
You must be signed in to change notification settings - Fork 0
/
json-ext.go
48 lines (39 loc) · 1.09 KB
/
json-ext.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2024.
* Created by Andy Pangaribuan <https://github.com/apangaribuan>.
*
* This product is protected by copyright and distributed under
* licenses restricting copying, distribution and decompilation.
* All Rights Reserved.
*/
package json
import (
"strings"
"time"
"github.com/andypangaribuan/gmod/gm"
jsoniter "github.com/json-iterator/go"
)
var api jsoniter.API
const dvalTimeFormat = "2006-01-02 15:04:05 -07:00"
func init() {
api = configWithCustomTimeFormat
mainJsonCallback = func() {
val, err := gm.Util.ReflectionGet(gm.Conf, "timezone")
if err == nil {
if v, ok := val.(string); ok {
v = strings.TrimSpace(v)
if v != "" {
loc, _ := time.LoadLocation(v)
setDefaultTimeFormat(dvalTimeFormat, loc)
}
}
}
}
setDefaultTimeFormat(dvalTimeFormat, nil)
addLocaleAlias("-", nil)
addTimeFormatAlias("date", "2006-01-02")
addTimeFormatAlias("time", "15:04:05")
addTimeFormatAlias("dt", dvalTimeFormat)
addTimeFormatAlias("dt-ms", "2006-01-02 15:04:05.000 -07:00")
addTimeFormatAlias("dt-micro", "2006-01-02 15:04:05.000000 -07:00")
}