fix #355. Return an error on invalid time strings
parent
40e7d08cc8
commit
6b890e91dc
|
@ -3,9 +3,9 @@ package parser
|
|||
import (
|
||||
"common"
|
||||
"fmt"
|
||||
. "launchpad.net/gocheck"
|
||||
"testing"
|
||||
"time"
|
||||
. "launchpad.net/gocheck"
|
||||
)
|
||||
|
||||
// Hook up gocheck into the gotest runner.
|
||||
|
@ -407,6 +407,13 @@ func (self *QueryParserSuite) TestParseSelectWithInequality(c *C) {
|
|||
c.Assert(rightValue.Name, Equals, "5")
|
||||
}
|
||||
|
||||
// issue #355
|
||||
func (self *QueryParserSuite) TestErrorWithTimeSuffix(c *C) {
|
||||
q := `SELECT * FROM foo where time < now() - '1f'`
|
||||
_, err := ParseSelectQuery(q)
|
||||
c.Assert(err, ErrorMatches, ".*1f.*")
|
||||
}
|
||||
|
||||
func (self *QueryParserSuite) TestParseSelectWithTimeCondition(c *C) {
|
||||
queries := map[string]time.Time{
|
||||
"select value, time from t where time > now() - 1d and time < now() - 1m;": time.Now().Add(-time.Minute).Round(time.Minute).UTC(),
|
||||
|
|
|
@ -249,6 +249,9 @@ func parseTime(value *Value) (int64, error) {
|
|||
|
||||
if value.Type == ValueString {
|
||||
t, err := parseTimeString(value.Name)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return t.UnixNano(), err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue