comparison plugins/mod_time.lua @ 12632:70ae68bb0aa5

mod_time: Return sub-second precision timestamps Because why not? Who even has this module enabled?
author Kim Alvefur <zash@zash.se>
date Sun, 14 Aug 2022 17:47:13 +0200
parents 0ba963e82ac7
children f928cb5c5d04
comparison
equal deleted inserted replaced
12631:9524bb7f3944 12632:70ae68bb0aa5
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 local st = require "util.stanza"; 9 local st = require "util.stanza";
10 local datetime = require "util.datetime".datetime; 10 local datetime = require "util.datetime".datetime;
11 local now = require "util.time".now;
11 local legacy = require "util.datetime".legacy; 12 local legacy = require "util.datetime".legacy;
12 13
13 -- XEP-0202: Entity Time 14 -- XEP-0202: Entity Time
14 15
15 module:add_feature("urn:xmpp:time"); 16 module:add_feature("urn:xmpp:time");
16 17
17 local function time_handler(event) 18 local function time_handler(event)
18 local origin, stanza = event.origin, event.stanza; 19 local origin, stanza = event.origin, event.stanza;
19 origin.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"}) 20 origin.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"})
20 :tag("tzo"):text("+00:00"):up() -- TODO get the timezone in a platform independent fashion 21 :tag("tzo"):text("+00:00"):up() -- TODO get the timezone in a platform independent fashion
21 :tag("utc"):text(datetime())); 22 :tag("utc"):text(datetime(now())));
22 return true; 23 return true;
23 end 24 end
24 25
25 module:hook("iq-get/bare/urn:xmpp:time:time", time_handler); 26 module:hook("iq-get/bare/urn:xmpp:time:time", time_handler);
26 module:hook("iq-get/host/urn:xmpp:time:time", time_handler); 27 module:hook("iq-get/host/urn:xmpp:time:time", time_handler);