From bb0f860989f84b901f80017ae0139a3fc0446dc1 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 9 May 2011 20:22:34 +0000 Subject: Refactored the sys::localtime routines. --- src/client/client.cc | 4 ++-- src/client/infowidget.cc | 30 ++++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/client') diff --git a/src/client/client.cc b/src/client/client.cc index 5b72146..d761e6e 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -196,13 +196,13 @@ void Client::run() } if (cl_framerate->value()) { - client_frame_lenght = (Uint32) roundf(1000.0f / cl_framerate->value()); + client_frame_lenght = (Uint32) floorf(1000.0f / cl_framerate->value()); } else { client_frame_lenght = 0; } // only advance per microsecond frame - Uint32 d = client_current_timestamp - client_previous_timestamp; + const Uint32 d = client_current_timestamp - client_previous_timestamp; if ((d > 0)) { if (d >= client_frame_lenght) { frame(client_current_timestamp); diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc index ed118a8..52af5ef 100644 --- a/src/client/infowidget.cc +++ b/src/client/infowidget.cc @@ -199,22 +199,24 @@ void ClockInfoWidget::draw() { if (mode() == ClockOff) return; + + int hours, minutes, seconds; + sys::get_localtime(hours, minutes, seconds); - std::ostringstream clockstr; - const unsigned long current_time = sys::time(); - unsigned long hours = current_time / 3600; - unsigned long minutes = (current_time % 3600) / 60; - //unsigned long seconds = current_time % 60; - + std::ostringstream clockstr; clockstr << std::setfill('0') << std::setw(2); - if (mode() == Clock12Hours) { - if (hours > 12) { - clockstr << hours-12 << ":" << std::setfill('0') << std::setw(2) << minutes << "pm"; - } else { - if (hours == 0) - hours +=12; - clockstr << hours << ":" << std::setfill('0') << std::setw(2) << minutes << "am"; - } + + if (mode() == Clock12Hours) { + std::string suffix("am"); + + if (hours >= 12) { + suffix[1] = 'p'; + hours -= 12; + } + if (hours == 0) { + hours += 12; + } + clockstr << hours << ":" << std::setfill('0') << std::setw(2) << minutes << suffix; } else { clockstr << " " << hours << ":" << std::setfill('0') << std::setw(2) << minutes; } -- cgit v1.2.3