forked from aquasecurity/trivy-iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utc_now.go
47 lines (41 loc) · 1.38 KB
/
utc_now.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
package functions
import (
"strings"
"time"
)
func UTCNow(args ...interface{}) interface{} {
if len(args) > 1 {
return nil
}
if len(args) == 1 {
format, ok := args[0].(string)
if ok {
goFormat := convertFormat(format)
return time.Now().UTC().Format(goFormat)
}
}
return time.Now().UTC().Format(time.RFC3339)
}
// don't look directly at this code
func convertFormat(format string) string {
goFormat := format
goFormat = strings.ReplaceAll(goFormat, "yyyy", "2006")
goFormat = strings.ReplaceAll(goFormat, "yy", "06")
goFormat = strings.ReplaceAll(goFormat, "MMMM", "January")
goFormat = strings.ReplaceAll(goFormat, "MMM", "Jan")
goFormat = strings.ReplaceAll(goFormat, "MM", "01")
goFormat = strings.ReplaceAll(goFormat, "M", "1")
goFormat = strings.ReplaceAll(goFormat, "dd", "02")
goFormat = strings.ReplaceAll(goFormat, "d", "2")
goFormat = strings.ReplaceAll(goFormat, "HH", "15")
goFormat = strings.ReplaceAll(goFormat, "H", "3")
goFormat = strings.ReplaceAll(goFormat, "hh", "03")
goFormat = strings.ReplaceAll(goFormat, "h", "3")
goFormat = strings.ReplaceAll(goFormat, "mm", "04")
goFormat = strings.ReplaceAll(goFormat, "m", "4")
goFormat = strings.ReplaceAll(goFormat, "ss", "05")
goFormat = strings.ReplaceAll(goFormat, "s", "5")
goFormat = strings.ReplaceAll(goFormat, "tt", "PM")
goFormat = strings.ReplaceAll(goFormat, "t", "PM")
return goFormat
}