mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-04 10:43:19 +00:00
Move all UI code into new 'ui' directory
This commit is contained in:
parent
00d9cbe7ef
commit
0046cb9bbb
21 changed files with 94 additions and 93 deletions
|
@ -1,92 +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 <chrono>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
void bindSlintUtils(const ui::Utils &utils)
|
||||
{
|
||||
utils.on_format_date([&](const ui::Date &date) {
|
||||
std::chrono::year_month_day chronoDate{
|
||||
std::chrono::year(date.year),
|
||||
std::chrono::month(date.month),
|
||||
std::chrono::day(date.day),
|
||||
};
|
||||
return std::format("{:%B %d}", chronoDate);
|
||||
});
|
||||
|
||||
auto currentDate = MiraiDateToSlintDate(mirai::date(std::chrono::system_clock::now()));
|
||||
utils.set_current_date(currentDate);
|
||||
|
||||
auto currentTime = MiraiTimeToSlintTime(mirai::time(std::chrono::system_clock::now()));
|
||||
utils.set_current_time(currentTime);
|
||||
}
|
||||
|
||||
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).to_std_chrono())
|
||||
- std::chrono::sys_days(todayDate.to_std_chrono())
|
||||
)
|
||||
.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 mirai::time{time.hour, time.minute};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue