[erlang-questions] Time zone
Scott Lystig Fritchie
fritchie@REDACTED
Thu Dec 14 00:19:41 CET 2006
>>>>> "cm" == Chandru <chandrashekhar.mullaparthi@REDACTED> writes:
cm> Basically offset from GMT was what I was after. I'm writing a web
cm> server and I had to print out access logs in the Common Log
cm> Format.
Hrm. I don't know how well this would work on a Windows box, but this
off-the-top-of-my-head-may-not-compile-cleanly code could be the Hack
Behind Door #2? Using a real "port" would avoid repeated fork() and
exec() overhead. Incorrectness, for some fraction of a second, may or
may not bother your app.
Come to think of it, if both fork+exec overhead and the Yaws version's
repeated arithmetic overhead are too high ... the current_offset()
func below could use the Yaws method instead of os:cmd/1. I haven't
measured how frequently the Yaws version needs to be called in order
to break even. :-)
Though, if you're seriously trying to optimize your Yaws app, timezone
calculations are probably very low on the list of inefficiencies to
attack first....
-Scott
--- snip --- snip --- snip --- snip --- snip --- snip --- snip ---
start_offset_server() ->
spawn_link(fun() -> offset_server() end);
get_offset()
offset_server ! {self(), current_offset},
receive
{offset_server, Offset} -> Offset
end.
offset_server() ->
register(offset_server, self()),
{ok, _} = timer:send_interval(1000, check_offset),
offset_server(current_offset()).
offset_server(Offset) ->
receive
check_offset ->
offset_server(current_offset());
{Pid, current_offset} ->
Pid ! {offset_server, Offset},
offset_server(Offset)
end.
current_offset() ->
os:cmd("date +%z"). % Removal of trailing \n exercise for reader
More information about the erlang-questions
mailing list