mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Let jlib use "B" instead of "w" to format integers
As a small optimization, use io:format's "B" control sequence to format integers. We don't need to let Erlang figure out the data type if we already know it.
This commit is contained in:
parent
0a19dac4fd
commit
466278fde1
16
src/jlib.erl
16
src/jlib.erl
@ -683,18 +683,18 @@ timestamp_to_iso({{Year, Month, Day},
|
||||
{Hour, Minute, Second}},
|
||||
Timezone) ->
|
||||
Timestamp_string =
|
||||
lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w",
|
||||
lists:flatten(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B",
|
||||
[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]);
|
||||
io_lib:format("~s~2..0B:~2..0B", [Sign, TZh, TZm]);
|
||||
{TZh, TZm} ->
|
||||
Sign = case TZh >= 0 of
|
||||
true -> "+";
|
||||
false -> "-"
|
||||
end,
|
||||
io_lib:format("~s~2..0w:~2..0w",
|
||||
io_lib:format("~s~2..0B:~2..0B",
|
||||
[Sign, abs(TZh), TZm])
|
||||
end,
|
||||
{iolist_to_binary(Timestamp_string), iolist_to_binary(Timezone_string)}.
|
||||
@ -703,7 +703,7 @@ timestamp_to_iso({{Year, Month, Day},
|
||||
|
||||
timestamp_to_iso({{Year, Month, Day},
|
||||
{Hour, Minute, Second}}) ->
|
||||
iolist_to_binary(io_lib:format("~4..0w~2..0w~2..0wT~2..0w:~2..0w:~2..0w",
|
||||
iolist_to_binary(io_lib:format("~4..0B~2..0B~2..0BT~2..0B:~2..0B:~2..0B",
|
||||
[Year, Month, Day, Hour, Minute, Second])).
|
||||
|
||||
-spec now_to_utc_string(erlang:timestamp()) -> binary().
|
||||
@ -718,8 +718,8 @@ now_to_utc_string({MegaSecs, Secs, MicroSecs}, Precision) ->
|
||||
calendar:now_to_universal_time({MegaSecs, Secs,
|
||||
MicroSecs}),
|
||||
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",
|
||||
list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~*."
|
||||
".0BZ",
|
||||
[Year, Month, Day, Hour, Minute, Second,
|
||||
Precision, FracOfSec])).
|
||||
|
||||
@ -739,8 +739,8 @@ now_to_local_string({MegaSecs, Secs, MicroSecs}) ->
|
||||
end,
|
||||
{{Year, Month, Day}, {Hour, Minute, Second}} =
|
||||
LocalTime,
|
||||
list_to_binary(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w.~6."
|
||||
".0w~s~2..0w:~2..0w",
|
||||
list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~6."
|
||||
".0B~s~2..0B:~2..0B",
|
||||
[Year, Month, Day, Hour, Minute, Second,
|
||||
MicroSecs, Sign, H, M])).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user