mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Add fractions of seconds to <delay/> timestamps
Include fractions of a second with XEP-0203 <delay/> timestamps, as specified in XEP-0082. Old timestamp: 2014-05-19T11:55:00Z New timestamp: 2014-05-19T11:55:00.123Z
This commit is contained in:
parent
a78a0a65fe
commit
0a19dac4fd
23
src/jlib.erl
23
src/jlib.erl
@ -622,8 +622,7 @@ add_delay_info(El, From, Time, Desc, Name, XMLNS) ->
|
|||||||
case xml:get_subtag_with_xmlns(El, Name, XMLNS) of
|
case xml:get_subtag_with_xmlns(El, Name, XMLNS) of
|
||||||
false ->
|
false ->
|
||||||
%% Add new tag
|
%% Add new tag
|
||||||
DelayTag = create_delay_tag(calendar:now_to_universal_time(Time),
|
DelayTag = create_delay_tag(Time, From, Desc, XMLNS),
|
||||||
From, Desc, XMLNS),
|
|
||||||
xml:append_subtags(El, [DelayTag]);
|
xml:append_subtags(El, [DelayTag]);
|
||||||
DelayTag ->
|
DelayTag ->
|
||||||
%% Update existing tag
|
%% Update existing tag
|
||||||
@ -648,16 +647,16 @@ add_delay_info(El, From, Time, Desc, Name, XMLNS) ->
|
|||||||
xml:append_subtags(NewEl, [NewDelayTag])
|
xml:append_subtags(NewEl, [NewDelayTag])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec create_delay_tag(calendar:datetime(), jid() | binary(),
|
-spec create_delay_tag(erlang:timestamp(), jid() | binary(), binary(),
|
||||||
binary(), binary()) -> xmlel() | error.
|
binary()) -> xmlel() | error.
|
||||||
|
|
||||||
create_delay_tag(DateTime, FromJID, Desc, XMLNS) when is_tuple(FromJID) ->
|
create_delay_tag(TimeStamp, FromJID, Desc, XMLNS) when is_tuple(FromJID) ->
|
||||||
From = jlib:jid_to_string(FromJID),
|
From = jlib:jid_to_string(FromJID),
|
||||||
{Name, Stamp} = case XMLNS of
|
{Name, Stamp} = case XMLNS of
|
||||||
?NS_DELAY ->
|
?NS_DELAY ->
|
||||||
{T, Tz} = timestamp_to_iso(DateTime, utc),
|
{<<"delay">>, now_to_utc_string(TimeStamp, 3)};
|
||||||
{<<"delay">>, <<T/binary, Tz/binary>>};
|
|
||||||
?NS_DELAY91 ->
|
?NS_DELAY91 ->
|
||||||
|
DateTime = calendar:now_to_universal_time(TimeStamp),
|
||||||
{<<"x">>, timestamp_to_iso(DateTime)}
|
{<<"x">>, timestamp_to_iso(DateTime)}
|
||||||
end,
|
end,
|
||||||
Children = case Desc of
|
Children = case Desc of
|
||||||
@ -710,13 +709,19 @@ timestamp_to_iso({{Year, Month, Day},
|
|||||||
-spec now_to_utc_string(erlang:timestamp()) -> binary().
|
-spec now_to_utc_string(erlang:timestamp()) -> binary().
|
||||||
|
|
||||||
now_to_utc_string({MegaSecs, Secs, MicroSecs}) ->
|
now_to_utc_string({MegaSecs, Secs, MicroSecs}) ->
|
||||||
|
now_to_utc_string({MegaSecs, Secs, MicroSecs}, 6).
|
||||||
|
|
||||||
|
-spec now_to_utc_string(erlang:timestamp(), 1..6) -> binary().
|
||||||
|
|
||||||
|
now_to_utc_string({MegaSecs, Secs, MicroSecs}, Precision) ->
|
||||||
{{Year, Month, Day}, {Hour, Minute, Second}} =
|
{{Year, Month, Day}, {Hour, Minute, Second}} =
|
||||||
calendar:now_to_universal_time({MegaSecs, Secs,
|
calendar:now_to_universal_time({MegaSecs, Secs,
|
||||||
MicroSecs}),
|
MicroSecs}),
|
||||||
list_to_binary(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w.~6."
|
FracOfSec = round(MicroSecs / math:pow(10, 6 - Precision)),
|
||||||
|
list_to_binary(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w.~*."
|
||||||
".0wZ",
|
".0wZ",
|
||||||
[Year, Month, Day, Hour, Minute, Second,
|
[Year, Month, Day, Hour, Minute, Second,
|
||||||
MicroSecs])).
|
Precision, FracOfSec])).
|
||||||
|
|
||||||
-spec now_to_local_string(erlang:timestamp()) -> binary().
|
-spec now_to_local_string(erlang:timestamp()) -> binary().
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user