Skip to content

Commit 13693b6

Browse files
committed
Update lua df time class. Fix refs
1 parent f61e91a commit 13693b6

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

depends/googletest

Submodule googletest updated 374 files

library/lua/time.lua

+18-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ end
3131
function Time:getDays() -- >>float<< Days as age (including years)
3232
return self.year * 336 + (self.ticks / TU_PER_DAY)
3333
end
34+
function Time:getDayInYear() -- >>int<< Current day of the year
35+
return math.floor (self.ticks / TU_PER_DAY)
36+
end
3437
function Time:getDayInMonth()
3538
return math.floor ( (self.ticks % TU_PER_MONTH) / TU_PER_DAY ) + 1
3639
end
@@ -58,16 +61,27 @@ function Time:getDayStr() -- Day as date
5861
end
5962
return d
6063
end
61-
--function Time:__add()
62-
--end
64+
function Time:__add(other)
65+
if DEBUG then self:_debugOps(other) end
66+
if self.ticks + other.ticks > TU_PER_YEAR then
67+
-- We add a year when ticks delta is greater than a year.
68+
return Time{ year = (self.year + other.year + 1) , ticks = (self.ticks + other.ticks - TU_PER_YEAR) }
69+
else
70+
return Time{ year = (self.year + other.year) , ticks = (self.ticks + other.ticks) }
71+
end
72+
end
6373
function Time:__sub(other)
64-
if DEBUG then print(self.year,self.ticks) end
65-
if DEBUG then print(other.year,other.ticks) end
74+
if DEBUG then self:_debugOps(other) end
6675
if self.ticks < other.ticks then
76+
-- We subtract a year when ticks delta is less than a year.
6777
return Time{ year = (self.year - other.year - 1) , ticks = (TU_PER_YEAR + self.ticks - other.ticks) }
6878
else
6979
return Time{ year = (self.year - other.year) , ticks = (self.ticks - other.ticks) }
7080
end
7181
end
82+
function Time:_debugOps(other)
83+
print(self.year,self.ticks)
84+
print(other.year,other.ticks)
85+
end
7286

7387
return _ENV

scripts

0 commit comments

Comments
 (0)