not all numbers are dates

This commit is contained in:
j 2020-04-28 21:25:28 +02:00
parent 3eb6e3f432
commit 39229c99a3

View file

@ -618,6 +618,16 @@ Ox.URL = function(options) {
});
}
function isDate(str) {
var values = /^(-?\d+)-?(\d+)?-?(\d+)? ?(\d+)?:?(\d+)?:?(\d+)?\.?(\d+)?$/
.exec(str);
return Boolean(
values &&
parseInt(values[1]) <= 9999 &&
(!values[2] || parseInt(values[2]) <= 12) &&
(!values[3] || parseInt(values[3]) <= 31)
)
}
function getSpanType(str, types) {
Ox.Log('Core', 'getSpanType', str, types)
@ -633,7 +643,7 @@ Ox.URL = function(options) {
: canBeLocation && length == 4 ? 'location'
// leaves us with [-]D[.D][,[-]D[.D]]
: canBeDuration ? 'duration'
: canBeDate && !/\./.test(str) && !/^\d{7}$/.test(str) && !/^\d{8}$/.test(str) ? 'date'
: canBeDate && isDate(str) ? 'date'
: canBeLocation && length == 2 ? 'location'
: canBeNumber && /^\d+$/.test(str) ? 'number'
: canBeString && str.length ? 'string'