data/FreeSlots.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QDate> | ||
| 4 | #include <QDateTime> | ||
| 5 | #include <QList> | ||
| 6 | #include <QSet> | ||
| 7 | #include <QTime> | ||
| 8 | #include <QTimeZone> | ||
| 9 | |||
| 10 | // Sprint 108 S108.8.1 (D-22): free times for *Suggest times* — slots of a | ||
| 11 | // given duration inside working hours on working days, over a horizon, | ||
| 12 | // that overlap no busy interval. Pure and deterministic: the caller passes | ||
| 13 | // the busy intervals (the shown calendars' timed occurrences, recurrences | ||
| 14 | // expanded) and the clock (`notBefore`). | ||
| 15 | // | ||
| 16 | // Slots start on a grid of `stepMinutes` from the day's start. A wall time | ||
| 17 | // that does not exist on a daylight-saving day (the spring gap) is skipped; | ||
| 18 | // a slot that would cross the end of working hours is not offered. | ||
| 19 | namespace FreeSlots { | ||
| 20 | |||
| 21 | struct Interval { | ||
| 22 | 4 | QDateTime start; | |
| 23 | 4 | QDateTime end; | |
| 24 |
2/4✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 4 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 4 times.
|
4 | bool operator==(const Interval &) const = default; |
| 25 | }; | ||
| 26 | |||
| 27 | struct Options { | ||
| 28 | QDate from; // first day looked at | ||
| 29 | int days = 14; // horizon in days (1–60) | ||
| 30 | QTime dayStart{8, 0}; | ||
| 31 | QTime dayEnd{18, 0}; | ||
| 32 | QSet<int> workingDays{1, 2, 3, 4, 5}; // Qt::DayOfWeek values | ||
| 33 | int durationMinutes = 60; // 5–480 | ||
| 34 | int stepMinutes = 30; // 5–120 | ||
| 35 | int maximum = 40; // at most this many slots | ||
| 36 | QDateTime notBefore; // nothing earlier (now) | ||
| 37 | QTimeZone zone = QTimeZone::LocalTime; | ||
| 38 | }; | ||
| 39 | |||
| 40 | QList<Interval> find(const QList<Interval> &busy, const Options &options); | ||
| 41 | |||
| 42 | // One busy stretch of a day as fractions of its working hours: 0 is | ||
| 43 | // `dayStart`, 1 is `dayEnd`. | ||
| 44 | struct Span { | ||
| 45 | double from = 0; | ||
| 46 | double to = 0; | ||
| 47 | bool operator==(const Span &) const = default; | ||
| 48 | }; | ||
| 49 | |||
| 50 | // What the scheduling grid draws for one row (S108.8.6): the parts of | ||
| 51 | // `busy` inside `day` between `dayStart` and `dayEnd`, clipped to them, | ||
| 52 | // sorted, overlapping and touching stretches merged. Intervals of other | ||
| 53 | // days give nothing. | ||
| 54 | QList<Span> daySpans(const QList<Interval> &busy, const QDate &day, const QTime &dayStart, const QTime &dayEnd, | ||
| 55 | const QTimeZone &zone = QTimeZone::LocalTime); | ||
| 56 | |||
| 57 | } // namespace FreeSlots | ||
| 58 |