Skip to content

Commit

Permalink
Implemented date/time evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Knetic committed Dec 28, 2014
1 parent 8174bc3 commit 4042673
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions EvaluableExpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package govaluate
import (
"errors"
"math"
"time"
)

/*
Expand Down Expand Up @@ -351,6 +352,7 @@ func evaluateValue(stream *tokenStream, parameters map[string]interface{}) (inte
case NUMERIC : fallthrough
case STRING : fallthrough
case BOOLEAN : return token.Value, nil;
case TIME : return float64(token.Value.(time.Time).Unix()), nil;
default : break;
}

Expand Down
54 changes: 54 additions & 0 deletions evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,60 @@ func TestNoParameterEvaluation(test *testing.T) {
Input: "1 + 5 ^ 3 % 2 * 5",
Expected: 6.0,
},
EvaluationTest {

Name: "Identical date equivalence",
Input: "'2014-01-02 14:12:22' == '2014-01-02 14:12:22'",
Expected: true,
},
EvaluationTest {

Name: "Positive date GT",
Input: "'2014-01-02 14:12:22' > '2014-01-02 12:12:22'",
Expected: true,
},
EvaluationTest {

Name: "Negative date GT",
Input: "'2014-01-02 14:12:22' > '2014-01-02 16:12:22'",
Expected: false,
},
EvaluationTest {

Name: "Positive date GTE",
Input: "'2014-01-02 14:12:22' >= '2014-01-02 12:12:22'",
Expected: true,
},
EvaluationTest {

Name: "Negative date GTE",
Input: "'2014-01-02 14:12:22' >= '2014-01-02 16:12:22'",
Expected: false,
},
EvaluationTest {

Name: "Positive date LT",
Input: "'2014-01-02 14:12:22' < '2014-01-02 16:12:22'",
Expected: true,
},
EvaluationTest {

Name: "Negative date LT",
Input: "'2014-01-02 14:12:22' < '2014-01-02 11:12:22'",
Expected: false,
},
EvaluationTest {

Name: "Positive date LTE",
Input: "'2014-01-02 09:12:22' <= '2014-01-02 12:12:22'",
Expected: true,
},
EvaluationTest {

Name: "Negative date LTE",
Input: "'2014-01-02 14:12:22' <= '2014-01-02 11:12:22'",
Expected: false,
},
}

runEvaluationTests(evaluationTests, test)
Expand Down

0 comments on commit 4042673

Please sign in to comment.