rename to dateRegEx and provide default value in api docs
This commit is contained in:
@@ -16,11 +16,12 @@
|
||||
OpenLayers.Date = {
|
||||
|
||||
/**
|
||||
* APIProperty: regex
|
||||
* APIProperty: dateRegEx
|
||||
* The regex to be used for validating dates. You can provide your own
|
||||
* regex for instance for adding support for years before BC.
|
||||
* regex for instance for adding support for years before BC. Default
|
||||
* value is: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/
|
||||
*/
|
||||
regex: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/,
|
||||
dateRegEx: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/,
|
||||
|
||||
/**
|
||||
* APIMethod: toISOString
|
||||
@@ -98,7 +99,7 @@ OpenLayers.Date = {
|
||||
*/
|
||||
parse: function(str) {
|
||||
var date;
|
||||
var match = str.match(this.regex);
|
||||
var match = str.match(this.dateRegEx);
|
||||
if (match && (match[1] || match[7])) { // must have at least year or time
|
||||
var year = parseInt(match[1], 10) || 0;
|
||||
var month = (parseInt(match[2], 10) - 1) || 0;
|
||||
|
||||
@@ -177,11 +177,11 @@
|
||||
|
||||
function test_regex(t) {
|
||||
t.plan(1);
|
||||
var regex = OpenLayers.Date.regex;
|
||||
OpenLayers.Date.regex = /^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/;
|
||||
var regex = OpenLayers.Date.dateRegEx;
|
||||
OpenLayers.Date.dateRegEx = /^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/;
|
||||
var date = OpenLayers.Date.parse("-0501-03-01T00:00:00.000Z");
|
||||
t.ok(!isNaN(date.getTime()), "date with negative year is parsed when providing alternative regex");
|
||||
OpenLayers.Date.regex = regex;
|
||||
OpenLayers.Date.dateRegEx = regex;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user