Merge pull request #729 from tschaub/date
WFS date filter literal not sent as ISO format
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* @requires OpenLayers/Format/Filter.js
|
||||
* @requires OpenLayers/Format/XML.js
|
||||
* @requires OpenLayers/Filter/Function.js
|
||||
* @requires OpenLayers/BaseTypes/Date.js
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -246,6 +247,25 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: encodeLiteral
|
||||
* Generates the string representation of a value for use in <Literal>
|
||||
* elements. The default encoder writes Date values as ISO 8601
|
||||
* strings.
|
||||
*
|
||||
* Parameters:
|
||||
* value - {Object} Literal value to encode
|
||||
*
|
||||
* Returns:
|
||||
* {String} String representation of the provided value.
|
||||
*/
|
||||
encodeLiteral: function(value) {
|
||||
if (value instanceof Date) {
|
||||
value = OpenLayers.Date.toISOString(value);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: writeOgcExpression
|
||||
* Limited support for writing OGC expressions. Currently it supports
|
||||
@@ -405,9 +425,10 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
});
|
||||
},
|
||||
"Literal": function(value) {
|
||||
// no ogc:expression handling for now
|
||||
var encode = this.encodeLiteral ||
|
||||
OpenLayers.Format.Filter.v1.prototype.encodeLiteral;
|
||||
return this.createElementNSPlus("ogc:Literal", {
|
||||
value: value
|
||||
value: encode(value)
|
||||
});
|
||||
},
|
||||
"LowerBoundary": function(filter) {
|
||||
|
||||
@@ -247,6 +247,59 @@
|
||||
}
|
||||
|
||||
|
||||
function test_date_writing(t) {
|
||||
t.plan(1);
|
||||
|
||||
// ISO 8601: 2010-11-27T18:19:15.123Z
|
||||
var start = new Date(Date.UTC(2010, 10, 27, 18, 19, 15, 123));
|
||||
|
||||
// ISO 8601: 2011-12-27T18:19:15.123Z
|
||||
var end = new Date(Date.UTC(2011, 11, 27, 18, 19, 15, 123));
|
||||
|
||||
var filter = new OpenLayers.Filter.Comparison({
|
||||
type: OpenLayers.Filter.Comparison.BETWEEN,
|
||||
property: "when",
|
||||
lowerBoundary: start,
|
||||
upperBoundary: end
|
||||
});
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_0_0();
|
||||
|
||||
var got = format.write(filter);
|
||||
var exp = readXML("BetweenDates");
|
||||
t.xml_eq(got, exp, "comparison filter with dates");
|
||||
}
|
||||
|
||||
|
||||
function test_custom_date_writing(t) {
|
||||
t.plan(1);
|
||||
|
||||
// ISO 8601: 2010-11-27T18:19:15.123Z
|
||||
var start = new Date(Date.UTC(2010, 10, 27, 18, 19, 15, 123));
|
||||
|
||||
// ISO 8601: 2011-12-27T18:19:15.123Z
|
||||
var end = new Date(Date.UTC(2011, 11, 27, 18, 19, 15, 123));
|
||||
|
||||
var filter = new OpenLayers.Filter.Comparison({
|
||||
type: OpenLayers.Filter.Comparison.BETWEEN,
|
||||
property: "when",
|
||||
lowerBoundary: start,
|
||||
upperBoundary: end
|
||||
});
|
||||
|
||||
var format = new OpenLayers.Format.Filter({
|
||||
encodeLiteral: function(value) {
|
||||
// return just the date and not the time portion
|
||||
return OpenLayers.Date.toISOString(value).split("T").shift();
|
||||
}
|
||||
});
|
||||
|
||||
var got = format.write(filter);
|
||||
var exp = readXML("CustomBetweenDates");
|
||||
t.xml_eq(got, exp, "comparison filter with dates");
|
||||
}
|
||||
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
@@ -288,6 +341,32 @@
|
||||
</ogc:Not>
|
||||
</ogc:Filter>
|
||||
--></div>
|
||||
<div id="BetweenDates"><!--
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>when</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>2010-11-27T18:19:15.123Z</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>2011-12-27T18:19:15.123Z</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Filter>
|
||||
--></div>
|
||||
<div id="CustomBetweenDates"><!--
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>when</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>2010-11-27</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>2011-12-27</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Filter>
|
||||
--></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user