-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.cpp
More file actions
35 lines (30 loc) · 714 Bytes
/
time.cpp
File metadata and controls
35 lines (30 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "time.h"
#include <ctime>
#include <iostream>
Time::Time()
{
time_t currentTime = time(nullptr);
// Èñïîëüçóåì ôóíêöèè ñòàíäàðòíîé áèáëèîòåêè äëÿ
// äåêîäèðîâàíèÿ êîìïîíåíòîâ âðåìåíè ê óäîáíîìó âèäó
tm* currentTM = gmtime(¤tTime);
m_hour = currentTM->tm_hour;
m_minutes = currentTM->tm_min;
if (!isValide())
throw std::logic_error("Error: time is not correct.");
}
Time::Time(const int _hour, const int _minutes)
:m_hour(_hour),
m_minutes(_minutes)
{
if (!isValide())
throw std::logic_error("Error: time is not correct.");
}
bool Time::isValide() const
{
if (m_hour > 23 ||
m_hour < 0)
return false;
if (m_minutes > 59 || m_minutes < 0)
return false;
else return true;
}