Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Aurélien Vermylen
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
Hide 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 @@
};
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
)
{
var
m1
=
this
.
mom
,
m2
=
other
.
mom
,
...
...
src/queries/core/simplequery.js
View file @
252a08a0
...
...
@@ -204,8 +204,8 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
if
(
value
===
undefined
)
{
return
false
;
}
if
(
value
.
eq
!==
undefined
)
{
return
value
.
eq
(
comparison_value
)
;
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
cmp
(
comparison_value
)
===
0
;
}
if
(
convertStringToRegExp
(
...
...
@@ -248,11 +248,8 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
if
(
value
===
undefined
)
{
return
true
;
}
if
(
value
.
ne
!==
undefined
)
{
return
value
.
ne
(
comparison_value
);
}
if
(
value
.
eq
!==
undefined
)
{
return
!
value
.
eq
(
comparison_value
);
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
cmp
(
comparison_value
)
!==
0
;
}
if
(
convertStringToRegExp
(
...
...
@@ -283,8 +280,8 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
}
if
(
value
.
lt
!==
undefined
)
{
return
value
.
lt
(
comparison_value
)
;
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
cmp
(
comparison_value
)
<
0
;
}
return
value
<
comparison_value
;
};
...
...
@@ -307,11 +304,8 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
}
if
(
value
.
le
!==
undefined
)
{
return
value
.
le
(
comparison_value
);
}
if
(
value
.
lt
!==
undefined
&&
value
.
eq
!==
undefined
)
{
return
value
.
lt
(
comparison_value
)
||
value
.
eq
(
comparison_value
);
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
cmp
(
comparison_value
)
<=
0
;
}
return
value
<=
comparison_value
;
};
...
...
@@ -334,11 +328,8 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
}
if
(
value
.
gt
!==
undefined
)
{
return
value
.
gt
(
comparison_value
);
}
if
(
value
.
lt
!==
undefined
&&
value
.
eq
!==
undefined
)
{
return
!
(
value
.
lt
(
comparison_value
)
||
value
.
eq
(
comparison_value
));
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
cmp
(
comparison_value
)
>
0
;
}
return
value
>
comparison_value
;
};
...
...
@@ -361,11 +352,8 @@ SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
if
(
typeof
value
===
'
object
'
&&
value
.
hasOwnProperty
(
'
content
'
))
{
value
=
value
.
content
;
}
if
(
value
.
ge
!==
undefined
)
{
return
value
.
ge
(
comparison_value
);
}
if
(
value
.
lt
!==
undefined
)
{
return
!
value
.
lt
(
comparison_value
);
if
(
value
.
cmp
!==
undefined
)
{
return
value
.
cmp
(
comparison_value
)
>=
0
;
}
return
value
>=
comparison_value
;
};
...
...
test/queries/jiodate.tests.js
View file @
252a08a0
...
...
@@ -62,11 +62,11 @@
test
(
"
Passing a JIODate object to the constructor clones it
"
,
function
()
{
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
=
[
[
jiodate
.
MSEC
,
...
...
@@ -122,58 +122,11 @@
mp
=
'
-
'
+
precision
;
// 1 vs 2
ok
(
d1
.
eq
(
d2
),
s1
+
'
==
'
+
s2
+
mp
);
ok
(
!
d1
.
ne
(
d2
),
'
not (
'
+
s1
+
'
!=
'
+
s2
+
'
)
'
+
mp
);
ok
(
!
d1
.
gt
(
d2
),
'
not (
'
+
s1
+
'
>
'
+
s2
+
'
)
'
+
mp
);
ok
(
d1
.
ge
(
d2
),
s1
+
'
>=
'
+
s2
+
mp
);
ok
(
!
d1
.
lt
(
d2
),
'
not (
'
+
s1
+
'
<
'
+
s2
+
'
)
'
+
mp
);
ok
(
d1
.
le
(
d2
),
s1
+
'
<=
'
+
s2
+
mp
);
strictEqual
(
d1
.
cmp
(
d2
),
0
,
s1
+
'
cmp
'
+
s2
+
mp
);
// 1 vs 3
ok
(
!
d1
.
eq
(
d3
),
'
not (
'
+
s1
+
'
==
'
+
s3
+
'
)
'
+
mp
);
ok
(
d1
.
ne
(
d3
),
s1
+
'
!=
'
+
s3
+
mp
);
ok
(
!
d1
.
gt
(
d3
),
'
not (
'
+
s1
+
'
>
'
+
s3
+
'
)
'
+
mp
);
ok
(
!
d1
.
ge
(
d3
),
'
not (
'
+
s1
+
'
>=
'
+
s3
+
'
)
'
+
mp
);
ok
(
d1
.
lt
(
d3
),
s1
+
'
<
'
+
s3
+
mp
);
ok
(
d1
.
le
(
d3
),
s1
+
'
<=
'
+
s3
+
mp
);
strictEqual
(
d1
.
cmp
(
d3
),
-
1
,
s1
+
'
cmp
'
+
s3
+
mp
);
// 2 vs 1
ok
(
d2
.
eq
(
d1
),
s2
+
'
==
'
+
s1
+
mp
);
ok
(
!
d2
.
ne
(
d1
),
'
not (
'
+
s2
+
'
!=
'
+
s1
+
'
)
'
+
mp
);
ok
(
!
d2
.
gt
(
d1
),
'
not (
'
+
s2
+
'
>
'
+
s1
+
'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
+
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
);
}
...
...
@@ -267,62 +220,55 @@
dmonth
=
JIODate
(
'
2012-05
'
),
dyear
=
JIODate
(
'
2012
'
);
ok
(
dmsec
.
eq
(
dsec
));
ok
(
dmsec
.
eq
(
dmin
));
ok
(
dmsec
.
eq
(
dhour
));
ok
(
dmsec
.
eq
(
dday
));
ok
(
dmsec
.
eq
(
dmonth
));
ok
(
dmsec
.
eq
(
dyear
));
ok
(
dsec
.
eq
(
dmsec
));
ok
(
dsec
.
eq
(
dmin
));
ok
(
dsec
.
eq
(
dhour
));
ok
(
dsec
.
eq
(
dday
));
ok
(
dsec
.
eq
(
dmonth
));
ok
(
dsec
.
eq
(
dyear
));
ok
(
dmin
.
eq
(
dmsec
));
ok
(
dmin
.
eq
(
dsec
));
ok
(
dmin
.
eq
(
dhour
));
ok
(
dmin
.
eq
(
dday
));
ok
(
dmin
.
eq
(
dmonth
));
ok
(
dmin
.
eq
(
dyear
));
ok
(
dhour
.
eq
(
dmsec
));
ok
(
dhour
.
eq
(
dsec
));
ok
(
dhour
.
eq
(
dmin
));
ok
(
dhour
.
eq
(
dday
));
ok
(
dhour
.
eq
(
dmonth
));
ok
(
dhour
.
eq
(
dyear
));
ok
(
dday
.
eq
(
dmsec
));
ok
(
dday
.
eq
(
dsec
));
ok
(
dday
.
eq
(
dmin
));
ok
(
dday
.
eq
(
dhour
));
ok
(
dday
.
eq
(
dmonth
));
ok
(
dday
.
eq
(
dyear
));
ok
(
dmonth
.
eq
(
dmsec
));
ok
(
dmonth
.
eq
(
dsec
));
ok
(
dmonth
.
eq
(
dmin
));
ok
(
dmonth
.
eq
(
dhour
));
ok
(
dmonth
.
eq
(
dday
));
ok
(
dmonth
.
eq
(
dyear
));
ok
(
dyear
.
eq
(
dmsec
));
ok
(
dyear
.
eq
(
dsec
));
ok
(
dyear
.
eq
(
dmin
));
ok
(
dyear
.
eq
(
dhour
));
ok
(
dyear
.
eq
(
dday
));
ok
(
dyear
.
eq
(
dmonth
));
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
(
dsec
),
0
);
strictEqual
(
dmsec
.
cmp
(
dmin
),
0
);
strictEqual
(
dmsec
.
cmp
(
dhour
),
0
);
strictEqual
(
dmsec
.
cmp
(
dday
),
0
);
strictEqual
(
dmsec
.
cmp
(
dmonth
),
0
);
strictEqual
(
dmsec
.
cmp
(
dyear
),
0
);
strictEqual
(
dsec
.
cmp
(
dmsec
),
0
);
strictEqual
(
dsec
.
cmp
(
dmin
),
0
);
strictEqual
(
dsec
.
cmp
(
dhour
),
0
);
strictEqual
(
dsec
.
cmp
(
dday
),
0
);
strictEqual
(
dsec
.
cmp
(
dmonth
),
0
);
strictEqual
(
dsec
.
cmp
(
dyear
),
0
);
strictEqual
(
dmin
.
cmp
(
dmsec
),
0
);
strictEqual
(
dmin
.
cmp
(
dsec
),
0
);
strictEqual
(
dmin
.
cmp
(
dhour
),
0
);
strictEqual
(
dmin
.
cmp
(
dday
),
0
);
strictEqual
(
dmin
.
cmp
(
dmonth
),
0
);
strictEqual
(
dmin
.
cmp
(
dyear
),
0
);
strictEqual
(
dhour
.
cmp
(
dmsec
),
0
);
strictEqual
(
dhour
.
cmp
(
dsec
),
0
);
strictEqual
(
dhour
.
cmp
(
dmin
),
0
);
strictEqual
(
dhour
.
cmp
(
dday
),
0
);
strictEqual
(
dhour
.
cmp
(
dmonth
),
0
);
strictEqual
(
dhour
.
cmp
(
dyear
),
0
);
strictEqual
(
dday
.
cmp
(
dmsec
),
0
);
strictEqual
(
dday
.
cmp
(
dsec
),
0
);
strictEqual
(
dday
.
cmp
(
dmin
),
0
);
strictEqual
(
dday
.
cmp
(
dhour
),
0
);
strictEqual
(
dday
.
cmp
(
dmonth
),
0
);
strictEqual
(
dday
.
cmp
(
dyear
),
0
);
strictEqual
(
dmonth
.
cmp
(
dmsec
),
0
);
strictEqual
(
dmonth
.
cmp
(
dsec
),
0
);
strictEqual
(
dmonth
.
cmp
(
dmin
),
0
);
strictEqual
(
dmonth
.
cmp
(
dhour
),
0
);
strictEqual
(
dmonth
.
cmp
(
dday
),
0
);
strictEqual
(
dmonth
.
cmp
(
dyear
),
0
);
strictEqual
(
dyear
.
cmp
(
dmsec
),
0
);
strictEqual
(
dyear
.
cmp
(
dsec
),
0
);
strictEqual
(
dyear
.
cmp
(
dmin
),
0
);
strictEqual
(
dyear
.
cmp
(
dhour
),
0
);
strictEqual
(
dyear
.
cmp
(
dday
),
0
);
strictEqual
(
dyear
.
cmp
(
dmonth
),
0
);
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: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