Skip to content

Commit 33364bd

Browse files
committed
fix(linux,windows): pass raw datetime components instead of epoch in dive converters
The Pigeon API was updated to accept individual datetime fields (year, month, day, hour, minute, second, timezone_offset) but the Linux and Windows native converters were still passing a single epoch value, causing build failures due to argument count mismatches.
1 parent 07ecc7b commit 33364bd

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

packages/libdivecomputer_plugin/linux/dive_converter.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "dive_converter.h"
22

3+
#include <limits.h>
34
#include <math.h>
45
#include <stdint.h>
56
#include <stdio.h>
67
#include <string.h>
7-
#include <time.h>
88

99
const char* map_event_type(unsigned int type) {
1010
switch (type) {
@@ -47,16 +47,18 @@ LibdivecomputerPluginParsedDive* convert_parsed_dive(
4747
snprintf(hex + i * 2, 3, "%02x", dive->fingerprint[i]);
4848
}
4949

50-
// Convert datetime to epoch seconds (UTC).
51-
struct tm t = {0};
52-
t.tm_year = dive->year - 1900;
53-
t.tm_mon = dive->month - 1;
54-
t.tm_mday = dive->day;
55-
t.tm_hour = dive->hour;
56-
t.tm_min = dive->minute;
57-
t.tm_sec = dive->second;
58-
t.tm_isdst = 0;
59-
int64_t epoch = (int64_t)timegm(&t);
50+
// Pass raw datetime components (wall-clock-as-UTC).
51+
int64_t dt_year = (int64_t)dive->year;
52+
int64_t dt_month = (int64_t)dive->month;
53+
int64_t dt_day = (int64_t)dive->day;
54+
int64_t dt_hour = (int64_t)dive->hour;
55+
int64_t dt_minute = (int64_t)dive->minute;
56+
int64_t dt_second = (int64_t)dive->second;
57+
58+
// INT32_MIN means "timezone not reported" per libdivecomputer convention.
59+
int64_t tz_val = (int64_t)dive->timezone;
60+
int64_t* tz_offset =
61+
(dive->timezone == INT32_MIN) ? NULL : &tz_val;
6062

6163
// Convert samples (all 14 fields, sentinels -> NULL).
6264
FlValue* samples = fl_value_new_list();
@@ -232,7 +234,8 @@ LibdivecomputerPluginParsedDive* convert_parsed_dive(
232234

233235
LibdivecomputerPluginParsedDive* result =
234236
libdivecomputer_plugin_parsed_dive_new(
235-
hex, epoch, dive->max_depth, dive->avg_depth,
237+
hex, dt_year, dt_month, dt_day, dt_hour, dt_minute, dt_second,
238+
tz_offset, dive->max_depth, dive->avg_depth,
236239
(int64_t)dive->duration, min_temp, max_temp, samples, tanks,
237240
gas_mixes, events, dive_mode, deco_algorithm, gf_low, gf_high,
238241
conservatism);

packages/libdivecomputer_plugin/windows/dive_converter.cc

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include "dive_converter.h"
22

3+
#include <climits>
34
#include <cmath>
45
#include <cstdint>
56
#include <cstdio>
67
#include <cstring>
7-
#include <ctime>
8-
#include <limits>
98
#include <optional>
109
#include <string>
1110
#include <vector>
@@ -50,16 +49,19 @@ ParsedDive ConvertParsedDive(const libdc_parsed_dive_t& dive) {
5049
snprintf(hex + i * 2, 3, "%02x", dive.fingerprint[i]);
5150
}
5251

53-
// Convert datetime to epoch seconds (UTC).
54-
struct tm t = {};
55-
t.tm_year = dive.year - 1900;
56-
t.tm_mon = dive.month - 1;
57-
t.tm_mday = dive.day;
58-
t.tm_hour = dive.hour;
59-
t.tm_min = dive.minute;
60-
t.tm_sec = dive.second;
61-
t.tm_isdst = 0;
62-
int64_t epoch = static_cast<int64_t>(_mkgmtime(&t));
52+
// Pass raw datetime components (wall-clock-as-UTC).
53+
int64_t dt_year = static_cast<int64_t>(dive.year);
54+
int64_t dt_month = static_cast<int64_t>(dive.month);
55+
int64_t dt_day = static_cast<int64_t>(dive.day);
56+
int64_t dt_hour = static_cast<int64_t>(dive.hour);
57+
int64_t dt_minute = static_cast<int64_t>(dive.minute);
58+
int64_t dt_second = static_cast<int64_t>(dive.second);
59+
60+
// INT32_MIN means "timezone not reported" per libdivecomputer convention.
61+
std::optional<int64_t> tz_offset =
62+
(dive.timezone == INT32_MIN)
63+
? std::nullopt
64+
: std::optional<int64_t>(static_cast<int64_t>(dive.timezone));
6365

6466
// Convert samples (all 14 fields, sentinels -> nullptr).
6567
flutter::EncodableList samples;
@@ -238,7 +240,13 @@ ParsedDive ConvertParsedDive(const libdc_parsed_dive_t& dive) {
238240

239241
return ParsedDive(
240242
std::string(hex),
241-
epoch,
243+
dt_year,
244+
dt_month,
245+
dt_day,
246+
dt_hour,
247+
dt_minute,
248+
dt_second,
249+
tz_offset ? &*tz_offset : nullptr,
242250
dive.max_depth,
243251
dive.avg_depth,
244252
static_cast<int64_t>(dive.duration),

0 commit comments

Comments
 (0)