Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/pico_util/datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void datetime_to_tm(const datetime_t *dt, struct tm *tm) {
tm->tm_hour = dt->hour;
tm->tm_min = dt->min;
tm->tm_sec = dt->sec;
tm->tm_isdst = -1;
}

void tm_to_datetime(const struct tm *tm, datetime_t *dt) {
Expand Down
42 changes: 42 additions & 0 deletions test/pico_time_test/pico_time_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static int issue_1953_test(void);
static int issue_2118_test(void);
static int issue_2148_test(void);
static int issue_2186_test(void);
static int issue_2374_test(void);

int main() {
setup_default_uart();
Expand Down Expand Up @@ -263,6 +264,8 @@ int main() {

issue_2186_test();

issue_2374_test();

PICOTEST_END_TEST();
}

Expand Down Expand Up @@ -421,3 +424,42 @@ static int issue_2148_test(void) {
#endif
return 0;
}

static void fill_stack(int val) {
uint8_t array[50];
memset(array, val, sizeof(array));
}

// aon_timer_get_time called aon_timer_get_time_calendar which called datetime_to_tm
// which didn't initialise tm_isdst
static int issue_2374_test(void) {
#if HAS_RP2040_RTC && !__clang__
PICOTEST_START_SECTION("Issue #2374 defect - time goes backwards");
setenv("TZ", "PST8PDT7,M3.2.0/2,M11.1.0/02:00:00", 1);
tzset();

struct timespec ts = { .tv_sec = 1743055938, .tv_nsec = 0 };
aon_timer_start(&ts);

struct timespec ts1;
fill_stack(1); // Setting tm_isdst if it's uninitialised
hard_assert(aon_timer_get_time(&ts1));

sleep_ms(1000);

struct timespec ts2;
fill_stack(0); // Setting tm_isdst if it's uninitialised
hard_assert(aon_timer_get_time(&ts2));

// Check time hasn't been adjusted due to dst
hard_assert(ts1.tv_sec == ts2.tv_sec - 1);

setenv("TZ", "", 1);
tzset();

aon_timer_stop();

PICOTEST_END_SECTION();
#endif
return 0;
}