Module:Coordinates: Difference between revisions

move validation functions
No edit summary
(move validation functions)
Line 56:
coordinateSpec.default = "dec"
end
 
errors = validate( lat, nil, nil, long, nil, nil, 'parseDec' );
-- TODO refactor the validations into separate functions
if (tonumber(lat) or 0) > 90 then
table.insert(errors, {"parseDec","latd>90"})
end
if (tonumber(lat) or 0) < -90 then
table.insert(errors, {"parseDec", "latd<-90"})
end
if (tonumber(long) or 0) >= 360 then
table.insert(errors, {"parseDec", "longd>=360"})
end
if (tonumber(long) or 0) <= -360 then
table.insert(errors, {"parseDec", "longd<=-360"})
end
return coordinateSpec, errors
end
Line 102 ⟶ 89:
coordinateSpec.default = "dms"
end
--[[
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS' );
-- Error reporting
if isEmpty(args[5]long_d) then
table.insert(errors, {"parseDMparseDMS", "Missing longitude" })
end
 
if not isEmpty(args[10]) then
table.insert(errors, {"parseDM", "Unexpected extra parameters"})
end
if (tonumber(args[1]) or 0) > 90 then
table.insert(errors, {"parseDMS", "latd>90"})
end
if (tonumber(args[1]) or 0) < -90 then
table.insert(errors, {"parseDMS", "latd<-90"})
end
if (tonumber(args[2]) or 0) >= 60 then
table.insert(errors, {"parseDMS", "latm>=60"})
end
if (tonumber(args[2]) or 0) < 0 then
table.insert(errors, {"parseDMS", "latm<0"})
end
if (tonumber(args[3]) or 0) >= 60 then
table.insert(errors, {"parseDMS", "lats>=60"})
end
if (tonumber(args[3]) or 0) < 0 then
table.insert(errors, {"parseDMS", "lats<0"})
end
if (tonumber(args[5]) or 0) >= 360 then
table.insert(errors, {"parseDMS", "longd>=360"})
end
if (tonumber(args[5]) or 0) <= -360 then
table.insert(errors, {"parseDMS", "longd<=-360"})
end
if (tonumber(args[6]) or 0) >= 60 then
table.insert(errors, {"parseDMS", "longm>=60"})
end
if (tonumber(args[6]) or 0) < 0 then
table.insert(errors, {"parseDMS", "longm<0"})
end
if (tonumber(args[7]) or 0) >= 60 then
table.insert(errors, {"parseDMS", "longs>=60"})
end
if (tonumber(args[7]) or 0) < 0 then
table.insert(errors, {"parseDMS", "longs<0"})
end
]]
return coordinateSpec, errors
end
Line 352 ⟶ 298:
end
 
function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source )
--- TODO not yet in use
local errors = {};
function validateDegreesLatitude(degrees)
 
if 0+tonumber(degrees) > 90 then
if (tonumber(lat_d) or 0) return "latd> 90" then
table.insert(errors, {source, "latd>90"})
end
if 0+(tonumber(degreeslat_d) or 0) < -90 then
returntable.insert(errors, {source, "latd<-90"})
end
if (tonumber(lat_m) or 0) >= 60 then
return true
table.insert(errors, {source, "latm>=60"})
end
 
--- TODO not yet in use
function validateDegreesLongtitude(degrees)
if 0+tonumber(degrees) >= 360 then
return "longd>=360"
end
if 0+(tonumber(degreeslat_m) or 0) <= -3600 then
returntable.insert(errors, {source, "longdlatm<=-3600"})
end
if (tonumber(lat_s) or 0) >= 60 then
return true
table.insert(errors, {source, "lats>=60"})
end
 
--- TODO not yet in use
function validateMinutes(minutes)
if 0+tonumber(minutes) >= 60 then
return "m>=60"
end
if 0+(tonumber(minuteslat_s) or 0) < 0 then
returntable.insert(errors, {source, "mlats<0"})
end
if (tonumber(long_d) or 0) >= 360 then
return true
table.insert(errors, {source, "longd>=360"})
end
 
--- TODO not yet in use
function validateSeconds(seconds)
if 0+tonumber(seconds) >= 60 then
return "s>=60"
end
if 0+(tonumber(secondslong_d) <or 0) <= -360 then
returntable.insert(errors, {source, "slongd<0=-360"})
end
if (tonumber(long_m) or 0) >= 60 then
return true
table.insert(errors, {source, "longm>=60"})
end
if (tonumber(long_m) or 0) < 0 then
table.insert(errors, {source, "longm<0"})
end
if (tonumber(long_s) or 0) >= 60 then
table.insert(errors, {source, "longs>=60"})
end
if (tonumber(long_s) or 0) < 0 then
table.insert(errors, {source, "longs<0"})
end
return errors;
end
 
 
--- The display function we exposed to Module:Coordinates
Anonymous user