comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 386:d54dbbfda3bb

mod_muc_log_http: Simplified calculating day count for a month.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 25 Jul 2011 02:21:40 +0500
parents fec9bc52aa42
children 90d0e90c5b0e
comparison
equal deleted inserted replaced
385:fec9bc52aa42 386:d54dbbfda3bb
119 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component); 119 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component);
120 end 120 end
121 end 121 end
122 122
123 -- Calendar stuff 123 -- Calendar stuff
124 local function getDaysForMonth(month, year) 124 local function get_days_for_month(month, year)
125 local daysCount = 30; 125 if month == 2 then
126 local leapyear = false; 126 local is_leap_year = (year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0;
127 127 return is_leap_year and 29 or 28;
128 if year%4 == 0 and year%100 == 0 then 128 elseif (month < 8 and month%2 == 1) or (month >= 8 and month%2 == 0) then
129 if year%400 == 0 then 129 return 31;
130 leapyear = true; 130 end
131 else 131 return 30;
132 leapyear = false; -- turn of the century but not a leapyear
133 end
134 elseif year%4 == 0 then
135 leapyear = true;
136 end
137
138 if month == 2 and leapyear then
139 daysCount = 29;
140 elseif month == 2 and not leapyear then
141 daysCount = 28;
142 elseif month < 8 and month%2 == 1 or
143 month >= 8 and month%2 == 0
144 then
145 daysCount = 31;
146 end
147 return daysCount;
148 end 132 end
149 133
150 local function createMonth(month, year, dayCallback) 134 local function createMonth(month, year, dayCallback)
151 local htmlStr = html.month.header; 135 local htmlStr = html.month.header;
152 local days = getDaysForMonth(month, year); 136 local days = get_days_for_month(month, year);
153 local time = os_time{year=year, month=month, day=1}; 137 local time = os_time{year=year, month=month, day=1};
154 local dow = tostring(os_date("%a", time)) 138 local dow = tostring(os_date("%a", time))
155 local title = tostring(os_date("%B", time)); 139 local title = tostring(os_date("%B", time));
156 local weekDays = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; 140 local weekDays = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
157 local weekDay = 0; 141 local weekDay = 0;