Skip to content

Commit

Permalink
Move time time converter function to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
CattoGamer committed Oct 5, 2024
1 parent e391711 commit 711e762
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
18 changes: 18 additions & 0 deletions workshop/gamemodes/cinema_modded/gamemode/extensions/sh_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ function SecondsToISO_8601(seconds)
return (t.h and t.h .. "h" or "") .. (t.m and t.m .. "m" or "") .. (t.s and t.s .. "s" or "")
end

-- Helper function for converting HH:MM:SS time strings
local hhmmss = "(%d+):(%d+):(%d+)"
local mmss = "(%d+):(%d+)"
function ConvertTimeToSeconds(time)
local hr, min, sec = string.match(time, hhmmss)

-- Not in HH:MM:SS, try MM:SS
if not hr then
min, sec = string.match(time, mmss)
if not min then return end -- Not in MM:SS, give up
hr = 0
end

return tonumber(hr) * 3600 +
tonumber(min) * 60 +
tonumber(sec)
end

-- Get the value for an attribute from a html element
function ParseElementAttribute( element, attribute )
if not element then return end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ if SERVER then

end

local hhmmss = "(%d+):(%d+):(%d+)"
local mmss = "(%d+):(%d+)"
function THEATER:Seek( seconds )

if not IsVideoTimed(self:VideoType()) then return end
Expand All @@ -501,18 +499,7 @@ if SERVER then

-- Seconds isn't a number, check HH:MM:SS
if not tonumber(seconds) then
local hr, min, sec = string.match(seconds, hhmmss)

-- Not in HH:MM:SS, try MM:SS
if not hr then
min, sec = string.match(seconds, mmss)
if not min then return end -- Not in MM:SS, give up
hr = 0
end

seconds = tonumber(hr) * 3600 +
tonumber(min) * 60 +
tonumber(sec)
seconds = util.ConvertTimeToSeconds(seconds)
end

-- If it's not one of those two things then it will fall trough wihtout any changes.
Expand Down

0 comments on commit 711e762

Please sign in to comment.