2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local st = require "util.stanza";
10 local datetime = require "util.datetime".datetime;
11 local legacy = require "util.datetime".legacy;
13 -- XEP-0202: Entity Time
15 module:add_feature("urn:xmpp:time");
17 local function time_handler(event)
18 local origin, stanza = event.origin, event.stanza;
19 if stanza.attr.type == "get" then
20 origin.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"})
21 :tag("tzo"):text("+00:00"):up() -- TODO get the timezone in a platform independent fashion
22 :tag("utc"):text(datetime()));
27 module:hook("iq/bare/urn:xmpp:time:time", time_handler);
28 module:hook("iq/host/urn:xmpp:time:time", time_handler);
30 -- XEP-0090: Entity Time (deprecated)
32 module:add_feature("jabber:iq:time");
34 local function legacy_time_handler(event)
35 local origin, stanza = event.origin, event.stanza;
36 if stanza.attr.type == "get" then
37 origin.send(st.reply(stanza):tag("query", {xmlns="jabber:iq:time"})
38 :tag("utc"):text(legacy()));
43 module:hook("iq/bare/jabber:iq:time:query", legacy_time_handler);
44 module:hook("iq/host/jabber:iq:time:query", legacy_time_handler);