Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhuliquan/datemath_parser
This package can parse date match expression, which used by ElasticSearch
https://github.com/zhuliquan/datemath_parser
datemath elasticsearch golang parser
Last synced: 3 days ago
JSON representation
This package can parse date match expression, which used by ElasticSearch
- Host: GitHub
- URL: https://github.com/zhuliquan/datemath_parser
- Owner: zhuliquan
- License: mit
- Created: 2021-12-18T14:59:39.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-24T16:27:13.000Z (8 months ago)
- Last Synced: 2024-11-16T20:37:25.497Z (2 months ago)
- Topics: datemath, elasticsearch, golang, parser
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html#date-math) 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.
```golang
package mainimport (
"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)
}
}
```