English String to Epoch Returning nil.

3 replies
Goto Page
To the start Previous 1 Next To the start
Up
Goo
User
Offline Off
Hi, I'm experimenting with some time/date functions and I've come acoss this strange issue:

The code:
Code:
1
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


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.
23.06.19 08:47:27 am
Up
Boolean
GAME BANNED
Offline Off
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 }))
23.06.19 09:11:40 am
Up
Goo
User
Offline Off
Weirdly enough it seems to fix it... Thanks.
23.06.19 09:21:23 am
Up
Boolean
GAME BANNED
Offline Off
Glad it works
To the start Previous 1 Next To the start