diff --git a/dashboard/src/views/RuleEdit.vue b/dashboard/src/views/RuleEdit.vue index 16a59c0..5c2d90a 100644 --- a/dashboard/src/views/RuleEdit.vue +++ b/dashboard/src/views/RuleEdit.vue @@ -443,11 +443,11 @@ let helpers = { {text: 'explode STR ","', displayText: 'explode(s, sep string) []string | 字符串分隔成数组'}, {text: 'ident "IDENT_STR" STR', displayText: 'ident(ident string, message string) string | 多行字符串统一缩进'}, {text: 'json JSONSTR', displayText: 'json(content string) string | JSON 字符串格式化'}, - {text: 'datetime DATETIME', displayText: 'datetime(datetime time.Time) string | 时间格式化展示为 2006-01-02 15:04:05 格式,时区选择北京/重庆'}, - {text: 'datetime_noloc DATETIME',displayText: 'datetime_noloc(datetime time.Time) string | 时间格式化展示为 2006-01-02 15:04:05 格式,默认时区'}, - {text: 'reformat_datetime_str ORIGINAL_LAYOUT TARGET_LAYOUT DATETIME_STR',displayText: 'reformat_datetime_str(originalLayout, targetLayout string, dt string) string | 重新格式化时间字符串,默认时区'}, - {text: 'parse_datetime_str LAYOUT DATETIME_STR',displayText: 'parse_datetime_str(layout string, dt string) time.Time | 将时间字符串解析为时间对象,默认时区'}, - {text: 'parse_datetime_str_rfc3339 DATETIME_STR',displayText: 'parse_datetime_str_rfc3339(dt string) time.Time | 将时间字符串解析为时间对象,格式为 RFC3339,默认时区'}, + {text: 'datetime LAYOUT DATETIME', displayText: 'datetime(layout string, datetime time.Time) string | 时间格式化展示为 2006-01-02 15:04:05 格式,时区选择北京/重庆'}, + {text: 'datetime_noloc LAYOUT DATETIME',displayText: 'datetime_noloc(layout string, datetime time.Time) string | 时间格式化展示为 2006-01-02 15:04:05 格式,默认时区'}, + {text: 'reformat_datetime_str ORIGINAL_LAYOUT TARGET_LAYOUT DATETIME_STR',displayText: 'reformat_datetime_str(originalLayout, targetLayout string, dt string) string | 重新格式化时间字符串'}, + {text: 'parse_datetime_str LAYOUT DATETIME_STR',displayText: 'parse_datetime_str(layout string, dt string) time.Time | 将时间字符串解析为时间对象'}, + {text: 'parse_datetime_str_rfc3339 DATETIME_STR',displayText: 'parse_datetime_str_rfc3339(dt string) time.Time | 将时间字符串解析为时间对象,格式为 RFC3339'}, {text: 'json_get "KEY" "DEFAULT" JSONSTR', displayText: 'json_get(key string, defaultValue string, body string) string | 将 body 解析为 json,然后获取 key 的值,失败返回 defaultValue'}, {text: 'json_gets "KEY" "DEFAULT" JSONSTR', displayText: 'json_gets(key string, defaultValue string, body string) string | 将 body 解析为 json,然后获取 key 的值(可以使用逗号分割多个key作为备选),失败返回 defaultValue'}, {text: 'json_array "KEY" JSONSTR', displayText: 'json_array(key string, body string) []string | 将 body 解析为 json,然后获取 key 的值(数组值)'}, diff --git a/pkg/template/template.go b/pkg/template/template.go index e1e0d06..a938f0d 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -155,19 +155,20 @@ func parseDatetimeRFC3339(dt string) time.Time { // reformatDatetimeStr 时间字符串重新格式化 func reformatDatetimeStr(originalLayout, targetLayout string, dt string) string { - return parseDatetime(originalLayout, dt).Format(targetLayout) + loc, _ := time.LoadLocation("Asia/Chongqing") + return parseDatetime(originalLayout, dt).In(loc).Format(targetLayout) } // datetimeFormat 时间格式化,不使用Location -func datetimeFormatNoLoc(datetime time.Time) string { - return datetime.Format("2006-01-02 15:04:05") +func datetimeFormatNoLoc(layout string, datetime time.Time) string { + return datetime.Format(layout) } // datetimeFormat 时间格式化 -func datetimeFormat(datetime time.Time) string { +func datetimeFormat(layout string, datetime time.Time) string { loc, _ := time.LoadLocation("Asia/Chongqing") - return datetime.In(loc).Format("2006-01-02 15:04:05") + return datetime.In(loc).Format(layout) } type KvPairs []jsonutils.KvPair