From fb3a157462e035edc4a0c018ede209b239ba7323 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 30 Jun 2024 22:02:20 +0200 Subject: [PATCH] core: move time_during_dive_with_offset() to struct dive Feels natural in a C++ code base. Signed-off-by: Berthold Stoeger --- core/dive.cpp | 6 +++--- core/dive.h | 3 +-- core/filterconstraint.cpp | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/dive.cpp b/core/dive.cpp index d5d393201..9740b75fc 100644 --- a/core/dive.cpp +++ b/core/dive.cpp @@ -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; } diff --git a/core/dive.h b/core/dive.h index 9ab5425eb..998d7da24 100644 --- a/core/dive.h +++ b/core/dive.h @@ -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 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); diff --git a/core/filterconstraint.cpp b/core/filterconstraint.cpp index 36c2d3256..658cd5de6 100644 --- a/core/filterconstraint.cpp +++ b/core/filterconstraint.cpp @@ -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: