Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
correction checking dates
Browse files Browse the repository at this point in the history
  • Loading branch information
al66 committed May 17, 2017
1 parent 35825f0 commit b6b93d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
19 changes: 10 additions & 9 deletions lib/cond.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var evalCond = function( tokens, cond ) {
next = true;
});
// date at start
token.val.replace(/^,?(\d{2}[./-]\d{2}[./-]\d{4}$)(.*)/g, function( match, $low, $rest, offset, string ){
token.val.replace(/^,?(\d{2}[./-]\d{2}[./-]\d{4})(.*)/g, function( match, $low, $rest, offset, string ){
if ($rest && $rest.length > 0) tokens.push({"sign":token.sign, "val":$rest});
if (!token.method) token.method = "EQ";
if ($low.length > 0 ) {
Expand Down Expand Up @@ -96,7 +96,7 @@ var compiler = function( condStr) {
while (tokens && tokens.length>0) {
evalCond(tokens, cond);
};
//console.log('cond:', cond);
console.log('cond:', cond);
return cond;
};

Expand All @@ -115,20 +115,21 @@ var check = function(data, cond) {

var compare = function(single) {
any = true;
if (single.date) data = Date.parse(data);
let value = data;
if (single.date) value = Date.parse(data);
switch (single.method) {
case 'EQ':
return data == single.low;
return value == single.low;
case 'GT':
return data > single.low;
return value > single.low;
case 'GE':
return data >= single.low;
return value >= single.low;
case 'LT':
return data < single.low;
return value < single.low;
case 'LE':
return data <= single.low;
return value <= single.low;
case 'BT':
return (data >= single.low && data <= single.high);
return (value >= single.low && value <= single.high);
default:
return false;
}
Expand Down
21 changes: 20 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,37 @@ var testDigits = [
]
]
];

var testDates = [
['< 01.01.2017', [
[new Date(Date.parse('12.12.2015')), true],
[new Date(Date.parse('05.03.2019')), false]
]
],
['01.01.2017', [
[new Date(Date.parse('01.01.2017')), true],
['01.01.2017', true]
]
],
['[01.01.2017..01.01.2018],01.01.2019,[03.01.2019..01.03.2019]', [
[new Date(Date.parse('12.12.2015')), false],
[new Date(Date.parse('01.01.2017')), true],
[new Date(Date.parse('05.06.2017')), true],
[new Date(Date.parse('01.02.2018')), false],
['01.01.2019', true],
[new Date(Date.parse('01.01.2019')), true]
]
],
['> 11/03/2017', [
[new Date(Date.parse('12/01/2017')), true],
[new Date(Date.parse('10/04/2017')), false]
]
],
['>=11/03/2017', [
[new Date(Date.parse('11/03/2017')), true],
[new Date(Date.parse('11/02/2017')), false]
]
],
['11/03/2017', [
[new Date(Date.parse('12/01/2017')), false],
['11/03/2017', true]
Expand Down Expand Up @@ -147,7 +167,6 @@ var testStrings = [
]
];


/*
* Test Digits
*/
Expand Down

0 comments on commit b6b93d1

Please sign in to comment.