Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
jio
Commits
252a08a0
Commit
252a08a0
authored
Dec 30, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom operators: simplified to only require .cmp()
parent
5b0db3bd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
170 deletions
+63
-170
src/jio.date/jiodate.js
src/jio.date/jiodate.js
+0
-41
src/queries/core/simplequery.js
src/queries/core/simplequery.js
+12
-24
test/queries/jiodate.tests.js
test/queries/jiodate.tests.js
+51
-105
No files found.
src/jio.date/jiodate.js
View file @
252a08a0
...
@@ -124,47 +124,6 @@
...
@@ -124,47 +124,6 @@
};
};
JIODate
.
prototype
.
eq
=
function
(
other
)
{
var
p
=
lesserPrecision
(
this
.
_precision
,
other
.
_precision
);
return
this
.
mom
.
isSame
(
other
.
mom
,
p
);
};
JIODate
.
prototype
.
ne
=
function
(
other
)
{
return
(
!
this
.
eq
(
other
));
};
JIODate
.
prototype
.
gt
=
function
(
other
)
{
var
p
=
lesserPrecision
(
this
.
_precision
,
other
.
_precision
);
return
this
.
mom
.
isAfter
(
other
.
mom
,
p
);
};
JIODate
.
prototype
.
lt
=
function
(
other
)
{
// XXX using the lesser precision cannot change the result (but check with business calendar)
var
p
=
lesserPrecision
(
this
.
_precision
,
other
.
_precision
);
return
this
.
mom
.
isBefore
(
other
.
mom
,
p
);
};
JIODate
.
prototype
.
ge
=
function
(
other
)
{
// XXX using the lesser precision cannot change the result (but check with business calendar)
var
m1
=
this
.
mom
,
m2
=
other
.
mom
,
p
=
lesserPrecision
(
this
.
_precision
,
other
.
_precision
);
return
m1
.
isAfter
(
m2
,
p
)
||
m1
.
isSame
(
m2
,
p
);
};
JIODate
.
prototype
.
le
=
function
(
other
)
{
var
m1
=
this
.
mom
,
m2
=
other
.
mom
,
p
=
lesserPrecision
(
this
.
_precision
,
other
.
_precision
);
return
m1
.
isBefore
(
m2
,
p
)
||
m1
.
isSame
(
m2
,
p
);
};
JIODate
.
prototype
.
cmp
=
function
(
other
)
{
JIODate
.
prototype
.
cmp
=
function
(
other
)
{
var
m1
=
this
.
mom
,
var
m1
=
this
.
mom
,
m2
=
other
.
mom
,
m2
=
other
.
mom
,
...
...
src/queries/core/simplequery.js
View file @
252a08a0
...
@@ -204,8 +204,8 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
...
@@ -204,8 +204,8 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
if
(
value
===
undefined
)
{
if
(
value
===
undefined
)
{
return
false
;
return
false
;
}
}
if
(
value
.
eq
!==
undefined
)
{
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
eq
(
comparison_value
)
;
return
value
.
cmp
(
comparison_value
)
===
0
;
}
}
if
(
if
(
convertStringToRegExp
(
convertStringToRegExp
(
...
@@ -248,11 +248,8 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
...
@@ -248,11 +248,8 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
if
(
value
===
undefined
)
{
if
(
value
===
undefined
)
{
return
true
;
return
true
;
}
}
if
(
value
.
ne
!==
undefined
)
{
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
ne
(
comparison_value
);
return
value
.
cmp
(
comparison_value
)
!==
0
;
}
if
(
value
.
eq
!==
undefined
)
{
return
!
value
.
eq
(
comparison_value
);
}
}
if
(
if
(
convertStringToRegExp
(
convertStringToRegExp
(
...
@@ -283,8 +280,8 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
...
@@ -283,8 +280,8 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
value
=
value
.
content
;
}
}
if
(
value
.
lt
!==
undefined
)
{
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
lt
(
comparison_value
)
;
return
value
.
cmp
(
comparison_value
)
<
0
;
}
}
return
value
<
comparison_value
;
return
value
<
comparison_value
;
};
};
...
@@ -307,11 +304,8 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
...
@@ -307,11 +304,8 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
value
=
value
.
content
;
}
}
if
(
value
.
le
!==
undefined
)
{
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
le
(
comparison_value
);
return
value
.
cmp
(
comparison_value
)
<=
0
;
}
if
(
value
.
lt
!==
undefined
&&
value
.
eq
!==
undefined
)
{
return
value
.
lt
(
comparison_value
)
||
value
.
eq
(
comparison_value
);
}
}
return
value
<=
comparison_value
;
return
value
<=
comparison_value
;
};
};
...
@@ -334,11 +328,8 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
...
@@ -334,11 +328,8 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
value
=
value
.
content
;
}
}
if
(
value
.
gt
!==
undefined
)
{
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
gt
(
comparison_value
);
return
value
.
cmp
(
comparison_value
)
>
0
;
}
if
(
value
.
lt
!==
undefined
&&
value
.
eq
!==
undefined
)
{
return
!
(
value
.
lt
(
comparison_value
)
||
value
.
eq
(
comparison_value
));
}
}
return
value
>
comparison_value
;
return
value
>
comparison_value
;
};
};
...
@@ -361,11 +352,8 @@ SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
...
@@ -361,11 +352,8 @@ SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
value
=
value
.
content
;
}
}
if
(
value
.
ge
!==
undefined
)
{
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
ge
(
comparison_value
);
return
value
.
cmp
(
comparison_value
)
>=
0
;
}
if
(
value
.
lt
!==
undefined
)
{
return
!
value
.
lt
(
comparison_value
);
}
}
return
value
>=
comparison_value
;
return
value
>=
comparison_value
;
};
};
...
...
test/queries/jiodate.tests.js
View file @
252a08a0
...
@@ -62,11 +62,11 @@
...
@@ -62,11 +62,11 @@
test
(
"
Passing a JIODate object to the constructor clones it
"
,
function
()
{
test
(
"
Passing a JIODate object to the constructor clones it
"
,
function
()
{
var
d
=
JIODate
(
'
2012-05-06
'
);
var
d
=
JIODate
(
'
2012-05-06
'
);
ok
(
d
.
eq
(
JIODate
(
d
))
);
strictEqual
(
d
.
cmp
(
JIODate
(
d
)),
0
);
});
});
test
(
"
Comparison with
eq/ne/gt/lt/ge/le/cmp
- any precision
"
,
function
()
{
test
(
"
Comparison with
.cmp()
- any precision
"
,
function
()
{
var
data
=
[
var
data
=
[
[
[
jiodate
.
MSEC
,
jiodate
.
MSEC
,
...
@@ -122,58 +122,11 @@
...
@@ -122,58 +122,11 @@
mp
=
'
-
'
+
precision
;
mp
=
'
-
'
+
precision
;
// 1 vs 2
ok
(
d1
.
eq
(
d2
),
s1
+
'
==
'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
,
s3
+
'
cmp
'
+
s1
+
mp
);
strictEqual
(
d3
.
cmp
(
d1
),
1
,
s3
+
'
cmp
'
+
s1
+
mp
);
// 3 vs 2
ok
(
!
d3
.
eq
(
d2
),
'
not (
'
+
s3
+
'
==
'
+
s2
+
'
)
'
+
mp
);
ok
(
d3
.
ne
(
d2
),
s3
+
'
!=
'
+
s2
+
mp
);
ok
(
d3
.
gt
(
d2
),
s3
+
'
>
'
+
s2
+
mp
);
ok
(
d3
.
ge
(
d2
),
s3
+
'
>=
'
+
s2
+
mp
);
ok
(
!
d3
.
lt
(
d2
),
'
not (
'
+
s3
+
'
<
'
+
s2
+
'
)
'
+
mp
);
ok
(
!
d3
.
le
(
d2
),
'
not (
'
+
s3
+
'
<=
'
+
s2
+
'
)
'
+
mp
);
strictEqual
(
d3
.
cmp
(
d2
),
1
,
s1
+
'
cmp
'
+
s2
+
mp
);
strictEqual
(
d3
.
cmp
(
d2
),
1
,
s1
+
'
cmp
'
+
s2
+
mp
);
}
}
...
@@ -267,62 +220,55 @@
...
@@ -267,62 +220,55 @@
dmonth
=
JIODate
(
'
2012-05
'
),
dmonth
=
JIODate
(
'
2012-05
'
),
dyear
=
JIODate
(
'
2012
'
);
dyear
=
JIODate
(
'
2012
'
);
ok
(
dmsec
.
eq
(
dsec
));
strictEqual
(
dmsec
.
cmp
(
dsec
),
0
);
ok
(
dmsec
.
eq
(
dmin
));
strictEqual
(
dmsec
.
cmp
(
dmin
),
0
);
ok
(
dmsec
.
eq
(
dhour
));
strictEqual
(
dmsec
.
cmp
(
dhour
),
0
);
ok
(
dmsec
.
eq
(
dday
));
strictEqual
(
dmsec
.
cmp
(
dday
),
0
);
ok
(
dmsec
.
eq
(
dmonth
));
strictEqual
(
dmsec
.
cmp
(
dmonth
),
0
);
ok
(
dmsec
.
eq
(
dyear
));
strictEqual
(
dmsec
.
cmp
(
dyear
),
0
);
ok
(
dsec
.
eq
(
dmsec
));
strictEqual
(
dsec
.
cmp
(
dmsec
),
0
);
ok
(
dsec
.
eq
(
dmin
));
strictEqual
(
dsec
.
cmp
(
dmin
),
0
);
ok
(
dsec
.
eq
(
dhour
));
strictEqual
(
dsec
.
cmp
(
dhour
),
0
);
ok
(
dsec
.
eq
(
dday
));
strictEqual
(
dsec
.
cmp
(
dday
),
0
);
ok
(
dsec
.
eq
(
dmonth
));
strictEqual
(
dsec
.
cmp
(
dmonth
),
0
);
ok
(
dsec
.
eq
(
dyear
));
strictEqual
(
dsec
.
cmp
(
dyear
),
0
);
ok
(
dmin
.
eq
(
dmsec
));
strictEqual
(
dmin
.
cmp
(
dmsec
),
0
);
ok
(
dmin
.
eq
(
dsec
));
strictEqual
(
dmin
.
cmp
(
dsec
),
0
);
ok
(
dmin
.
eq
(
dhour
));
strictEqual
(
dmin
.
cmp
(
dhour
),
0
);
ok
(
dmin
.
eq
(
dday
));
strictEqual
(
dmin
.
cmp
(
dday
),
0
);
ok
(
dmin
.
eq
(
dmonth
));
strictEqual
(
dmin
.
cmp
(
dmonth
),
0
);
ok
(
dmin
.
eq
(
dyear
));
strictEqual
(
dmin
.
cmp
(
dyear
),
0
);
ok
(
dhour
.
eq
(
dmsec
));
strictEqual
(
dhour
.
cmp
(
dmsec
),
0
);
ok
(
dhour
.
eq
(
dsec
));
strictEqual
(
dhour
.
cmp
(
dsec
),
0
);
ok
(
dhour
.
eq
(
dmin
));
strictEqual
(
dhour
.
cmp
(
dmin
),
0
);
ok
(
dhour
.
eq
(
dday
));
strictEqual
(
dhour
.
cmp
(
dday
),
0
);
ok
(
dhour
.
eq
(
dmonth
));
strictEqual
(
dhour
.
cmp
(
dmonth
),
0
);
ok
(
dhour
.
eq
(
dyear
));
strictEqual
(
dhour
.
cmp
(
dyear
),
0
);
ok
(
dday
.
eq
(
dmsec
));
strictEqual
(
dday
.
cmp
(
dmsec
),
0
);
ok
(
dday
.
eq
(
dsec
));
strictEqual
(
dday
.
cmp
(
dsec
),
0
);
ok
(
dday
.
eq
(
dmin
));
strictEqual
(
dday
.
cmp
(
dmin
),
0
);
ok
(
dday
.
eq
(
dhour
));
strictEqual
(
dday
.
cmp
(
dhour
),
0
);
ok
(
dday
.
eq
(
dmonth
));
strictEqual
(
dday
.
cmp
(
dmonth
),
0
);
ok
(
dday
.
eq
(
dyear
));
strictEqual
(
dday
.
cmp
(
dyear
),
0
);
ok
(
dmonth
.
eq
(
dmsec
));
strictEqual
(
dmonth
.
cmp
(
dmsec
),
0
);
ok
(
dmonth
.
eq
(
dsec
));
strictEqual
(
dmonth
.
cmp
(
dsec
),
0
);
ok
(
dmonth
.
eq
(
dmin
));
strictEqual
(
dmonth
.
cmp
(
dmin
),
0
);
ok
(
dmonth
.
eq
(
dhour
));
strictEqual
(
dmonth
.
cmp
(
dhour
),
0
);
ok
(
dmonth
.
eq
(
dday
));
strictEqual
(
dmonth
.
cmp
(
dday
),
0
);
ok
(
dmonth
.
eq
(
dyear
));
strictEqual
(
dmonth
.
cmp
(
dyear
),
0
);
ok
(
dyear
.
eq
(
dmsec
));
strictEqual
(
dyear
.
cmp
(
dmsec
),
0
);
ok
(
dyear
.
eq
(
dsec
));
strictEqual
(
dyear
.
cmp
(
dsec
),
0
);
ok
(
dyear
.
eq
(
dmin
));
strictEqual
(
dyear
.
cmp
(
dmin
),
0
);
ok
(
dyear
.
eq
(
dhour
));
strictEqual
(
dyear
.
cmp
(
dhour
),
0
);
ok
(
dyear
.
eq
(
dday
));
strictEqual
(
dyear
.
cmp
(
dday
),
0
);
ok
(
dyear
.
eq
(
dmonth
));
strictEqual
(
dyear
.
cmp
(
dmonth
),
0
);
ok
(
!
dmsec
.
lt
(
JIODate
(
'
2012-05-02 06:07:08
'
)));
ok
(
dmsec
.
lt
(
JIODate
(
'
2012-05-02 06:07:09
'
)));
ok
(
dmsec
.
le
(
JIODate
(
'
2012-05-02 06:07:08
'
)));
ok
(
!
dmsec
.
gt
(
JIODate
(
'
2012-05-02 06:07:08
'
)));
ok
(
dmsec
.
ge
(
JIODate
(
'
2012-05-02 06:07:08
'
)));
ok
(
!
dmsec
.
ne
(
JIODate
(
'
2012-05-02 06:07:08
'
)));
ok
(
dmsec
.
eq
(
JIODate
(
'
2012-05-02 06:07:08
'
)));
strictEqual
(
dmsec
.
cmp
(
JIODate
(
'
2012-05-02 06:07:07
'
)),
+
1
);
strictEqual
(
dmsec
.
cmp
(
JIODate
(
'
2012-05-02 06:07:07
'
)),
+
1
);
strictEqual
(
dmsec
.
cmp
(
JIODate
(
'
2012-05-02 06:07:08
'
)),
0
);
strictEqual
(
dmsec
.
cmp
(
JIODate
(
'
2012-05-02 06:07:08
'
)),
0
);
strictEqual
(
dmsec
.
cmp
(
JIODate
(
'
2012-05-02 06:07:09
'
)),
-
1
);
strictEqual
(
dmsec
.
cmp
(
JIODate
(
'
2012-05-02 06:07:09
'
)),
-
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment