winix/templates/uptime.cpp

64 lines
890 B
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
*/
#include <ctime>
#include "templates.h"
namespace Winix
{
namespace TemplatesFunctions
{
void uptime_more_than_one_day(Info & i)
{
time_t up = time(0) - system->system_start;
time_t days = up / 60 / 60 / 24;
i.res = ( days > 1 );
}
void uptime_days(Info & i)
{
time_t up = time(0) - system->system_start;
time_t days = up / 60 / 60 / 24;
i.out << days;
}
void uptime_hours(Info & i)
{
char buf[50];
time_t sec = time(0) - system->system_start;
time_t min = sec / 60;
time_t hour = min / 60;
if( hour == 0 && min == 0 )
sprintf(buf, "%d:%02d:%02d", (int)hour, (int)(min%60), (int)(sec%60));
else
sprintf(buf, "%d:%02d", (int)hour, (int)(min%60));
i.out << buf;
}
} // namespace
} // namespace Winix