mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Merge pull request #1984 from mattbostock/1983_add_minute
PromQL: Add minute() function
This commit is contained in:
commit
03855679a1
|
@ -909,6 +909,13 @@ func funcHour(ev *evaluator, args Expressions) model.Value {
|
|||
})
|
||||
}
|
||||
|
||||
// === minute(v vector) scalar ===
|
||||
func funcMinute(ev *evaluator, args Expressions) model.Value {
|
||||
return dateWrapper(ev, args, func(t time.Time) model.SampleValue {
|
||||
return model.SampleValue(t.Minute())
|
||||
})
|
||||
}
|
||||
|
||||
// === month(v vector) scalar ===
|
||||
func funcMonth(ev *evaluator, args Expressions) model.Value {
|
||||
return dateWrapper(ev, args, func(t time.Time) model.SampleValue {
|
||||
|
@ -1102,6 +1109,13 @@ var functions = map[string]*Function{
|
|||
ReturnType: model.ValVector,
|
||||
Call: funcMinOverTime,
|
||||
},
|
||||
"minute": {
|
||||
Name: "minute",
|
||||
ArgTypes: []model.ValueType{model.ValVector},
|
||||
OptionalArgs: 1,
|
||||
ReturnType: model.ValVector,
|
||||
Call: funcMinute,
|
||||
},
|
||||
"month": {
|
||||
Name: "month",
|
||||
ArgTypes: []model.ValueType{model.ValVector},
|
||||
|
|
21
promql/testdata/functions.test
vendored
21
promql/testdata/functions.test
vendored
|
@ -370,19 +370,40 @@ clear
|
|||
eval instant at 0m year()
|
||||
{} 1970
|
||||
|
||||
eval instant at 0m year(vector(1136239445))
|
||||
{} 2006
|
||||
|
||||
eval instant at 0m month()
|
||||
{} 1
|
||||
|
||||
eval instant at 0m month(vector(1136239445))
|
||||
{} 1
|
||||
|
||||
eval instant at 0m day_of_month()
|
||||
{} 1
|
||||
|
||||
eval instant at 0m day_of_month(vector(1136239445))
|
||||
{} 2
|
||||
|
||||
# Thursday.
|
||||
eval instant at 0m day_of_week()
|
||||
{} 4
|
||||
|
||||
eval instant at 0m day_of_week(vector(1136239445))
|
||||
{} 1
|
||||
|
||||
eval instant at 0m hour()
|
||||
{} 0
|
||||
|
||||
eval instant at 0m hour(vector(1136239445))
|
||||
{} 22
|
||||
|
||||
eval instant at 0m minute()
|
||||
{} 0
|
||||
|
||||
eval instant at 0m minute(vector(1136239445))
|
||||
{} 4
|
||||
|
||||
# 2008-12-31 23:59:59 just before leap second.
|
||||
eval instant at 0m year(vector(1230767999))
|
||||
{} 2008
|
||||
|
|
Loading…
Reference in a new issue