From 8564e6d0f4f6f94ae81ffda5aca8906466e307bf Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 14 Feb 2026 13:25:11 +0100 Subject: [PATCH] change init tm and return const --- src/xml.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/xml.c b/src/xml.c index 28b1145..0ef765b 100644 --- a/src/xml.c +++ b/src/xml.c @@ -166,6 +166,24 @@ void _copy_entry(xmlTextReaderPtr xmlreader, xmlTextWriterPtr xmlwriter) xmlElemContent = NULL; } +struct tm _init_tm_with_date(const char* date, uint8_t hour, uint8_t min) +{ + struct tm value; + const time_t now = time(NULL); + const struct tm* tmp_now = gmtime(&now); + memcpy(&value, tmp_now, sizeof(struct tm)); + + if (date != NULL) { + value.tm_year = get_year_from_str(date) - 1900; + value.tm_mon = get_month_from_str(date) - 1; + value.tm_mday = get_day_from_str(date); + } + value.tm_hour = hour; + value.tm_min = min; + + return value; +} + void _write_entry_node(xmlTextWriterPtr xmlWriter, const char* date, uint8_t begin_hour, @@ -174,24 +192,8 @@ void _write_entry_node(xmlTextWriterPtr xmlWriter, uint8_t end_min, time_t last_saldo) { - const time_t now = time(NULL); - const struct tm* tmp_now = gmtime(&now); - struct tm begin_tm; - struct tm end_tm; - memcpy(&begin_tm, tmp_now, sizeof(struct tm)); - memcpy(&end_tm, tmp_now, sizeof(struct tm)); - if (date != NULL) { - begin_tm.tm_year = get_year_from_str(date) - 1900; - begin_tm.tm_mon = get_month_from_str(date) - 1; - begin_tm.tm_mday = get_day_from_str(date); - end_tm.tm_year = get_year_from_str(date) - 1900; - end_tm.tm_mon = get_month_from_str(date) - 1; - end_tm.tm_mday = get_day_from_str(date); - } - begin_tm.tm_hour = begin_hour; - begin_tm.tm_min = begin_min; - end_tm.tm_hour = end_hour; - end_tm.tm_min = end_min; + const struct tm begin_tm = _init_tm_with_date(date, begin_hour, begin_min); + const struct tm end_tm = _init_tm_with_date(date, end_hour, end_min); const time_t begin = mktime(&begin_tm); const time_t end = mktime(&end_tm); const time_t brutto_worktime = get_brutto_worktime(begin, end); -- 2.47.3