Comparison

mod_http_muc_log/mod_http_muc_log.lua @ 2836:52a7c0f6aea1

mod_http_muc_log: Add a function for rounding timestamps down to midnight
author Kim Alvefur <zash@zash.se>
date Sat, 18 Nov 2017 20:38:30 +0100
parent 2826:ed26608920d4
child 2837:bd5eb429ebab
comparison
equal deleted inserted replaced
2835:b69ef062806e 2836:52a7c0f6aea1
62 62
63 -- Time zone hack? 63 -- Time zone hack?
64 local t_diff = os_time(os_date("*t")) - os_time(os_date("!*t")); 64 local t_diff = os_time(os_date("*t")) - os_time(os_date("!*t"));
65 local function time(t) 65 local function time(t)
66 return os_time(t) + t_diff; 66 return os_time(t) + t_diff;
67 end
68 local function date_floor(t)
69 return t - t % 86400;
67 end 70 end
68 71
69 -- Fetch one item 72 -- Fetch one item
70 local function find_once(room, query, retval) 73 local function find_once(room, query, retval)
71 if query then query.limit = 1; else query = { limit = 1 }; end 74 if query then query.limit = 1; else query = { limit = 1 }; end
111 repeat 114 repeat
112 local when = find_once(room, { start = next_day; }, 3); 115 local when = find_once(room, { start = next_day; }, 3);
113 if not when then break; end 116 if not when then break; end
114 local t = os_date("!*t", when); 117 local t = os_date("!*t", when);
115 dates:set(t.year, t.month, t.day, when ); 118 dates:set(t.year, t.month, t.day, when );
116 next_day = when + (86400 - (when % 86400)); 119 next_day = date_floor(when) + 86400;
117 until not next_day; 120 until not next_day;
118 end 121 end
119 122
120 local years = {}; 123 local years = {};
121 124