String to Epoch Returning nil.
3 replies



23.06.19 04:34:52 am
Hi, I'm experimenting with some time/date functions and I've come acoss this strange issue:
The code:
The input:
The output:
I've checked and the table does seem to contain the information it's supposed to.
The code:
Code:
1
2
3
4
5
2
3
4
5
function string_to_epoch(str)
local t_hour, t_min, t_sec, t_day, t_month, t_year = str:match('(%d+):(%d+):(%d+) (%d+)/(%d+)/(%d+)')
return os.time({ year = t_year, month = t_month, day = t_day, hour = t_hour, min = t_min, sec = t_sec, isdst = false })
end
local t_hour, t_min, t_sec, t_day, t_month, t_year = str:match('(%d+):(%d+):(%d+) (%d+)/(%d+)/(%d+)')
return os.time({ year = t_year, month = t_month, day = t_day, hour = t_hour, min = t_min, sec = t_sec, isdst = false })
end
The input:
Code:
1
'05:34:01 23/06/19'
The output:
nil
I've checked and the table does seem to contain the information it's supposed to.
It's hard being the best girl in the whole entire world
Try using
table.sort
?Code:
1
return os.time(table.sort({ year = t_year, month = t_month, day = t_day, hour = t_hour, min = t_min, sec = t_sec, isdst = false }))
Weirdly enough it seems to fix it... Thanks.
It's hard being the best girl in the whole entire world



