@@ -116,19 +116,19 @@ function DwarfCalendar:addYears(years)
116116 return self
117117end
118118
119- -- should this be named getYear()?
120- -- returns an integer pair: (year), (year tick count)
121- function DwarfCalendar :getYears ()
122- return self .year , self .year_tick
123- end
124-
125119function DwarfCalendar :setDayOfMonth (day , month )
126120 month = month or self :getMonth ()
127121 -- zero based when converting to ticks
128122 self .year_tick = self :monthsToTicks (month - 1 ) + self :daysToTicks (day - 1 )
129123 return self
130124end
131125
126+ -- should this be named getYear()?
127+ -- returns an integer pair: (year), (year tick count)
128+ function DwarfCalendar :getYears ()
129+ return self .year , self .year_tick
130+ end
131+
132132-- returns an integer pair: (day of month starting from 1), (day tick count)
133133function DwarfCalendar :getDayOfMonth ()
134134 return self :ticksToDayOfMonth () + 1 , self :getDayTicks ()
@@ -194,7 +194,9 @@ function DwarfCalendar:isFullMoon()
194194end
195195
196196function DwarfCalendar :nextFullMoon ()
197- local dateT = DateTime { year = self .year , year_tick = self .year_tick }
197+ local dateT = DateTime { year = self .year ,
198+ year_tick = self .year_tick ,
199+ ticks_per_day = self .ticks_per_day }
198200 if (dateT :isFullMoon ()) then dateT :addDays (1 ) end
199201
200202 local cur_m = dateT :getMonth ()
@@ -243,13 +245,17 @@ end
243245function DwarfCalendar :__add (other )
244246 if DEBUG then self :_debugOps (other ) end
245247 -- normalize() handles adjustments to year and year_tick
246- return DwarfCalendar { year = (self .year + other .year ), year_tick = (self .year_tick + other .year_tick ), ticks_per_day = self .ticks_per_day }
248+ return DwarfCalendar { year = (self .year + other .year ),
249+ year_tick = (self .year_tick + other .year_tick ),
250+ ticks_per_day = self .ticks_per_day }
247251end
248252
249253function DwarfCalendar :__sub (other )
250254 if DEBUG then self :_debugOps (other ) end
251255 -- normalize() handles adjustments to year and year_tick
252- return DwarfCalendar { year = (self .year - other .year ) , year_tick = (self .year_tick - other .year_tick ), ticks_per_day = self .ticks_per_day }
256+ return DwarfCalendar { year = (self .year - other .year ),
257+ year_tick = (self .year_tick - other .year_tick ),
258+ ticks_per_day = self .ticks_per_day }
253259end
254260
255261function DwarfCalendar :_debugOps (other )
@@ -287,20 +293,26 @@ end
287293-- where the caller provides the time unit specifiers
288294-- i.e. getDuration/toDuration('ymd') or toDuration('y', 'm', 'd'), etc
289295function DateTime :toDuration ()
290- return Duration { year = self .year , year_tick = self .year_tick , ticks_per_day = self .ticks_per_day }
296+ return Duration { year = self .year ,
297+ year_tick = self .year_tick ,
298+ ticks_per_day = self .ticks_per_day }
291299end
292300
293301function DateTime :__add (other )
294302 if DEBUG then self :_debugOps (other ) end
295303 -- normalize() handles adjustments to year and year_tick
296- return DateTime { year = (self .year + other .year ), year_tick = (self .year_tick + other .year_tick ), ticks_per_day = self .ticks_per_day }
304+ return DateTime { year = (self .year + other .year ),
305+ year_tick = (self .year_tick + other .year_tick ),
306+ ticks_per_day = self .ticks_per_day }
297307end
298308
299309-- might make sense to return a Duration here
300310function DateTime :__sub (other )
301311 if DEBUG then self :_debugOps (other ) end
302312 -- normalize() handles adjustments to year and year_tick
303- return DateTime { year = (self .year - other .year ) , year_tick = (self .year_tick - other .year_tick ), ticks_per_day = self .ticks_per_day }
313+ return DateTime { year = (self .year - other .year ),
314+ year_tick = (self .year_tick - other .year_tick ),
315+ ticks_per_day = self .ticks_per_day }
304316end
305317
306318function DateTime .now (game_mode )
@@ -311,7 +323,8 @@ function DateTime.now(game_mode)
311323 -- Tick rate defaults to DWARF mode, we should set the tick rate here as well
312324 -- For a custom rate the caller can use setTickRate() or we can add a second
313325 -- optional parameter
314- return DateTime { year = df .global .cur_year , year_tick = ticks }:setTickRate (game_mode )
326+ return DateTime { year = df .global .cur_year ,
327+ year_tick = ticks }:setTickRate (game_mode )
315328end
316329
317330Duration = defclass (Duration , DwarfCalendar )
@@ -343,13 +356,17 @@ end
343356function Duration :__add (other )
344357 if DEBUG then self :_debugOps (other ) end
345358 -- normalize() handles adjustments to year and year_tick
346- return Duration { year = (self .year + other .year ), year_tick = (self .year_tick + other .year_tick ) }
359+ return Duration { year = (self .year + other .year ),
360+ year_tick = (self .year_tick + other .year_tick ),
361+ ticks_per_day = self .ticks_per_day }
347362end
348363
349364function Duration :__sub (other )
350365 if DEBUG then self :_debugOps (other ) end
351366 -- normalize() handles adjustments to year and year_tick
352- return Duration { year = (self .year - other .year ) , year_tick = (self .year_tick - other .year_tick ) }
367+ return Duration { year = (self .year - other .year ),
368+ year_tick = (self .year_tick - other .year_tick ),
369+ ticks_per_day = self .ticks_per_day }
353370end
354371
355372return _ENV
0 commit comments