simplify the clock object.

This commit is contained in:
2018-04-17 23:01:39 +02:00
parent 9b7dad5be6
commit 0eafedabe8
2 changed files with 13 additions and 27 deletions

View File

@@ -47,17 +47,6 @@ Clock::~Clock(void)
{
}
/*! ----------------------------------------------------------------------------
* @fn set
*
* @brief Set a time (hour/minute) to the Clock.
*/
int Clock::set(void)
{
m_now = time(NULL);
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn is_equal_to_timer
@@ -69,17 +58,18 @@ bool Clock::is_equal_to_timer(const Timer &a_timer)
struct tm the_compared_time;
double the_diff;
the_compared_time = *localtime(&m_now);
time_t the_time = time(NULL);
printf ("=>Hour: %.2d h %.2d\n", the_compared_time.tm_hour, the_compared_time.tm_min);
the_compared_time = *localtime(&the_time);
printf ("=>Timer: (%.2d h %.2d) Now: (%.2d h %.2d)\n", a_timer.get_hour(),a_timer.get_minute(),
the_compared_time.tm_hour, the_compared_time.tm_min);
the_compared_time.tm_hour = a_timer.get_hour();
the_compared_time.tm_min = a_timer.get_minute();
the_diff = difftime(m_now, mktime(&the_compared_time));
printf ("=>Timer: %.2d h %.2d\n", a_timer.get_hour(),a_timer.get_minute());
printf ("%.f seconds of diff between current time and Timer time.\n", the_diff);
the_diff = difftime(the_time, mktime(&the_compared_time));
// printf ("%.f seconds of diff between current time and Timer time.\n", the_diff);
if (the_diff == 0)
return true;
@@ -98,14 +88,15 @@ bool Clock::is_expired(uint16_t a_duration)
struct tm the_compared_time;
double the_diff;
the_compared_time = *localtime(&m_now);
time_t the_time = time(NULL);
the_compared_time = *localtime(&the_time);
// the_compared_time.tm_hour = m_hour;
// the_compared_time.tm_min = m_minute;
the_expired = mktime(&the_compared_time) + (a_duration * 60);
the_diff = difftime(m_now, the_expired);
the_diff = difftime(the_time, the_expired);
//printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired);

View File

@@ -44,13 +44,8 @@ class Clock
Clock(void);
~Clock(void);
int set(void);
bool is_equal_to_timer(const Timer &a_timer);
bool is_expired(uint16_t a_duration);
private:
time_t m_now;
static bool is_equal_to_timer(const Timer &a_timer);
static bool is_expired(uint16_t a_duration);
};
#endif /* _CLOCK_H */