From 13e0b49dc65e0311b76ee743d59a93e16dda3852 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 16 Feb 2026 18:06:24 +0100 Subject: [PATCH] change refactor time str from tm --- src/time_format.c | 15 --------------- src/time_format.h | 1 - src/xml.c | 4 ++-- tests/time_format_tests.c | 16 ---------------- 4 files changed, 2 insertions(+), 34 deletions(-) diff --git a/src/time_format.c b/src/time_format.c index 2937803..9270223 100644 --- a/src/time_format.c +++ b/src/time_format.c @@ -107,21 +107,6 @@ char* get_date_str(const struct tm date) return datestr; } -char* get_time_str_from_tm(const struct tm time) -{ - char* timestr = malloc(sizeof(char) * MAX_TIME_STR_LENGTH); - if (timestr == NULL) - return NULL; - - memset(timestr, 0, MAX_TIME_STR_LENGTH); - - sprintf(timestr, "%02d:%02d", - time.tm_hour, - time.tm_min); - - return timestr; -} - char* get_time_str_from_int(const uint8_t hour, const uint8_t min) { char* timestr = malloc(sizeof(char) * MAX_TIME_STR_LENGTH); diff --git a/src/time_format.h b/src/time_format.h index 313e6b4..e6249bb 100644 --- a/src/time_format.h +++ b/src/time_format.h @@ -9,7 +9,6 @@ char* get_time_overtime_str(const time_t timediff); char* get_weekday_str(const uint8_t wday); char* get_weekday_short_str(const uint8_t wday); char* get_date_str(const struct tm date); -char* get_time_str_from_tm(const struct tm time); char* get_time_str_from_int(const uint8_t hour, const uint8_t min); time_t get_seconds_from_str(const char* timestr); diff --git a/src/xml.c b/src/xml.c index a903f25..31aa841 100644 --- a/src/xml.c +++ b/src/xml.c @@ -229,9 +229,9 @@ void _write_entry_node(xmlTextWriterPtr xmlWriter, _write_attribute(xmlWriter, "wochentag", &wday_short_str); char* datestr = get_date_str(begin_tm); _write_attribute(xmlWriter, "datum", &datestr); - char* begin_str = get_time_str_from_tm(begin_tm); + char* begin_str = get_time_str_from_int(begin_tm.tm_hour, begin_tm.tm_min); _write_attribute(xmlWriter, "begin", &begin_str); - char* end_str = get_time_str_from_tm(end_tm); + char* end_str = get_time_str_from_int(end_tm.tm_hour, end_tm.tm_min); _write_attribute(xmlWriter, "ende", &end_str); char* breaktimestr = get_time_str(breaktime); _write_attribute(xmlWriter, "pause", &breaktimestr); diff --git a/tests/time_format_tests.c b/tests/time_format_tests.c index 45acc28..66f52e7 100644 --- a/tests/time_format_tests.c +++ b/tests/time_format_tests.c @@ -296,21 +296,6 @@ void get_date_str_from_tm_test() datestr = NULL; } -void get_time_str_from_tm_test() -{ - struct tm time = { - .tm_hour = 16, - .tm_min = 25 - }; - - char* timestr = get_time_str_from_tm(time); - - assert_string_equal(timestr, "16:25"); - - free(timestr); - timestr = NULL; -} - void get_time_str_from_four_nine_test() { char* timestr = get_time_str_from_int(4, 9); @@ -362,7 +347,6 @@ int main() cmocka_unit_test(get_month_from_date_test), cmocka_unit_test(get_dat_from_date_test), cmocka_unit_test(get_date_str_from_tm_test), - cmocka_unit_test(get_time_str_from_tm_test), cmocka_unit_test(get_time_str_from_four_nine_test), cmocka_unit_test(get_time_str_from_twenty_three_fity_nine_test) }; -- 2.47.3