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

Badlop badlop at gmail.com
Mon Nov 22 16:53:04 MSK 2010


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.

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


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

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?

As a first step, let's modularize your code in an equivalent manner;
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.


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

Note: I didn't test that code.


---
Badlop
ProcessOne


More information about the ejabberd mailing list