-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
local _ENV = mkmodule('time') | ||
|
||
local TU_PER_DAY = 1200 | ||
--[[ | ||
if advmode then TU_PER_DAY = 86400 ? or only for cur_year_tick? | ||
advmod_TU / 72 = ticks | ||
--]] | ||
local TU_PER_MONTH = TU_PER_DAY * 28 | ||
local TU_PER_YEAR = TU_PER_MONTH * 12 | ||
|
||
local MONTHS = { | ||
'Granite', | ||
'Slate', | ||
'Felsite', | ||
'Hematite', | ||
'Malachite', | ||
'Galena', | ||
'Limestone', | ||
'Sandstone', | ||
'Timber', | ||
'Moonstone', | ||
'Opal', | ||
'Obsidian', | ||
} | ||
|
||
Time = defclass(Time) | ||
function Time:init(args) | ||
self.year = args.year or 0 | ||
self.ticks = args.ticks or 0 | ||
end | ||
function Time:getDays() -- >>float<< Days as age (including years) | ||
return self.year * 336 + (self.ticks / TU_PER_DAY) | ||
end | ||
function Time:getDayInMonth() | ||
return math.floor ( (self.ticks % TU_PER_MONTH) / TU_PER_DAY ) + 1 | ||
end | ||
function Time:getMonths() -- >>int<< Months as age (not including years) | ||
return math.floor (self.ticks / TU_PER_MONTH) | ||
end | ||
function Time:getYears() -- >>int<< | ||
return self.year | ||
end | ||
function Time:getMonthStr() -- Month as date | ||
return MONTHS[self:getMonths()+1] or 'error' | ||
end | ||
function Time:getDayStr() -- Day as date | ||
local d = math.floor ( (self.ticks % TU_PER_MONTH) / TU_PER_DAY ) + 1 | ||
if d == 11 or d == 12 or d == 13 then | ||
d = tostring(d)..'th' | ||
elseif d % 10 == 1 then | ||
d = tostring(d)..'st' | ||
elseif d % 10 == 2 then | ||
d = tostring(d)..'nd' | ||
elseif d % 10 == 3 then | ||
d = tostring(d)..'rd' | ||
else | ||
d = tostring(d)..'th' | ||
end | ||
return d | ||
end | ||
--function Time:__add() | ||
--end | ||
function Time:__sub(other) | ||
if DEBUG then print(self.year,self.ticks) end | ||
if DEBUG then print(other.year,other.ticks) end | ||
if self.ticks < other.ticks then | ||
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 | ||
|
||
return _ENV |
Submodule scripts
updated
from 1fcc83 to 761892