-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtimeHandler.cpp
More file actions
32 lines (29 loc) · 1000 Bytes
/
timeHandler.cpp
File metadata and controls
32 lines (29 loc) · 1000 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
#include "pch.h"
#include "timeHandler.h"
#include "messageHandler.h"
bool vsid::time::isActive(const std::string& timezone, const int start, const int end)
{
try
{
std::chrono::zoned_time zt{ timezone, std::chrono::system_clock::now() };
std::chrono::zoned_time ztStart = zt;
std::chrono::zoned_time ztEnd = zt;
auto day = std::chrono::floor<std::chrono::days>(zt.get_local_time());
ztStart = day + std::chrono::hours{ start };
ztEnd = day + std::chrono::hours{ end };
if ((ztEnd.get_local_time() < ztStart.get_local_time() &&
(zt.get_local_time() > ztStart.get_local_time() || zt.get_local_time() < ztEnd.get_local_time())) ||
(ztEnd.get_local_time() > ztStart.get_local_time() &&
zt.get_local_time() > ztStart.get_local_time() &&
zt.get_local_time() < ztEnd.get_local_time())
)
{
return true;
}
}
catch (std::runtime_error& e)
{
messageHandler->writeMessage("ERROR", "Timezone failed - " + std::string(e.what()) + ": " + timezone);
}
return false;
}