Commits

Anonymous committed dd4db29

store X-Riak-Last-Modified as datetime tuple, not rfc1123 date string

Comments (0)

Files changed (4)

src/jiak_object.erl

                        Links),
     {struct, [{<<"vclock">>,vclock_to_headers(riak_object:vclock(RiakObject))},
               {<<"lastmod">>,
-               list_to_binary(dict:fetch(<<"X-Riak-Last-Modified">>, MD))},
+               list_to_binary(
+                 case dict:fetch(<<"X-Riak-Last-Modified">>, MD) of
+                     Datetime={_,_} ->
+                         httpd_util:rfc1123_date(
+                           calendar:universal_time_to_local_time(Datetime));
+                     Rfc1123 when is_list(Rfc1123) ->
+                         Rfc1123
+                 end)},
               {<<"vtag">>,
                list_to_binary(dict:fetch(<<"X-Riak-VTag">>, MD))}
               |J0]}.

src/raw_http_resource.erl

      end,
      LHead,": ",Links,"\n",
      "Etag: ",dict:fetch(?MD_VTAG, MD),"\n",
-     "Last-Modified: ",dict:fetch(?MD_LASTMOD, MD),"\n",
+     "Last-Modified: ",
+     case dict:fetch(?MD_LASTMOD, MD) of
+         Datetime={_,_} ->
+             httpd_util:rfc1123_date(
+               calendar:universal_time_to_local_time(Datetime));
+         Rfc1123 when is_list(Rfc1123) ->
+             Rfc1123
+     end,
+     "\n",
      "\n",V].
     
 
 last_modified(RD, Ctx) ->
     case select_doc(Ctx) of
         {MD, _} ->
-            {httpd_util:convert_request_date(
-               dict:fetch(?MD_LASTMOD, MD)), RD, Ctx};
+            {case dict:fetch(?MD_LASTMOD, MD) of
+                 Datetime={_,_} ->
+                     Datetime;
+                 Rfc1123 when is_list(Rfc1123) ->
+                     httpd_util:convert_request_date(Rfc1123)
+             end,
+             RD, Ctx};
         multiple_choices ->
             {undefined, RD, Ctx}
     end.

src/riak_put_fsm.erl

         false -> dict:store(<<"X-Riak-VTag">>,
                        make_vtag(RObj),
                        dict:store(<<"X-Riak-Last-Modified">>,
-                                  httpd_util:rfc1123_date(),
+                                  calendar:universal_time(),
                                   MD0))
     end,
     riak_object:apply_updates(riak_object:update_metadata(RObj, NewMD)).

src/riak_util.erl

 %%      the gregorian calendar.
 moment() -> calendar:datetime_to_gregorian_seconds(calendar:universal_time()).
 
-%% @spec compare_dates(string(), string()) -> boolean()
-%% @doc Compare two RFC1123 date strings.  Return true if date A
-%%      is later than date B.
-compare_dates(A, B) ->
-    % true if A is later than B, where
-    % A and B are rfc1123 dates.
-    A1 = calendar:datetime_to_gregorian_seconds(
-	   httpd_util:convert_request_date(A)),
-    B1 = calendar:datetime_to_gregorian_seconds(
-	   httpd_util:convert_request_date(B)),
-    A1 > B1.
+%% @spec compare_dates(string()|datetime(), string()|datetime()) -> boolean()
+%% @doc Compare two RFC1123 date strings or two datetime tuples (or
+%%      one of each).  Return true if date A is later than date B.
+compare_dates(A={_,_}, B={_,_}) ->
+    %% assume 2-tuples are datetimes
+    A > B;
+compare_dates(A, B) when is_list(A) ->
+    %% assume lists are rfc1123 date strings
+    compare_dates(httpd_util:convert_request_date(A), B);
+compare_dates(A, B) when is_list(B) ->
+    compare_dates(A, httpd_util:convert_request_date(B)).
 
 %% @spec make_tmp_dir() -> string()
 %% @doc Create a unique directory in /tmp.  Returns the path
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.