Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when passing utc timestamps into httpd_util:rfc1123/1. #776

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/riak_repl_wm_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jsonify_stats([{K,V}|T], Acc) when is_list(V) ->
jsonify_stats([{K, {{Year, Month, Day}, {Hour, Min, Second}} = DateTime } | T], Acc) when is_integer(Year), is_integer(Month), is_integer(Day), is_integer(Hour), is_integer(Min), is_integer(Second) ->
% the guard clause may be insane, but I just want to be very sure it's a
% date time tuple that's being converted.
StrDate = httpd_util:rfc1123_date(DateTime),
StrDate = httpd_util:rfc1123_date(calendar:universal_time_to_local_time(DateTime)),
jsonify_stats(T, [{K, list_to_binary(StrDate)} | Acc]);
jsonify_stats([{K,V}|T], Acc) ->
jsonify_stats(T, [{K,V}|Acc]);
Expand All @@ -199,6 +199,16 @@ jsonify_stats([KV|T], Acc) ->

jsonify_stats_test_() ->
[
{"correctly handle utc datetimes in rfc1123",
fun() ->
%% this datetime doesn't exist in DST, without correct handling
%% causes rfc1123 to explode.
Actual = [{date, {{2017,3,26},{1,0,0}}}],
Expected = [{date, <<"Sun, 26 Mar 2017 01:00:00 GMT">>}],
?assertEqual(Expected, jsonify_stats(Actual, [])),
_Result = mochijson2:encode({struct, Expected})
end
},
%% test with bad stat to make sure
%% the catch-all works
{"catch-all",
Expand Down Expand Up @@ -251,7 +261,7 @@ jsonify_stats_test_() ->
{"Coord during fullsync",
fun() ->
Date = {{2013, 9, 19}, {20, 51, 7}},
BinDate = list_to_binary(httpd_util:rfc1123_date(Date)),
BinDate = list_to_binary(httpd_util:rfc1123_date(calendar:universal_time_to_local_time(Date))),
Input = [{fullsync_coordinator, [{"bar", [
{last_fullsync_started, Date}
]}]}],
Expand Down