aboutsummaryrefslogtreecommitdiffstats
path: root/core/divelist.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-22 23:11:23 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-23 13:22:24 -0800
commit70897dd1b7d33f3d1f6b47acc587a7f33a176a04 (patch)
treed2304bd23c797d558b709dfa20d9a5afef2cd286 /core/divelist.c
parent68414531adeb68f7ad01c98bbac4d4d950409f02 (diff)
downloadsubsurface-70897dd1b7d33f3d1f6b47acc587a7f33a176a04.tar.gz
Core: move is-single-day-trip and count-shown functions into core
These functionality was used by the desktop filter. To unify desktop and mobile, move it into two new functions in divelist.c Since one of them is the only caller of is_same_day() move that likewise into divelist.c and make it of static linkage. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divelist.c')
-rw-r--r--core/divelist.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 1dc4e3d8a..ee7986466 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -47,6 +47,8 @@
* int find_next_visible_dive(timestamp_t when);
* void clear_dive_file_data()
* void clear_table(struct dive_table *table)
+ * bool trip_is_single_day(const struct dive_trip *trip)
+ * int trip_shown_dives(const struct dive_trip *trip)
*/
#include <unistd.h>
#include <stdio.h>
@@ -1875,3 +1877,37 @@ struct dive *find_next_visible_dive(timestamp_t when)
return NULL;
}
+
+static bool is_same_day(timestamp_t trip_when, timestamp_t dive_when)
+{
+ static timestamp_t twhen = (timestamp_t) 0;
+ static struct tm tmt;
+ struct tm tmd;
+
+ utc_mkdate(dive_when, &tmd);
+
+ if (twhen != trip_when) {
+ twhen = trip_when;
+ utc_mkdate(twhen, &tmt);
+ }
+
+ return (tmd.tm_mday == tmt.tm_mday) && (tmd.tm_mon == tmt.tm_mon) && (tmd.tm_year == tmt.tm_year);
+}
+
+bool trip_is_single_day(const struct dive_trip *trip)
+{
+ if (trip->dives.nr <= 1)
+ return true;
+ return is_same_day(trip->dives.dives[0]->when,
+ trip->dives.dives[trip->dives.nr - 1]->when);
+}
+
+int trip_shown_dives(const struct dive_trip *trip)
+{
+ int res = 0;
+ for (int i = 0; i < trip->dives.nr; ++i) {
+ if (!trip->dives.dives[i]->hidden_by_filter)
+ res++;
+ }
+ return res;
+}