mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-04 10:43:19 +00:00
Refactor the whole structure, no more separation for C++ and Slint files
This commit is contained in:
parent
d6c781faa2
commit
893fcc11e3
35 changed files with 920 additions and 518 deletions
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "Utils.h"
|
||||
#include <cctype>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
std::string formatZeroPadding(const int number)
|
||||
{
|
||||
if (number < 10) {
|
||||
return "0" + std::to_string(number);
|
||||
}
|
||||
return std::to_string(number);
|
||||
}
|
||||
|
||||
std::string formatDateRelative(const ui::Date &date)
|
||||
{
|
||||
auto todayDate = mirai::Date(std::chrono::system_clock::now());
|
||||
auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(
|
||||
std::chrono::sys_days(SlintDateToMiraiDate(date).toStdChrono()) -
|
||||
std::chrono::sys_days(todayDate.toStdChrono())
|
||||
)
|
||||
.count();
|
||||
|
||||
if (relativeDaysDiff == 0) {
|
||||
return std::string("today");
|
||||
} else if (relativeDaysDiff == 1) {
|
||||
return std::string("tomorrow");
|
||||
}
|
||||
return std::format("in {} days", relativeDaysDiff);
|
||||
};
|
||||
|
||||
std::string capitalize(std::string str)
|
||||
{
|
||||
str[0] = static_cast<char>(toupper(str[0]));
|
||||
return str;
|
||||
};
|
||||
|
||||
std::string SlintDateToStdString(const ui::Date &date)
|
||||
{
|
||||
return std::to_string(date.year) + "-" + formatZeroPadding(date.month) + "-" +
|
||||
formatZeroPadding(date.day);
|
||||
}
|
||||
|
||||
mirai::Date SlintDateToMiraiDate(const ui::Date &date)
|
||||
{
|
||||
return mirai::Date(
|
||||
date.year, static_cast<unsigned>(date.month), static_cast<unsigned>(date.day)
|
||||
);
|
||||
}
|
||||
|
||||
ui::Date MiraiDateToSlintDate(const mirai::Date &date)
|
||||
{
|
||||
return {
|
||||
.year = date.year,
|
||||
.month = static_cast<int>(date.month),
|
||||
.day = static_cast<int>(date.day),
|
||||
};
|
||||
}
|
||||
|
||||
ui::Time MiraiTimeToSlintTime(const mirai::Time &time)
|
||||
{
|
||||
return {.hour = time.hour, .minute = time.minute, .second = 0};
|
||||
}
|
||||
|
||||
mirai::Time SlintTimeToMiraiTime(const ui::Time &time)
|
||||
{
|
||||
return {.hour = time.hour, .minute = time.minute};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue