Skip to content

Commit

Permalink
Detach the GetServerOffset and GetToday functions from the Broker_Cur…
Browse files Browse the repository at this point in the history
…rency object.
  • Loading branch information
Torhal committed Apr 21, 2021
1 parent 2e49bfa commit fae81e1
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions Broker_Currency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,34 +106,26 @@ local function ShowOptionIcon(currencyID)
end
private.ShowOptionIcon = ShowOptionIcon

do
local offset

function Broker_Currency:GetServerOffset()
if offset then
return offset
end

local serverHour, serverMinute = _G.GetGameTime()
local utcHour = tonumber(date("!%H"))
local utcMinute = tonumber(date("!%M"))
local ser = serverHour + serverMinute / 60
local utc = utcHour + utcMinute / 60

offset = math.floor((ser - utc) * 2 + 0.5) / 2

if offset >= 12 then
offset = offset - 24
elseif offset < -12 then
offset = offset + 24
end

return offset
local function GetServerOffset()
local serverHour, serverMinute = _G.GetGameTime()
local utcHour = tonumber(date("!%H"))
local utcMinute = tonumber(date("!%M"))
local ser = serverHour + serverMinute / 60
local utc = utcHour + utcMinute / 60

local offset = math.floor((ser - utc) * 2 + 0.5) / 2

if offset >= 12 then
offset = offset - 24
elseif offset < -12 then
offset = offset + 24
end

return offset
end

local function GetToday(self)
return math.floor((time() / 60 / 60 + self:GetServerOffset()) / 24)
local function GetToday()
return math.floor((time() / 60 / 60 + GetServerOffset()) / 24)
end

local CreateMoneyString
Expand Down Expand Up @@ -360,7 +352,7 @@ function Broker_Currency:Update()
playerInfo.money = currentMoney

-- Update Statistics
local today = GetToday(self)
local today = GetToday()

if not self.lastTime then
self.lastTime = today
Expand Down Expand Up @@ -946,7 +938,7 @@ do

-- Initialize statistics
self.last.money = _G.GetMoney()
self.lastTime = GetToday(self)
self.lastTime = GetToday()

local lastWeek = self.lastTime - 13

Expand Down

0 comments on commit fae81e1

Please sign in to comment.