summaryrefslogtreecommitdiff
path: root/activity.lua
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-08-31 23:22:45 +0200
committerAki <please@ignore.pl>2023-08-31 23:22:45 +0200
commit1e81f505fc56efba701ba62a6d858d5fb5b70a7f (patch)
tree50b1b181b945082f3745ec43f8c7c0bf29cb2af8 /activity.lua
parentfb1297a0cd84fde95c565178d0d223258d1c2bee (diff)
downloadactivity-1e81f505fc56efba701ba62a6d858d5fb5b70a7f.zip
activity-1e81f505fc56efba701ba62a6d858d5fb5b70a7f.tar.gz
activity-1e81f505fc56efba701ba62a6d858d5fb5b70a7f.tar.bz2
Split out dates module
Diffstat (limited to 'activity.lua')
-rw-r--r--activity.lua26
1 files changed, 4 insertions, 22 deletions
diff --git a/activity.lua b/activity.lua
index 1d1ef8e..cece167 100644
--- a/activity.lua
+++ b/activity.lua
@@ -1,27 +1,9 @@
+local dates = require "activity.dates"
local activity = {}
-function activity.days_in (year)
- if year % 4 ~= 0 or year % 100 == 0 and year % 400 ~= 0 then
- return 365
- end
- return 366
-end
-
-
-function activity.this_year ()
- return os.date"%Y"
-end
-
-
-function activity.first_week_day (year)
- year = year or activity.this_year()
- return os.date("*t", os.time{year=year, month=1, day=1}).wday
-end
-
-
function activity.generate_table (year)
- year = year or activity.this_year()
+ year = year or dates.this_year()
local function spot ()
return [[<td>]]
@@ -52,8 +34,8 @@ function activity.generate_table (year)
local rows = ""
local weekdays = {"", "Mon", "", "Wed", "", "Fri", ""}
- local start_from = activity.first_week_day(year)
- local end_at = (start_from + activity.days_in(year) - 1) % 7
+ local start_from = dates.first_week_day(year)
+ local end_at = (start_from + dates.days_in(year) - 1) % 7
for index, weekday in pairs(weekdays) do
rows = rows .. row(weekday, index >= start_from, index <= end_at)
end