Add current time indicator of the current day on the Calendar

This commit is contained in:
Vyn 2024-11-06 18:38:42 +01:00
parent ab2200ecc1
commit e2cd994026
9 changed files with 54 additions and 8 deletions

View file

@ -6,6 +6,7 @@
#include "DateTime.h"
#include <charconv>
#include <chrono>
#include <optional>
#include <ranges>
#include <string>
@ -54,10 +55,6 @@ Date::Date(std::chrono::year_month_day chronoDate)
day = static_cast<unsigned>(chronoDate.day());
}
int year;
unsigned month;
unsigned day;
bool Date::operator==(const Date &other) const
{
return other.year == year && other.month == month && other.day == day;
@ -92,6 +89,21 @@ bool Date::operator<=(const Date &other) const
return (*this < other) || (*this == other);
}
Time::Time(int hour, int minute) : hour(hour), minute(minute)
{
}
Time::Time(std::chrono::time_point<std::chrono::system_clock> tp)
{
auto localTp = std::chrono::zoned_time{std::chrono::current_zone(), tp}.get_local_time();
auto chronoDate = std::chrono::floor<std::chrono::days>(localTp);
auto chronoTime =
std::chrono::hh_mm_ss{std::chrono::duration_cast<std::chrono::minutes>(localTp - chronoDate)
};
hour = static_cast<int>(chronoTime.hours().count());
minute = static_cast<int>(chronoTime.minutes().count());
}
bool Time::operator==(const Time &other) const
{
return other.hour == hour && other.minute == minute;

View file

@ -61,9 +61,10 @@ Time stringToTime(const std::string &str)
if (str[2] != 'h') {
throw std::runtime_error("Malformated time range");
}
Time time{};
std::from_chars(str.data(), str.data() + 2, time.hour);
std::from_chars(str.data() + 3, str.data() + 5, time.minute);
int hour, minute;
std::from_chars(str.data(), str.data() + 2, hour);
std::from_chars(str.data() + 3, str.data() + 5, minute);
Time time{hour, minute};
return time;
}

View file

@ -6,6 +6,7 @@
#include "View.h"
#include "utils.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>
@ -104,6 +105,13 @@ void View::update()
auto tasks = source->getUnscheduledTasks();
unscheduledTasks_.insert(unscheduledTasks_.end(), tasks.begin(), tasks.end());
}
for (auto &date : dates) {
auto &events = date.second.events;
std::sort(events.begin(), events.end(), [](const Event &a, const Event &b) {
return a.startsAt() < b.startsAt();
});
}
}
void View::removeSources()