core: move time_during_dive_with_offset() to struct dive

Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-30 22:02:20 +02:00 committed by bstoeger
parent 28814829e0
commit fb3a157462
3 changed files with 5 additions and 6 deletions

View file

@ -2274,10 +2274,10 @@ timestamp_t dive::endtime() const
return when + totaltime().seconds;
}
bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset)
bool dive::time_during_dive_with_offset(timestamp_t when, timestamp_t offset) const
{
timestamp_t start = dive->when;
timestamp_t end = dive->endtime();
timestamp_t start = when;
timestamp_t end = endtime();
return start - offset <= when && when <= end + offset;
}

View file

@ -111,6 +111,7 @@ struct dive {
const cylinder_t *get_cylinder(int idx) const;
weight_t total_weight() const;
int get_salinity() const;
bool time_during_dive_with_offset(timestamp_t when, timestamp_t offset) const;
std::string get_country() const;
std::string get_location() const;
@ -166,8 +167,6 @@ struct dive_components {
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
extern int save_dives(const char *filename);
extern int save_dives_logic(const char *filename, bool select_only, bool anonymize);
extern int save_dive(FILE *f, const struct dive &dive, bool anonymize);

View file

@ -949,7 +949,7 @@ static bool check_datetime_range(const filter_constraint &c, const struct dive *
case FILTER_CONSTRAINT_EQUAL:
// Exact mode is a bit strange for timestamps. Therefore we return any dive
// where the given timestamp is during that dive.
return time_during_dive_with_offset(d, c.data.timestamp_range.from, 0) != c.negate;
return d->time_during_dive_with_offset(c.data.timestamp_range.from, 0) != c.negate;
case FILTER_CONSTRAINT_LESS:
return (d->endtime() <= c.data.timestamp_range.to) != c.negate;
case FILTER_CONSTRAINT_GREATER: