diff --git a/src/jlib.erl b/src/jlib.erl index c3a3433aa..6c65663d5 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -153,7 +153,7 @@ rsm_encode_count(Count, Arr)-> i2b(I) when is_integer(I) -> list_to_binary(integer_to_list(I)); i2b(L) when is_list(L) -> list_to_binary(L). -%% Timezone = utc | {Hours, Minutes} +%% Timezone = utc | {Sign::string(), {Hours, Minutes}} | {Hours, Minutes} %% Hours = integer() %% Minutes = integer() timestamp_to_iso({{Year, Month, Day}, {Hour, Minute, Second}}, Timezone) -> @@ -162,6 +162,8 @@ timestamp_to_iso({{Year, Month, Day}, {Hour, Minute, Second}}, Timezone) -> [Year, Month, Day, Hour, Minute, Second])), Timezone_string = case Timezone of utc -> "Z"; + {Sign, {TZh, TZm}} -> + io_lib:format("~s~2..0w:~2..0w", [Sign, TZh, TZm]); {TZh, TZm} -> Sign = case TZh >= 0 of true -> "+"; diff --git a/src/mod_time.erl b/src/mod_time.erl index 4f2eb1ac3..4adb1039e 100644 --- a/src/mod_time.erl +++ b/src/mod_time.erl @@ -59,14 +59,8 @@ process_local_iq(_From, _To, #iq{type = get} = IQ_Rec) -> {UTC, UTC_diff} = jlib:timestamp_to_iso(Now_universal, utc), Seconds_diff = calendar:datetime_to_gregorian_seconds(Now_local) - calendar:datetime_to_gregorian_seconds(Now_universal), - {Hd, Md, _} = case Seconds_diff >= 0 of - true -> - calendar:seconds_to_time(Seconds_diff); - false -> - {Hd0, Md0, Sd0} = calendar:seconds_to_time(-Seconds_diff), - {-Hd0, Md0, Sd0} - end, - {_, TZO_diff} = jlib:timestamp_to_iso({{0, 0, 0}, {0, 0, 0}}, {Hd, Md}), + {Hd, Md, _} = calendar:seconds_to_time(abs(Seconds_diff)), + {_, TZO_diff} = jlib:timestamp_to_iso({{0, 0, 0}, {0, 0, 0}}, {sign(Seconds_diff), {Hd, Md}}), Result = #xmlel{ns = ?NS_TIME, name = 'time', children = [ #xmlel{ns = ?NS_TIME, name = 'tzo', children = [ #xmlcdata{cdata = list_to_binary(TZO_diff)}]}, @@ -89,3 +83,6 @@ process_local_iq90(_From, _To, #iq{type = get} = IQ_Rec) -> exmpp_iq:result(IQ_Rec, Result); process_local_iq90(_From, _To, #iq{type = set} = IQ_Rec) -> exmpp_iq:error(IQ_Rec, 'not-allowed'). + +sign(N) when N < 0 -> "-"; +sign(_) -> "+".