couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1125682 - in /couchdb/branches/1.1.x: share/www/script/test/replicator_db.js src/couchdb/couch_rep.erl
Date Sat, 21 May 2011 12:29:38 GMT
Author: fdmanana
Date: Sat May 21 12:29:38 2011
New Revision: 1125682

URL: http://svn.apache.org/viewvc?rev=1125682&view=rev
Log:
Merged revision 1125680 from trunk

    Use RFC3339 timestamps in replication documents

    As recently proposed by Max Odgen, RFC3339 timestamps are
    now used instead of Unix timestamps.


Modified:
    couchdb/branches/1.1.x/share/www/script/test/replicator_db.js
    couchdb/branches/1.1.x/src/couchdb/couch_rep.erl

Modified: couchdb/branches/1.1.x/share/www/script/test/replicator_db.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/replicator_db.js?rev=1125682&r1=1125681&r2=1125682&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/replicator_db.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/replicator_db.js Sat May 21 12:29:38 2011
@@ -121,7 +121,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.source === repDoc.source);
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "completed", "simple");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
   }
 
@@ -173,7 +173,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.source === repDoc.source);
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "completed", "filtered");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
   }
 
@@ -217,7 +217,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.source === repDoc.source);
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "triggered");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
 
     // add a design doc to source, it will be replicated to target
@@ -332,7 +332,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1_copy.source === repDoc1.source);
     T(repDoc1_copy.target === repDoc1.target);
     T(repDoc1_copy._replication_state === "completed");
-    T(typeof repDoc1_copy._replication_state_time === "number");
+    T(typeof repDoc1_copy._replication_state_time === "string");
     T(typeof repDoc1_copy._replication_id  === "string");
 
     var newDoc = {
@@ -363,7 +363,7 @@ couchTests.replicator_db = function(debu
     T(repDoc2_copy.source === repDoc1.source);
     T(repDoc2_copy.target === repDoc1.target);
     T(repDoc2_copy._replication_state === "completed");
-    T(typeof repDoc2_copy._replication_state_time === "number");
+    T(typeof repDoc2_copy._replication_state_time === "string");
     T(typeof repDoc2_copy._replication_id === "string");
     T(repDoc2_copy._replication_id === repDoc1_copy._replication_id);
   }
@@ -400,7 +400,7 @@ couchTests.replicator_db = function(debu
     repDoc1 = repDb.open("foo_dup_rep_doc_1");
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "completed", "identical");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
 
     repDoc2 = repDb.open("foo_dup_rep_doc_2");
@@ -444,7 +444,7 @@ couchTests.replicator_db = function(debu
     repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "triggered");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
 
     repDoc2 = repDb.open("foo_dup_cont_rep_doc_2");
@@ -470,7 +470,7 @@ couchTests.replicator_db = function(debu
     repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "triggered");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
 
     var newDoc2 = {
         _id: "foo5000",
@@ -739,7 +739,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "completed",
       "replication document with bad replication id failed");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
     T(repDoc1._replication_id !== "1234abc");
   }
@@ -930,7 +930,7 @@ couchTests.replicator_db = function(debu
     var repDoc1 = repDb.open(repDoc._id);
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "error");
-    T(typeof repDoc1._replication_state_time === "number");
+    T(typeof repDoc1._replication_state_time === "string");
     T(typeof repDoc1._replication_id  === "string");
   }
 

Modified: couchdb/branches/1.1.x/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_rep.erl?rev=1125682&r1=1125681&r2=1125682&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_rep.erl Sat May 21 12:29:38 2011
@@ -889,11 +889,9 @@ update_rep_doc(RepDb, #doc{body = {RepDo
                     Body;
                 _ ->
                     Body1 = lists:keystore(K, 1, Body, KV),
-                    {Mega, Secs, _} = erlang:now(),
-                    UnixTime = Mega * 1000000 + Secs,
                     lists:keystore(
                         <<"_replication_state_time">>, 1,
-                        Body1, {<<"_replication_state_time">>, UnixTime})
+                        Body1, {<<"_replication_state_time">>, timestamp()})
                 end;
             ({K, _V} = KV, Body) ->
                 lists:keystore(K, 1, Body, KV)
@@ -909,6 +907,26 @@ update_rep_doc(RepDb, #doc{body = {RepDo
         []
     ).
 
+% RFC3339 timestamps.
+% Note: doesn't include the time seconds fraction (RFC3339 says it's optional).
+timestamp() ->
+    {{Year, Month, Day}, {Hour, Min, Sec}} = calendar:now_to_local_time(now()),
+    UTime = erlang:universaltime(),
+    LocalTime = calendar:universal_time_to_local_time(UTime),
+    DiffSecs = calendar:datetime_to_gregorian_seconds(LocalTime) -
+        calendar:datetime_to_gregorian_seconds(UTime),
+    zone(DiffSecs div 3600, (DiffSecs rem 3600) div 60),
+    iolist_to_binary(
+        io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w~s",
+            [Year, Month, Day, Hour, Min, Sec,
+                zone(DiffSecs div 3600, (DiffSecs rem 3600) div 60)])).
+
+zone(Hr, Min) when Hr >= 0, Min >= 0 ->
+    io_lib:format("+~2..0w:~2..0w", [Hr, Min]);
+zone(Hr, Min) ->
+    io_lib:format("-~2..0w:~2..0w", [abs(Hr), abs(Min)]).
+
+
 maybe_set_triggered({RepProps} = RepDoc, RepId) ->
     case couch_util:get_value(<<"_replication_state">>, RepProps) of
     <<"triggered">> ->



Mime
View raw message