Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vacation and sickness #10

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ std::chrono::minutes Plan::planned_normal_working_time(const Period& period) con
{
using std::chrono_literals::operator""min;
auto result = 0min;
for (int day = 0; day <= period.days(); ++day) {
result += planned_normal_working_time(period.begin().addDays(day));
for (const auto date : period.dates()) {
result += planned_normal_working_time(date);
}
return result;
}
Expand Down
18 changes: 13 additions & 5 deletions src/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ using ProjectIndexMap = std::map<const Project*, int>;
nlohmann::json& j = vs.emplace_back();
j[begin_key] = interval->begin();
j[end_key] = interval->end();
try {
j[project_key] = project_index_map.at(interval->project());
} catch (std::out_of_range&) {
throw DeserializationError("Failed to store project reference.");
if (const auto project = interval->project(); project == nullptr) {
j[project_key] = nullptr;
} else {
try {
j[project_key] = project_index_map.at(project);
} catch (std::out_of_range&) {
throw DeserializationError("Failed to store project reference.");
}
}
}
return vs;
Expand All @@ -57,11 +61,15 @@ using ProjectIndexMap = std::map<const Project*, int>;
std::deque<std::unique_ptr<Interval>> intervals;
for (const auto& v : data) {
try {
auto& interval = *intervals.emplace_back(std::make_unique<Interval>(projects.at(v.at(project_key))));
const auto project_reference = v.at(project_key);
const auto* const project = project_reference.is_null() ? nullptr : projects.at(project_reference);
auto& interval = *intervals.emplace_back(std::make_unique<Interval>(project));
interval.swap_begin(v.at(begin_key));
interval.swap_end(v.at(end_key));
} catch (const std::out_of_range&) {
throw DeserializationError("Failed to restore project reference.");
} catch (const nlohmann::json::exception&) {
throw DeserializationError("Failed to restore project reference.");
}
}
return std::make_unique<IntervalModel>(std::move(intervals));
Expand Down
Loading