MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / parseTimeValue

Function parseTimeValue

sdk/cliproxy/auth/types.go:666–701  ·  view source on GitHub ↗
(v any)

Source from the content-addressed store, hash-verified

664}
665
666func parseTimeValue(v any) (time.Time, bool) {
667 switch value := v.(type) {
668 case string:
669 s := strings.TrimSpace(value)
670 if s == "" {
671 return time.Time{}, false
672 }
673 layouts := []string{
674 time.RFC3339,
675 time.RFC3339Nano,
676 "2006-01-02 15:04:05",
677 "2006-01-02 15:04",
678 "2006-01-02T15:04:05Z07:00",
679 }
680 for _, layout := range layouts {
681 if ts, err := time.Parse(layout, s); err == nil {
682 return ts, true
683 }
684 }
685 if unix, err := strconv.ParseInt(s, 10, 64); err == nil {
686 return normaliseUnix(unix), true
687 }
688 case float64:
689 return normaliseUnix(int64(value)), true
690 case int64:
691 return normaliseUnix(value), true
692 case json.Number:
693 if i, err := value.Int64(); err == nil {
694 return normaliseUnix(i), true
695 }
696 if f, err := value.Float64(); err == nil {
697 return normaliseUnix(int64(f)), true
698 }
699 }
700 return time.Time{}, false
701}
702
703func normaliseUnix(raw int64) time.Time {
704 if raw <= 0 {

Callers 3

expirationFromMapFunction · 0.85
authLastRefreshTimestampFunction · 0.85
lookupMetadataTimeFunction · 0.85

Calls 1

normaliseUnixFunction · 0.85

Tested by

no test coverage detected