Skip to content

Commit

Permalink
Update lua df time class. Fix refs
Browse files Browse the repository at this point in the history
  • Loading branch information
dhthwy committed Oct 22, 2023
1 parent f61e91a commit 56cc90a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions library/lua/time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ end
function Time:getDays() -- >>float<< Days as age (including years)
return self.year * 336 + (self.ticks / TU_PER_DAY)
end
function Time:getDayInYear() -- >>int<< Current day of the year
return math.floor (self.ticks / TU_PER_DAY)
end
function Time:getDayInMonth()
return math.floor ( (self.ticks % TU_PER_MONTH) / TU_PER_DAY ) + 1
end
Expand Down Expand Up @@ -58,16 +61,27 @@ function Time:getDayStr() -- Day as date
end
return d
end
--function Time:__add()
--end
function Time:__add(other)
if DEBUG then self:_debugOps(other) end
if self.ticks + other.ticks > TU_PER_YEAR then
-- We add a year when ticks delta is greater than a year.
return Time{ year = (self.year + other.year + 1) , ticks = (self.ticks + other.ticks - TU_PER_YEAR) }
else
return Time{ year = (self.year + other.year) , ticks = (self.ticks + other.ticks) }
end
end
function Time:__sub(other)
if DEBUG then print(self.year,self.ticks) end
if DEBUG then print(other.year,other.ticks) end
if DEBUG then self:_debugOps(other) end
if self.ticks < other.ticks then
-- We subtract a year when ticks delta is less than a year.
return Time{ year = (self.year - other.year - 1) , ticks = (TU_PER_YEAR + self.ticks - other.ticks) }
else
return Time{ year = (self.year - other.year) , ticks = (self.ticks - other.ticks) }
end
end
function Time:_debugOps(other)
print(self.year,self.ticks)
print(other.year,other.ticks)
end
return _ENV

0 comments on commit 56cc90a

Please sign in to comment.