Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:klacke/yaws
Browse files Browse the repository at this point in the history
  • Loading branch information
vinoski committed Sep 28, 2009
2 parents 887a15a + c966d77 commit 6adf0e1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/yaws_log.erl
Expand Up @@ -476,10 +476,11 @@ fmt_ip(HostName) ->


fmtnow() ->
{{Year, Month, Date}, {Hour, Min, Sec}} =
{{Year, Month, Day}, {Hour, Min, Sec}} =
calendar:now_to_local_time(now()),
io_lib:format("[~2..0w/~s/~4..0w:~2..0w:~2..0w:~2..0w ~s]",
[Date,yaws:month(Month),Year, Hour, Min, Sec, zone()]).
[fill_zero(Day,2),"/",yaws:month(Month),"/",integer_to_list(Year),":",
fill_zero(Hour,2),":",fill_zero(Min,2),":",fill_zero(Sec,2)," ",zone()].


zone() ->
Time = erlang:universaltime(),
Expand All @@ -488,10 +489,19 @@ zone() ->
calendar:datetime_to_gregorian_seconds(Time),
zone(DiffSecs div 3600, (DiffSecs rem 3600) div 60).

%% Ugly reformatting code to get times like +0000 and -1300


zone(Hr, Min) when Hr < 0; Min < 0 ->
io_lib:format("-~2..0w~2..0w", [abs(Hr), abs(Min)]);
[$-, fill_zero(abs(Hr), 2), fill_zero(abs(Min), 2)];
zone(Hr, Min) when Hr >= 0, Min >= 0 ->
io_lib:format("+~2..0w~2..0w", [Hr, Min]).
[$+, fill_zero(abs(Hr), 2), fill_zero(abs(Min), 2)].

fill_zero(N, Width) ->
left_fill(N, Width, $0).

left_fill(N, Width, Fill) when is_integer(N) ->
left_fill(integer_to_list(N), Width, Fill);
left_fill(N, Width, _Fill) when length(N) >= Width ->
N;
left_fill(N, Width, Fill) ->
left_fill([Fill|N], Width, Fill).

0 comments on commit 6adf0e1

Please sign in to comment.