Add hint to show how many days left relative to today

This commit is contained in:
Vyn 2024-10-08 17:05:52 +02:00
parent 53b1280115
commit 534da46a26
4 changed files with 33 additions and 13 deletions

View file

@ -25,6 +25,15 @@ struct Date {
bool operator<(const Date &other) const;
bool operator>(const Date &other) const;
std::chrono::year_month_day toStdChrono() const
{
return std::chrono::year_month_day{
std::chrono::year(year),
std::chrono::month(month),
std::chrono::day(day),
};
}
int year;
unsigned month;
unsigned day;

View file

@ -223,7 +223,7 @@ void UiState::setupUtilsCallbacks()
std::chrono::month(date.month),
std::chrono::day(date.day),
};
return std::format("{:%d %B}", chronoDate);
return std::format("{:%B %d}", chronoDate);
});
}
@ -361,15 +361,21 @@ void UiState::reloadTasks()
auto &currentDay = view_[dayIndex];
auto slintEvents = std::make_shared<slint::VectorModel<Event>>();
auto slintDayTasks = std::make_shared<slint::VectorModel<TaskData>>();
slintDays->push_back(Day{
.sourceId = currentDay.day->source()->id(),
.id = dayIndex,
.date = MiraiDateToSlintDate(currentDay.day->getDate()),
.events = slintEvents,
.tasks = slintDayTasks,
.isLate = currentDay.day->getDate() < todayDate,
.isToday = currentDay.day->getDate() == todayDate,
});
auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(
std::chrono::sys_days(currentDay.day->getDate().toStdChrono()) -
std::chrono::sys_days(todayDate.toStdChrono())
)
.count();
slintDays->push_back(
Day{.sourceId = currentDay.day->source()->id(),
.id = dayIndex,
.date = MiraiDateToSlintDate(currentDay.day->getDate()),
.events = slintEvents,
.tasks = slintDayTasks,
.isLate = currentDay.day->getDate() < todayDate,
.isToday = currentDay.day->getDate() == todayDate,
.relativeDaysDiff = static_cast<int>(relativeDaysDiff)}
);
for (int taskIndex = 0; taskIndex < currentDay.filteredTasks.size(); ++taskIndex) {
auto &task = currentDay.filteredTasks.at(taskIndex);
std::vector<slint::SharedString> tags;

View file

@ -26,7 +26,8 @@ export struct Day {
events: [Event],
tasks: [TaskData],
isLate: bool,
isToday: bool
isToday: bool,
relativeDaysDiff: int
}
struct OpenNewTaskFormParams {

View file

@ -80,10 +80,14 @@ export component MainView inherits Rectangle {
color: day.isLate ? Palette.orange : Palette.foreground;
font-size: 1.2rem;
}
if day.isToday : VerticalLayout {
VerticalLayout {
alignment: center;
VText {
text: " - Today";
text: day.relativeDaysDiff == 0 ? " - today" :
day.relativeDaysDiff == 1 ? " - tomorrow" :
day.relativeDaysDiff == -1 ? " - yesterday" :
day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
" - \{-day.relativeDaysDiff} days ago";
color: Palette.foreground-hint;
font-size: 1rem;
}