mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Fix a binary warning in cowboy_clock.
Just a change in the order of arguments of update_rfc1123.
This commit is contained in:
parent
648921b8cf
commit
a93eb02646
1 changed files with 15 additions and 15 deletions
|
@ -64,7 +64,7 @@ init([]) ->
|
||||||
?TABLE = ets:new(?TABLE, [set, protected,
|
?TABLE = ets:new(?TABLE, [set, protected,
|
||||||
named_table, {read_concurrency, true}]),
|
named_table, {read_concurrency, true}]),
|
||||||
T = erlang:universaltime(),
|
T = erlang:universaltime(),
|
||||||
B = update_rfc1123(undefined, T, <<>>),
|
B = update_rfc1123(<<>>, undefined, T),
|
||||||
{ok, TRef} = timer:send_interval(1000, update),
|
{ok, TRef} = timer:send_interval(1000, update),
|
||||||
ets:insert(?TABLE, {rfc1123, B}),
|
ets:insert(?TABLE, {rfc1123, B}),
|
||||||
{ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
|
{ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
|
||||||
|
@ -81,7 +81,7 @@ handle_cast(_Msg, State) ->
|
||||||
|
|
||||||
handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
|
handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
|
||||||
T = erlang:universaltime(),
|
T = erlang:universaltime(),
|
||||||
B2 = update_rfc1123(Prev, T, B1),
|
B2 = update_rfc1123(B1, Prev, T),
|
||||||
ets:insert(?TABLE, {rfc1123, B2}),
|
ets:insert(?TABLE, {rfc1123, B2}),
|
||||||
{noreply, #state{universaltime=T, rfc1123=B2, tref=TRef}};
|
{noreply, #state{universaltime=T, rfc1123=B2, tref=TRef}};
|
||||||
|
|
||||||
|
@ -96,32 +96,32 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
||||||
%% Internal.
|
%% Internal.
|
||||||
|
|
||||||
-spec update_rfc1123(undefined | datetime(), datetime(), binary()) -> binary().
|
-spec update_rfc1123(binary(), undefined | datetime(), datetime()) -> binary().
|
||||||
update_rfc1123(Now, Now, Bin) ->
|
update_rfc1123(Bin, Now, Now) ->
|
||||||
Bin;
|
Bin;
|
||||||
update_rfc1123({Date, {H, M, _}}, {Date, {H, M, S}},
|
update_rfc1123(<< Keep:23/binary, _/bits >>,
|
||||||
<< Keep:23/binary, _/bits >>) ->
|
{Date, {H, M, _}}, {Date, {H, M, S}}) ->
|
||||||
<< Keep/binary, (pad_int(S))/binary, " GMT" >>;
|
<< Keep/binary, (pad_int(S))/binary, " GMT" >>;
|
||||||
update_rfc1123({Date, {H, _, _}}, {Date, {H, M, S}},
|
update_rfc1123(<< Keep:20/binary, _/bits >>,
|
||||||
<< Keep:20/binary, _/bits >>) ->
|
{Date, {H, _, _}}, {Date, {H, M, S}}) ->
|
||||||
<< Keep/binary, (pad_int(M))/binary, $:, (pad_int(S))/binary, " GMT" >>;
|
<< Keep/binary, (pad_int(M))/binary, $:, (pad_int(S))/binary, " GMT" >>;
|
||||||
update_rfc1123({Date, _}, {Date, {H, M, S}}, << Keep:17/binary, _/bits >>) ->
|
update_rfc1123(<< Keep:17/binary, _/bits >>, {Date, _}, {Date, {H, M, S}}) ->
|
||||||
<< Keep/binary, (pad_int(H))/binary, $:, (pad_int(M))/binary,
|
<< Keep/binary, (pad_int(H))/binary, $:, (pad_int(M))/binary,
|
||||||
$:, (pad_int(S))/binary, " GMT" >>;
|
$:, (pad_int(S))/binary, " GMT" >>;
|
||||||
update_rfc1123({{Y, Mo, _}, _}, {Date = {Y, Mo, D}, {H, M, S}},
|
update_rfc1123(<< _:7/binary, Keep:10/binary, _/bits >>,
|
||||||
<< _:7/binary, Keep:10/binary, _/bits >>) ->
|
{{Y, Mo, _}, _}, {Date = {Y, Mo, D}, {H, M, S}}) ->
|
||||||
Wday = calendar:day_of_the_week(Date),
|
Wday = calendar:day_of_the_week(Date),
|
||||||
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, Keep/binary,
|
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, Keep/binary,
|
||||||
(pad_int(H))/binary, $:, (pad_int(M))/binary,
|
(pad_int(H))/binary, $:, (pad_int(M))/binary,
|
||||||
$:, (pad_int(S))/binary, " GMT" >>;
|
$:, (pad_int(S))/binary, " GMT" >>;
|
||||||
update_rfc1123({{Y, _, _}, _}, {Date = {Y, Mo, D}, {H, M, S}},
|
update_rfc1123(<< _:11/binary, Keep:6/binary, _/bits >>,
|
||||||
<< _:11/binary, Keep:6/binary, _/bits >>) ->
|
{{Y, _, _}, _}, {Date = {Y, Mo, D}, {H, M, S}}) ->
|
||||||
Wday = calendar:day_of_the_week(Date),
|
Wday = calendar:day_of_the_week(Date),
|
||||||
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
|
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
|
||||||
(month(Mo))/binary, Keep/binary,
|
(month(Mo))/binary, Keep/binary,
|
||||||
(pad_int(H))/binary, $:, (pad_int(M))/binary,
|
(pad_int(H))/binary, $:, (pad_int(M))/binary,
|
||||||
$:, (pad_int(S))/binary, " GMT" >>;
|
$:, (pad_int(S))/binary, " GMT" >>;
|
||||||
update_rfc1123(_, {Date = {Y, Mo, D}, {H, M, S}}, _) ->
|
update_rfc1123(_, _, {Date = {Y, Mo, D}, {H, M, S}}) ->
|
||||||
Wday = calendar:day_of_the_week(Date),
|
Wday = calendar:day_of_the_week(Date),
|
||||||
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
|
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
|
||||||
(month(Mo))/binary, " ", (list_to_binary(integer_to_list(Y)))/binary,
|
(month(Mo))/binary, " ", (list_to_binary(integer_to_list(Y)))/binary,
|
||||||
|
@ -181,7 +181,7 @@ update_rfc1123_test_() ->
|
||||||
{<<"Sun, 01 Jan 2012 00:00:00 GMT">>, {{2011, 5, 31}, {23, 59, 59}},
|
{<<"Sun, 01 Jan 2012 00:00:00 GMT">>, {{2011, 5, 31}, {23, 59, 59}},
|
||||||
{{2012, 1, 1}, { 0, 0, 0}}, <<"Sat, 31 Dec 2011 23:59:59 GMT">>}
|
{{2012, 1, 1}, { 0, 0, 0}}, <<"Sat, 31 Dec 2011 23:59:59 GMT">>}
|
||||||
],
|
],
|
||||||
[{R, fun() -> R = update_rfc1123(P, N, B) end} || {R, P, N, B} <- Tests].
|
[{R, fun() -> R = update_rfc1123(B, P, N) end} || {R, P, N, B} <- Tests].
|
||||||
|
|
||||||
pad_int_test_() ->
|
pad_int_test_() ->
|
||||||
Tests = [
|
Tests = [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue