[ejabberd] mod_time:process_local_iq/3 doesn't work for negative TZ values

Alexander Zhukov zuav at yandex.ru
Fri Nov 26 13:10:43 MSK 2010


>>>>> Badlop  (B) writes:
Thank you for your reply.

 B> 2010/11/18 Alexander Zhukov <zuav at yandex.ru>:
 >> I'd made a quick fix (see below) and it works for us.  But I'm not
 >> sure if TZ value ({Hd, Md}) can have an Hd == 0.

 B> Let's assume it can have, or may have in the future if some country
 B> changes his timezone.


 >> F.e. if Seconds_diff == -1800 the fix will fail. Even worse, it will
 >> produce an incorrect result.

 B> I'll focus in those 4 lines:

 >>            Sign = sign(Seconds_diff),
 >>            {_, TZO_diff} = jlib:timestamp_to_iso({{0, 0, 0}, {0, 0, 0}}, {Sign*Hd, Md}),
 >> sign(N) when N < 0 -> -1;
 >> sign(_)            -> 1.

 >> Does anybody have a better ideas?

 B> As a first step, let's modularize your code in an equivalent manner;
 B> rewriting those 4 lines into:

 >>    {_, TZO_diff} = jlib:timestamp_to_iso({{0, 0, 0}, {0, 0, 0}}, get_hm(Hd, Md, Seconds_diff) ),
 >> get_hm(H, M, SecDiff) ->
 >>     Sign = sign(SecDiff),
 >>     {Sign*Hd, Md}.
 >> sign(N) when N < 0 -> -1;
 >> sign(_)            -> 1.


 B> To allow the get_hm function to support H==0, I think it can be
 B> rewritten like this:
 B> get_hm(H, M, SecDiff) when SecDiff < 0 and H /= 0 ->
 B>     {-1*H, M};
 B> get_hm(H, M, SecDiff) when SecDiff < 0 and H == 0 ->
 B>     {H, -1*M};
 B> get_hm(H, M, SecDiff) when SecDiff >= 0 ->
 B>     {H, M}.

 B> Note: I didn't test that code.

I've already thought along these lines. From my point of view a better
solution will be to add Sign to a Timezone argument of the
jlib:timezone_to_iso/2  like this:

jlib:timestamp_to_iso({{0, 0, 0}, {0, 0, 0}},
                      {sign(Seconds_diff), {Hd, Md}}),

I've checked the sources and found that jlib:timestamp_to_iso/2 called
only from mod_time:process_local_iq/3 and from jlib:timestamp_to_xml/4.

jlib:timestamp_to_xml/4 is called many times but only with Timezone =
utc.

Thus the proposed change seems to be safe.

In the message I did included the patch againt ejabberd-2.1.5 sources.
Please, feel free to apply it to ejabberd if you like it.

BTW, what is the Right way to send patches/fixes to ejabberd?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: timezone.patch
Type: text/x-diff
Size: 1945 bytes
Desc: not available
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20101126/078b2f5c/attachment.patch>
-------------- next part --------------


-- 
Alexander Zhukov


More information about the ejabberd mailing list