|
|
@@ -0,0 +1,145 @@
|
|
|
+#include "Trigger.h"
|
|
|
+#include <date.h>
|
|
|
+#include <DateTime.h>
|
|
|
+
|
|
|
+
|
|
|
+namespace Timer {
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Second()
|
|
|
+{
|
|
|
+ return Second(std::chrono::system_clock::now());
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Minute()
|
|
|
+{
|
|
|
+ return Minute(std::chrono::system_clock::now());
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Hour()
|
|
|
+{
|
|
|
+ return Hour(std::chrono::system_clock::now());
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Day()
|
|
|
+{
|
|
|
+ return Day(std::chrono::system_clock::now());
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Seconds(int seconds)
|
|
|
+{
|
|
|
+ return Seconds(std::chrono::system_clock::now(), seconds);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Minutes(int minutes)
|
|
|
+{
|
|
|
+ return Minutes(std::chrono::system_clock::now(), minutes);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Hours(int hours)
|
|
|
+{
|
|
|
+ return Hours(std::chrono::system_clock::now(), hours);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::SecondsMultitude(int seconds)
|
|
|
+{
|
|
|
+ return SecondsMultitude(std::chrono::system_clock::now(), seconds);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::MinutesMultitude(int minutes)
|
|
|
+{
|
|
|
+ return MinutesMultitude(std::chrono::system_clock::now(), minutes);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::HoursMultitude(int hours)
|
|
|
+{
|
|
|
+ return HoursMultitude(std::chrono::system_clock::now(), hours);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Second(std::chrono::time_point<std::chrono::system_clock> base)
|
|
|
+{
|
|
|
+ return Seconds(base, 1);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Minute(std::chrono::time_point<std::chrono::system_clock> base)
|
|
|
+{
|
|
|
+ return Minutes(base, 1);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Hour(std::chrono::time_point<std::chrono::system_clock> base)
|
|
|
+{
|
|
|
+ return Hours(base, 1);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Day(std::chrono::time_point<std::chrono::system_clock> base)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point tomorrow = base + std::chrono::hours(24) + std::chrono::seconds(DateTime::GetUTCOffset());
|
|
|
+ auto daypoint = date::floor<date::days>(tomorrow); // This call works on UTC
|
|
|
+ auto yearMonthDay = date::year_month_day(daypoint);
|
|
|
+
|
|
|
+ DateTime::DateTime dateTime{
|
|
|
+ static_cast<int>(yearMonthDay.year()),
|
|
|
+ static_cast<unsigned>(yearMonthDay.month()),
|
|
|
+ static_cast<unsigned>(yearMonthDay.day())
|
|
|
+ };
|
|
|
+
|
|
|
+ return DateTime::DateTime_to_time_point(dateTime, date::current_zone());
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Seconds(std::chrono::time_point<std::chrono::system_clock> base, int seconds)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point now = base + std::chrono::seconds(1);
|
|
|
+ auto time = date::make_time(now.time_since_epoch());
|
|
|
+ asio::system_timer::duration targetTime = time.hours() + time.minutes() + time.seconds() + std::chrono::seconds(seconds);
|
|
|
+ return asio::system_timer::time_point(targetTime);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Minutes(std::chrono::time_point<std::chrono::system_clock> base, int minutes)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point now = base + std::chrono::seconds(1);
|
|
|
+ auto time = date::make_time(now.time_since_epoch());
|
|
|
+ asio::system_timer::duration targetTime = time.hours() + time.minutes() + std::chrono::minutes(minutes);
|
|
|
+ return asio::system_timer::time_point(targetTime);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::Hours(std::chrono::time_point<std::chrono::system_clock> base, int hours)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point now = base + std::chrono::seconds(1);
|
|
|
+ auto time = date::make_time(now.time_since_epoch());
|
|
|
+ asio::system_timer::duration targetTime = time.hours() + time.minutes() + std::chrono::hours(hours);
|
|
|
+ return asio::system_timer::time_point(targetTime);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::SecondsMultitude(std::chrono::time_point<std::chrono::system_clock> base, int seconds)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point now = base + std::chrono::seconds(1);
|
|
|
+ auto time = date::make_time(now.time_since_epoch());
|
|
|
+
|
|
|
+ auto baseSeconds = time.seconds() - std::chrono::seconds(time.seconds().count() % seconds);
|
|
|
+
|
|
|
+ asio::system_timer::duration targetTime = time.hours() + time.minutes() + baseSeconds + std::chrono::seconds(seconds);
|
|
|
+ return asio::system_timer::time_point(targetTime);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::MinutesMultitude(std::chrono::time_point<std::chrono::system_clock> base, int minutes)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point now = base + std::chrono::seconds(1);
|
|
|
+ auto time = date::make_time(now.time_since_epoch());
|
|
|
+
|
|
|
+ auto baseMinutes = time.minutes() - std::chrono::minutes(time.minutes().count() % minutes);
|
|
|
+
|
|
|
+ asio::system_timer::duration targetTime = time.hours() + baseMinutes + std::chrono::minutes(minutes);
|
|
|
+ return asio::system_timer::time_point(targetTime);
|
|
|
+}
|
|
|
+
|
|
|
+asio::system_timer::time_point Trigger::HoursMultitude(std::chrono::time_point<std::chrono::system_clock> base, int hours)
|
|
|
+{
|
|
|
+ asio::system_timer::time_point now = base + std::chrono::seconds(1);
|
|
|
+ auto time = date::make_time(now.time_since_epoch());
|
|
|
+
|
|
|
+ auto baseHours = time.hours() - std::chrono::hours(time.hours().count() % hours);
|
|
|
+
|
|
|
+ asio::system_timer::duration targetTime = baseHours + std::chrono::hours(hours);
|
|
|
+ return asio::system_timer::time_point(targetTime);
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace Timer
|