|
@@ -64,7 +64,7 @@ init([]) ->
|
|
|
?TABLE = ets:new(?TABLE, [set, protected,
|
|
|
named_table, {read_concurrency, true}]),
|
|
|
T = erlang:universaltime(),
|
|
|
- B = update_rfc1123(undefined, T, <<>>),
|
|
|
+ B = update_rfc1123(<<>>, undefined, T),
|
|
|
{ok, TRef} = timer:send_interval(1000, update),
|
|
|
ets:insert(?TABLE, {rfc1123, B}),
|
|
|
{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}) ->
|
|
|
T = erlang:universaltime(),
|
|
|
- B2 = update_rfc1123(Prev, T, B1),
|
|
|
+ B2 = update_rfc1123(B1, Prev, T),
|
|
|
ets:insert(?TABLE, {rfc1123, B2}),
|
|
|
{noreply, #state{universaltime=T, rfc1123=B2, tref=TRef}};
|
|
|
|
|
@@ -96,32 +96,32 @@ code_change(_OldVsn, State, _Extra) ->
|
|
|
|
|
|
%% Internal.
|
|
|
|
|
|
--spec update_rfc1123(undefined | datetime(), datetime(), binary()) -> binary().
|
|
|
-update_rfc1123(Now, Now, Bin) ->
|
|
|
+-spec update_rfc1123(binary(), undefined | datetime(), datetime()) -> binary().
|
|
|
+update_rfc1123(Bin, Now, Now) ->
|
|
|
Bin;
|
|
|
-update_rfc1123({Date, {H, M, _}}, {Date, {H, M, S}},
|
|
|
- << Keep:23/binary, _/bits >>) ->
|
|
|
+update_rfc1123(<< Keep:23/binary, _/bits >>,
|
|
|
+ {Date, {H, M, _}}, {Date, {H, M, S}}) ->
|
|
|
<< Keep/binary, (pad_int(S))/binary, " GMT" >>;
|
|
|
-update_rfc1123({Date, {H, _, _}}, {Date, {H, M, S}},
|
|
|
- << Keep:20/binary, _/bits >>) ->
|
|
|
+update_rfc1123(<< Keep:20/binary, _/bits >>,
|
|
|
+ {Date, {H, _, _}}, {Date, {H, M, S}}) ->
|
|
|
<< 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,
|
|
|
$:, (pad_int(S))/binary, " GMT" >>;
|
|
|
-update_rfc1123({{Y, Mo, _}, _}, {Date = {Y, Mo, D}, {H, M, S}},
|
|
|
- << _:7/binary, Keep:10/binary, _/bits >>) ->
|
|
|
+update_rfc1123(<< _:7/binary, Keep:10/binary, _/bits >>,
|
|
|
+ {{Y, Mo, _}, _}, {Date = {Y, Mo, D}, {H, M, S}}) ->
|
|
|
Wday = calendar:day_of_the_week(Date),
|
|
|
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, Keep/binary,
|
|
|
(pad_int(H))/binary, $:, (pad_int(M))/binary,
|
|
|
$:, (pad_int(S))/binary, " GMT" >>;
|
|
|
-update_rfc1123({{Y, _, _}, _}, {Date = {Y, Mo, D}, {H, M, S}},
|
|
|
- << _:11/binary, Keep:6/binary, _/bits >>) ->
|
|
|
+update_rfc1123(<< _:11/binary, Keep:6/binary, _/bits >>,
|
|
|
+ {{Y, _, _}, _}, {Date = {Y, Mo, D}, {H, M, S}}) ->
|
|
|
Wday = calendar:day_of_the_week(Date),
|
|
|
<< (weekday(Wday))/binary, ", ", (pad_int(D))/binary, " ",
|
|
|
(month(Mo))/binary, Keep/binary,
|
|
|
(pad_int(H))/binary, $:, (pad_int(M))/binary,
|
|
|
$:, (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),
|
|
|
<< (weekday(Wday))/binary, ", ", (pad_int(D))/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}},
|
|
|
{{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_() ->
|
|
|
Tests = [
|