26 lines
750 B
Go
26 lines
750 B
Go
package gateway
|
||
|
||
import (
|
||
"strings"
|
||
"time"
|
||
)
|
||
|
||
// upstreamLocation 是上游时间字段的时区(北京时间,固定 +08:00,不依赖系统时区数据库)。
|
||
var upstreamLocation = time.FixedZone("CST", 8*3600)
|
||
|
||
var upstreamTimeLayouts = []string{"2006-01-02 15:04:05", "2006-01-02T15:04:05", "2006/01/02 15:04:05"}
|
||
|
||
// parseUpstreamTime 按北京时间解析上游时间字符串,空或无法解析返回 nil。
|
||
func parseUpstreamTime(raw string) *time.Time {
|
||
value := strings.TrimSpace(raw)
|
||
if value == "" || strings.EqualFold(value, "null") {
|
||
return nil
|
||
}
|
||
for _, layout := range upstreamTimeLayouts {
|
||
if parsed, err := time.ParseInLocation(layout, value, upstreamLocation); err == nil {
|
||
return &parsed
|
||
}
|
||
}
|
||
return nil
|
||
}
|