Skip to content

This package can parse date match expression, which used by ElasticSearch

License

Notifications You must be signed in to change notification settings

zhuliquan/datemath_parser

Repository files navigation

datemath-parser

this package is pure go package, this package can parse date match expression, which used by ElasticSearch.

Date Math Definition

you can click here to see date math definition. The date type supports using date math expression when using it in a range date query. The expression starts with an "anchor" date, which can be either now or a date string (in the applicable format) ending with ||. It can then follow by a math expression, supporting +, - and / (time rounding symbol). The support time units are:

time unit symbol meaning
y Years
M Months
w Weeks
d Days
h Hours
H Hours
m Minutes
s Seconds

Here are some samples: now+1h, now+1h+1m, now+1h/d, 2012-01-01||+1M/d.

Note, when doing range type searches, and the upper value is inclusive, the rounding will properly be rounded to the ceiling instead of flooring it.

Usage

Returns a time.Time struct object, which store utc time.

package main

import (
    "fmt"
    "github.com/zhuliquan/datemath_parser"
)

func main() {
    var parser = datemath_parser.NewDataMathParser()
    if t, err := parser.Parse("now+7M/d"); err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(t)
    } 
}

About

This package can parse date match expression, which used by ElasticSearch

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages