mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13:19 +00:00
Add hint to show how many days left relative to today
This commit is contained in:
parent
53b1280115
commit
534da46a26
4 changed files with 33 additions and 13 deletions
|
@ -25,6 +25,15 @@ struct Date {
|
||||||
bool operator<(const Date &other) const;
|
bool operator<(const Date &other) const;
|
||||||
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;
|
int year;
|
||||||
unsigned month;
|
unsigned month;
|
||||||
unsigned day;
|
unsigned day;
|
||||||
|
|
|
@ -223,7 +223,7 @@ void UiState::setupUtilsCallbacks()
|
||||||
std::chrono::month(date.month),
|
std::chrono::month(date.month),
|
||||||
std::chrono::day(date.day),
|
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 ¤tDay = view_[dayIndex];
|
auto ¤tDay = view_[dayIndex];
|
||||||
auto slintEvents = std::make_shared<slint::VectorModel<Event>>();
|
auto slintEvents = std::make_shared<slint::VectorModel<Event>>();
|
||||||
auto slintDayTasks = std::make_shared<slint::VectorModel<TaskData>>();
|
auto slintDayTasks = std::make_shared<slint::VectorModel<TaskData>>();
|
||||||
slintDays->push_back(Day{
|
auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(
|
||||||
.sourceId = currentDay.day->source()->id(),
|
std::chrono::sys_days(currentDay.day->getDate().toStdChrono()) -
|
||||||
.id = dayIndex,
|
std::chrono::sys_days(todayDate.toStdChrono())
|
||||||
.date = MiraiDateToSlintDate(currentDay.day->getDate()),
|
)
|
||||||
.events = slintEvents,
|
.count();
|
||||||
.tasks = slintDayTasks,
|
slintDays->push_back(
|
||||||
.isLate = currentDay.day->getDate() < todayDate,
|
Day{.sourceId = currentDay.day->source()->id(),
|
||||||
.isToday = currentDay.day->getDate() == todayDate,
|
.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) {
|
for (int taskIndex = 0; taskIndex < currentDay.filteredTasks.size(); ++taskIndex) {
|
||||||
auto &task = currentDay.filteredTasks.at(taskIndex);
|
auto &task = currentDay.filteredTasks.at(taskIndex);
|
||||||
std::vector<slint::SharedString> tags;
|
std::vector<slint::SharedString> tags;
|
||||||
|
|
|
@ -26,7 +26,8 @@ export struct Day {
|
||||||
events: [Event],
|
events: [Event],
|
||||||
tasks: [TaskData],
|
tasks: [TaskData],
|
||||||
isLate: bool,
|
isLate: bool,
|
||||||
isToday: bool
|
isToday: bool,
|
||||||
|
relativeDaysDiff: int
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OpenNewTaskFormParams {
|
struct OpenNewTaskFormParams {
|
||||||
|
|
|
@ -80,10 +80,14 @@ export component MainView inherits Rectangle {
|
||||||
color: day.isLate ? Palette.orange : Palette.foreground;
|
color: day.isLate ? Palette.orange : Palette.foreground;
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
}
|
}
|
||||||
if day.isToday : VerticalLayout {
|
VerticalLayout {
|
||||||
alignment: center;
|
alignment: center;
|
||||||
VText {
|
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;
|
color: Palette.foreground-hint;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue