mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Add parseRelativeTime function
This commit is contained in:
parent
7276b3d5ef
commit
a2c58bea82
@ -316,7 +316,24 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
||||
|
||||
return a / b
|
||||
},
|
||||
"parseTime": func(layout, value string) time.Time {
|
||||
"parseTime": customAPIFuncParseTime,
|
||||
"toRelativeTime": dynamicRelativeTimeAttrs,
|
||||
"parseRelativeTime": func(layout, value string) template.HTMLAttr {
|
||||
// Shorthand to do both of the above with a single function call
|
||||
return dynamicRelativeTimeAttrs(customAPIFuncParseTime(layout, value))
|
||||
},
|
||||
}
|
||||
|
||||
for key, value := range globalTemplateFunctions {
|
||||
if _, exists := funcs[key]; !exists {
|
||||
funcs[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return funcs
|
||||
}()
|
||||
|
||||
func customAPIFuncParseTime(layout, value string) time.Time {
|
||||
switch strings.ToLower(layout) {
|
||||
case "rfc3339":
|
||||
layout = time.RFC3339
|
||||
@ -336,15 +353,4 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
||||
}
|
||||
|
||||
return parsed
|
||||
},
|
||||
"toRelativeTime": dynamicRelativeTimeAttrs,
|
||||
}
|
||||
|
||||
for key, value := range globalTemplateFunctions {
|
||||
if _, exists := funcs[key]; !exists {
|
||||
funcs[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return funcs
|
||||
}()
|
||||
|
Loading…
x
Reference in New Issue
Block a user