12345678910111213141516171819202122232425262728293031 |
- /*
- * SPDX-FileCopyrightText: 2023 Helmut Pozimski <helmut@pozimski.eu>
- *
- * SPDX-License-Identifier: GPL-2.0-only
- */
- #include <freertos/FreeRTOS.h>
- #include <freertos/semphr.h>
- #include <time.h>
- #include "configuration.h"
-
- static SemaphoreHandle_t mutex = NULL;
-
- struct tm* convert_to_local(struct tm *timeinfo) {
- if (mutex == NULL) {
- mutex = xSemaphoreCreateMutex();
- }
- xSemaphoreTake(mutex, portMAX_DELAY);
- setenv("TZ", "GMT+0GMT+0", 1);
- tzset();
- time_t epoch_time = mktime(timeinfo);
- setenv("TZ", LOCAL_TIMEZONE, 1);
- tzset();
- struct tm* result = localtime(&epoch_time);
- setenv("TZ", "GMT+0GMT+0", 1);
- tzset();
- xSemaphoreGive(mutex);
- return result;
- }
|