]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change init tm and return const
authorBastian Dehn <hhaalo@arcor.de>
Sat, 14 Feb 2026 12:25:11 +0000 (13:25 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 14 Feb 2026 12:25:11 +0000 (13:25 +0100)
src/xml.c

index 28b114571b748c83e745e58a76b656ead0a13299..0ef765b430fa73d4d7af928b3441d502150cd907 100644 (file)
--- 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);