summaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-12-25 02:37:31 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-12-25 02:37:31 -0500
commit41d80af128cc74e538a2f5d2474ca49febc52c35 (patch)
tree5b5be602db4c84874998fbadffe2e19011c3fc13 /src/util.cpp
parent145504bdd66e93fe13426fc943e903e4d0db08d1 (diff)
downloadabaddon-portaudio-41d80af128cc74e538a2f5d2474ca49febc52c35.tar.gz
abaddon-portaudio-41d80af128cc74e538a2f5d2474ca49febc52c35.zip
mark more channels as unread properly
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 34ca6d4..6796a3f 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1,4 +1,5 @@
#include "util.hpp"
+#include <array>
#include <filesystem>
Semaphore::Semaphore(int count)
@@ -215,3 +216,31 @@ bool util::IsFile(std::string_view path) {
if (ec) return false;
return status.type() == std::filesystem::file_type::regular;
}
+
+constexpr bool IsLeapYear(int year) {
+ if (year % 4 != 0) return false;
+ if (year % 100 != 0) return true;
+ return (year % 400) == 0;
+}
+
+constexpr static int SecsPerMinute = 60;
+constexpr static int SecsPerHour = 3600;
+constexpr static int SecsPerDay = 86400;
+constexpr static std::array<int, 12> DaysOfMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+// may god smite whoever is responsible for the absolutely abominable api that is C time functions
+// i shouldnt have to write this. mktime ALMOST works but it adds the current timezone offset. WHY???
+uint64_t util::TimeToEpoch(int year, int month, int day, int hour, int minute, int seconds) {
+ uint64_t secs = 0;
+ for (int y = 1970; y < year; ++y)
+ secs += (IsLeapYear(y) ? 366 : 365) * SecsPerDay;
+ for (int m = 1; m < month; ++m) {
+ secs += DaysOfMonth[m - 1] * SecsPerDay;
+ if (m == 2 && IsLeapYear(year)) secs += SecsPerDay;
+ }
+ secs += (day - 1) * SecsPerDay;
+ secs += hour * SecsPerHour;
+ secs += minute * SecsPerMinute;
+ secs += seconds;
+ return secs;
+}