Flesh out time module
This commit is contained in:
33
components/time/time_manager.c
Normal file
33
components/time/time_manager.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (c) Camden Dixie O'Brien
|
||||
*/
|
||||
|
||||
#include "time_manager.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
static void handle_timezone_update(const char *timezone)
|
||||
{
|
||||
setenv("TZ", timezone, 1);
|
||||
tzset();
|
||||
}
|
||||
|
||||
void time_manager_init(void)
|
||||
{
|
||||
char timezone[CONFIG_MAX_VALUE_SIZE];
|
||||
(void)config_get_timezone(timezone, CONFIG_MAX_VALUE_SIZE);
|
||||
handle_timezone_update(timezone);
|
||||
|
||||
config_add_timezone_callback(&handle_timezone_update);
|
||||
}
|
||||
|
||||
Time get_time(void)
|
||||
{
|
||||
const time_t now = time(NULL);
|
||||
struct tm timeinfo;
|
||||
(void)localtime_r(&now, &timeinfo);
|
||||
return (Time) { .hour = timeinfo.tm_hour, .minute = timeinfo.tm_min };
|
||||
}
|
||||
Reference in New Issue
Block a user