Module:Sandbox/Hellknowz/Test: Difference between revisions

Content deleted Content added
m as usual
okay, long weird code
Line 256:
-- Only immediate big improvement is to only seekNextElement() when actually checking that deep, though this will make a (even bigger) mess
 
if (elements[1] == ELEMENT_ONETWODIGITS) then -- '3' or '10'
if (elements[2] == ELEMENT_WHITESPACE) then -- '3 '
if (elements[3] == ELEMENT_MONTHWORD) then -- '3 May'
Line 286:
end
end
end
elseif (elements[2] == ELEMENT_TIMESEPARATOR) then -- '10:'
 
-- Here's a case where we want to optimize or rather add readability and trim redundancy
-- Basically, any time '10am', '10:28', '10:28am', '10:28:27', '10:28:27am' can be followed by a date, which means 5 copies of 30+ lines (urgh)
-- Instead we will only check once, but using a different element index offset if needed, so date might start at element 4 or 5 or 6 etc.
 
local wasTime = false -- by default we didn't find a valid time syntax, we have '10' and that's not a time by itself without 'am/pm' or further precision
local possibleHour, possibleMinute, possibleSecond -- temporary values that we will fill as far as we can when parsing time and use for time+date combo if one is found
local i = 0 -- this is our offset from the closest possible ___location for date seeking
 
elseifif (elements[2] == ELEMENT_TIMESEPARATOR) then -- '10:'
possibleHour = values[1] -- only once we see ':' (or 'am' below) it is likely a time
if (elements[3] == ELEMENT_ONETWODIGITS) then -- '10:28'
if (numberOfElements == 3) then return checkAndOutput(nil, nil, nil, values[1], values[3], nil) end
possibleMinute = values[3]
wasTime = true -- this is a valid final time, so we can check date appended to this
i = 1 -- '10', ':' and '28' are three elements, so we start 1 further from 3
if (elements[4] == ELEMENT_TIMESEPARATOR) then -- '10:28:'
wasTime = false -- a time can't end with separator, so if this is last match, we aren't appending any dates
if (elements[5] == ELEMENT_ONETWODIGITS) then -- '10:28:27'
if (numberOfElements == 5) then return checkAndOutput(nil, nil, nil, values[1], values[3], values[5]) end
if (elements[6]possibleSecond == ELEMENT_WHITESPACE or elementsvalues[65] == ELEMENT_COMMA) then -- '10:28:27, '
wasTime = true -- ifthis (elements[7]is ==a ELEMENT_ONETWODIGITS)valid thenfinal -- '10:28:27time, 3'so we can check date appended to this
if (elements[8]i == ELEMENT_WHITESPACE) then3 -- '10', ':', '28', ':' and '27' are five elements, so we start 3 'further from 3
if (elements[9] == ELEMENT_MONTHWORD) then -- '10:28:27, 3 May'end
end
if (elements[10] == ELEMENT_WHITESPACE) then -- '10:28:27, 3 May '
end
if (elements[11] == ELEMENT_FOURDIGITS) then -- '10:28:27, 3 May 2013'
elseif (elements[2] == ELEMENT_TIMEPERIOD) then -- '10 am'
if (numberOfElements == 11) then return checkAndOutput(values[11], values[9], values[7], values[1], values[3], values[5]) end
if (numberOfElements == 2) then return checkAndOutput(nil, nil, nil, values[1] + periodHourAdd(values[2]), nil, nil) end
end
possibleHour = values[1] + periodHourAdd(values[2]) -- only once we see 'am' (or ':' above) it is likely a endtime
wasTime = true -- this is a valid final time, so we can check date appended to endthis
i = 0 -- '10' and 'am' are two elements, so we start at 3 - default
end
 
if (wasTime) then -- '10am', '10:28', '10:28am', '10:28:27', '10:28:27am' (using just '10:28:27...' below)
-- Now we will try to append a date to the time
if (elements[3+i] == ELEMENT_WHITESPACE or elements[6] == ELEMENT_COMMA) then -- '10:28:27, '
if (elements[4+i] == ELEMENT_ONETWODIGITS) then -- '10:28:27, 3'
if (elements[5+i] == ELEMENT_WHITESPACE) then -- '10:28:27, 3 '
if (elements[6+i] == ELEMENT_MONTHWORD) then -- '10:28:27, 3 May'
if (elements[107+i] == ELEMENT_WHITESPACE) then -- '10:28:27, 3 May '
if (elements[118+i] == ELEMENT_FOURDIGITS) then -- '10:28:27, 3 May 2013'
if (numberOfElements == 118+i) then return checkAndOutput(values[114+i], values[96+i], values[78+i], values[1]possibleHour, values[3]possibleMinute, values[5]possibleSecond) end
end
elseif (elements[7] == ELEMENT_MONTHWORD) then -- '10:28:27, May'end
if (elements[8] == ELEMENT_WHITESPACE) then -- '10:28:27, May 'end
end
ifelseif (elements[93+i] == ELEMENT_ONETWODIGITSELEMENT_MONTHWORD) then -- '10:28:27, May 3'
if (elements[10] == ELEMENT_COMMA or elements[104+i] == ELEMENT_WHITESPACE) then -- '10:28:27, May 3, '
if (elements[115+i] == ELEMENT_FOURDIGITSELEMENT_ONETWODIGITS) then -- '10:28:27, May 3, 2013'
if (elements[6+i] == ELEMENT_COMMA or if (numberOfElementselements[10] == 11ELEMENT_WHITESPACE) then return-- checkAndOutput(values[11]'10:28:27, values[7],May values[9], values[1], values[3], values[5]) end'
if (elements[7+i] == ELEMENT_FOURDIGITS) then -- '10:28:27, May 3, end2013'
if (numberOfElements == 8+i) then return checkAndOutput(values[4+i], values[6+i], values[8+i], possibleHour, possibleMinute, possibleSecond) end
end
end
elseif (elements[7] == ELEMENT_FOURDIGITS) then -- '10:28:27, 2013'end
if (elements[8] == ELEMENT_DATESEPARATOR) then -- '10:28:27, 2013-'end
end
ifelseif (elements[93+i] == ELEMENT_ONETWODIGITSELEMENT_FOURDIGITS) then -- '10:28:27, 2013-05'
if (elements[104+i] == ELEMENT_DATESEPARATOR) then -- '10:28:27, 2013-05-'
if (elements[115+i] == ELEMENT_ONETWODIGITS) then -- '10:28:27, 2013-05-03'
if (numberOfElementselements[6+i] == 11ELEMENT_DATESEPARATOR) then return-- checkAndOutput(values[7]'10:28:27, values[9], values[11], values[1], values[3], values[5]) end2013-05-'
if (elements[7+i] == ELEMENT_ONETWODIGITS) then -- '10:28:27, end2013-05-03'
if (numberOfElements == 8+i) then return checkAndOutput(values[4+i], values[6+i], values[8+i], possibleHour, possibleMinute, possibleSecond) end
end
end
end
Line 328 ⟶ 355:
end
end
end
elseif (elements[2] == ELEMENT_TIMEPERIOD) then -- '10 am'
if (numberOfElements == 2) then return checkAndOutput(nil, nil, nil, values[1] + periodHourAdd(values[2]), nil, nil) end
end
 
elseif (elements[1] == ELEMENT_FOURDIGITS) then -- '2013'