/* * Mirai. Copyright (C) 2024 Vyn * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt */ #pragma once #include #include #include #include #include namespace mirai { struct Date { explicit Date(int year, unsigned month, unsigned day) : year(year), month(month), day(day) { } explicit Date(std::chrono::time_point tp) { auto chronoDate = std::chrono::year_month_day(std::chrono::floor(tp)); year = static_cast(chronoDate.year()); month = static_cast(chronoDate.month()); day = static_cast(chronoDate.day()); } explicit Date(std::chrono::year_month_day chronoDate) { year = static_cast(chronoDate.year()); month = static_cast(chronoDate.month()); day = static_cast(chronoDate.day()); } int year; unsigned month; unsigned day; bool operator==(const Date &other) const { return other.year == year && other.month == month && other.day == day; } bool operator<(const Date &other) const { if (year < other.year) { return true; } if (year == other.year && month < other.month) { return true; } if (year == other.year && month == other.month && day < other.day) { return true; } return false; } bool operator>(const Date &other) const { return !(*this < other) && !(*this == other); } }; struct Time { int hour; int minute; bool operator==(const Time &other) const { return other.hour == hour && other.minute == minute; } bool operator<(const Time &other) const { if (hour < other.hour) { return true; } if (hour == other.hour && minute < other.minute) { return true; } return false; } bool operator>(const Time &other) const { return !(*this < other) && !(*this == other); } }; std::optional stringToDate(const std::string &dateStr); } // namespace mirai