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
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
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
wasTime = true --
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▼
possibleHour = values[1] + periodHourAdd(values[2]) -- only once we see 'am' (or ':' above) it is likely a
wasTime = true -- this is a valid final time, so we can check date appended to
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'
▲
end
end
if (elements[6+i] == ELEMENT_COMMA or
if (elements[7+i] == ELEMENT_FOURDIGITS) then -- '10:28:27, May 3,
if (numberOfElements == 8+i) then return checkAndOutput(values[4+i], values[6+i], values[8+i], possibleHour, possibleMinute, possibleSecond) end
▲ end
end
end
if (elements[7+i] == ELEMENT_ONETWODIGITS) then -- '10:28:27,
if (numberOfElements == 8+i) then return checkAndOutput(values[4+i], values[6+i], values[8+i], possibleHour, possibleMinute, possibleSecond) 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'
|