|
31 | 31 | function Time:getDays() -- >>float<< Days as age (including years)
|
32 | 32 | return self.year * 336 + (self.ticks / TU_PER_DAY)
|
33 | 33 | end
|
| 34 | +function Time:getDayInYear() -- >>int<< Current day of the year |
| 35 | + return math.floor (self.ticks / TU_PER_DAY) |
| 36 | +end |
34 | 37 | function Time:getDayInMonth()
|
35 | 38 | return math.floor ( (self.ticks % TU_PER_MONTH) / TU_PER_DAY ) + 1
|
36 | 39 | end
|
@@ -58,16 +61,27 @@ function Time:getDayStr() -- Day as date
|
58 | 61 | end
|
59 | 62 | return d
|
60 | 63 | 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 |
63 | 73 | 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 |
66 | 75 | if self.ticks < other.ticks then
|
| 76 | + -- We subtract a year when ticks delta is less than a year. |
67 | 77 | return Time{ year = (self.year - other.year - 1) , ticks = (TU_PER_YEAR + self.ticks - other.ticks) }
|
68 | 78 | else
|
69 | 79 | return Time{ year = (self.year - other.year) , ticks = (self.ticks - other.ticks) }
|
70 | 80 | end
|
71 | 81 | end
|
| 82 | +function Time:_debugOps(other) |
| 83 | + print(self.year,self.ticks) |
| 84 | + print(other.year,other.ticks) |
| 85 | +end |
72 | 86 |
|
73 | 87 | return _ENV
|
0 commit comments