From 119c898bc1854987a50a6f0faadfd9f3677da9a2 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 14 Feb 2026 13:32:37 +0100 Subject: [PATCH] change method get tm from time --- src/feierabend.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/feierabend.c b/src/feierabend.c index fc6f59a..a143c08 100644 --- a/src/feierabend.c +++ b/src/feierabend.c @@ -107,6 +107,15 @@ void _print_time_to_max_end_worktime(const time_t begin, const time_t end) timestr = NULL; } +struct tm get_tm_from_time(const time_t time) +{ + struct tm tm_value; + const struct tm* time_tm = localtime(&time); + memcpy(&tm_value, time_tm, sizeof(struct tm)); + + return tm_value; +} + int main(int argc, const char* argv[]) { if (argc < 3 || (argc > 3 && argc < 5)) { @@ -147,17 +156,10 @@ int main(int argc, const char* argv[]) const time_t begin = mktime(&begin_tm); const time_t end = mktime(&end_tm); - const time_t worktime_eight_end = get_eight_hour_end_worktime(begin); const time_t worktime_max_end = get_ten_hour_end_worktime(begin); - - const struct tm* tmp_work_eight_end = localtime(&worktime_eight_end); - struct tm work_eight_end_tm; - memcpy(&work_eight_end_tm, tmp_work_eight_end, sizeof(struct tm)); - - const struct tm* tmp_max_work_end = localtime(&worktime_max_end); - struct tm max_work_end_tm; - memcpy(&max_work_end_tm, tmp_max_work_end, sizeof(struct tm)); + const struct tm work_eight_end_tm = get_tm_from_time(worktime_eight_end); + const struct tm max_work_end_tm = get_tm_from_time(worktime_max_end); _print_time_now(end_tm); printf("\n"); -- 2.47.3