From 13693b676029f26cae53d6ef7f729aacdf90e629 Mon Sep 17 00:00:00 2001 From: dhthwy <302825+dhthwy@users.noreply.github.com> Date: Thu, 19 Oct 2023 23:11:05 -0400 Subject: [PATCH] Update lua df time class. Fix refs --- depends/googletest | 2 +- library/lua/time.lua | 22 ++++++++++++++++++---- scripts | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/depends/googletest b/depends/googletest index 2fe3bd994b3..116b7e55281 160000 --- a/depends/googletest +++ b/depends/googletest @@ -1 +1 @@ -Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2 +Subproject commit 116b7e55281c4200151524b093ecc03757a4ffda diff --git a/library/lua/time.lua b/library/lua/time.lua index 58a976c8b8c..3712a04a849 100644 --- a/library/lua/time.lua +++ b/library/lua/time.lua @@ -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 @@ -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 diff --git a/scripts b/scripts index 76189285df0..1fcc83838e4 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 76189285df019d668f530a55fafe8a66a7c30c05 +Subproject commit 1fcc83838e471fd8ef50cc6d6cb9259b69f1d847