From cd437737fda7f47cbbb27fab4ec86d0e7c0ff57d Mon Sep 17 00:00:00 2001 From: Lastres Date: Fri, 22 Jun 2012 09:42:41 -0400 Subject: [PATCH] fixed error that causes possible duplicated hash numbers sometimes --- apps/wriaki/src/article.erl | 4 ++-- apps/wriaki/src/article_dtl_helper.erl | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/wriaki/src/article.erl b/apps/wriaki/src/article.erl index 4824185..6936d4e 100644 --- a/apps/wriaki/src/article.erl +++ b/apps/wriaki/src/article.erl @@ -141,8 +141,8 @@ get_timestamp(Article) -> wobj:get_json_field(Article, ?F_TS). update_version(Article) -> - {MS, S, _US} = now(), - TS = 1000000*MS+S, + {MS, S, US} = now(), + TS = 1000000000000*MS + 1000000*S + US, wobj:set_json_field( wobj:set_json_field(Article, ?F_TS, TS), ?F_VERSION, list_to_binary( diff --git a/apps/wriaki/src/article_dtl_helper.erl b/apps/wriaki/src/article_dtl_helper.erl index 5a6335a..fd4242d 100644 --- a/apps/wriaki/src/article_dtl_helper.erl +++ b/apps/wriaki/src/article_dtl_helper.erl @@ -114,9 +114,10 @@ history() -> %% @spec format_time(datetime()) -> iolist() %% @doc format a history timestamp for display in HTML -format_time(EpochSecs) -> - Secs = EpochSecs rem 1000000, - MegaSecs = (EpochSecs-Secs) div 1000000, +format_time(TS) -> + MicroSecs = TS rem 1000000, + Secs = ((TS-MicroSecs) div 1000000) rem 1000000, + MegaSecs = (TS-Secs*1000000-MicroSecs) div 1000000000000, {{Y,M,D},{H,I,S}} = calendar:now_to_universal_time({MegaSecs, Secs, 0}), io_lib:format("~4..0b.~2..0b.~2..0b ~2..0b:~2..0b:~2..0b", [Y,M,D,H,I,S]).