diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2011-05-21 12:29:38 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2011-05-21 12:29:38 +0000 |
commit | 86c8ffc732052ba5eb942330ad431d1a42297034 (patch) | |
tree | e90f73a4f147e442caa03351ac880a445d76fb5f /src/couchdb | |
parent | 5b8d4522255662ce2b8637680ed1a3db24c2bcef (diff) |
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.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1125682 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_rep.erl | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl index e4b4264e..49a82e5d 100644 --- a/src/couchdb/couch_rep.erl +++ b/src/couchdb/couch_rep.erl @@ -889,11 +889,9 @@ update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) -> 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 = {RepDocBody}} = RepDoc, KVs) -> [] ). +% 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">> -> |