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/infowidget.cc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/client/infowidget.cc') 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