From d8d10d2d7026f64de315a8e7df0c2b710e72a39a Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 14 Feb 2026 14:00:33 +0100 Subject: [PATCH] change only two args for print version --- src/feierabend.c | 58 ++++++++++++++++++++++-------------------------- src/xml.c | 4 ++-- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/feierabend.c b/src/feierabend.c index a143c08..148253f 100644 --- a/src/feierabend.c +++ b/src/feierabend.c @@ -107,7 +107,7 @@ 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 _get_tm_from_time(const time_t time) { struct tm tm_value; const struct tm* time_tm = localtime(&time); @@ -116,50 +116,44 @@ struct tm get_tm_from_time(const time_t time) return tm_value; } +struct tm _init_tm_with_time(const char* hour, const char* min) +{ + struct tm value; + const time_t now = time(NULL); + const struct tm* now_tm = localtime(&now); + memcpy(&value, now_tm, sizeof(struct tm)); + + if (hour != NULL) + value.tm_hour = atoi(hour); + + if (min != NULL) + value.tm_min = atoi(min); + + return value; +} + int main(int argc, const char* argv[]) { - if (argc < 3 || (argc > 3 && argc < 5)) { - printf("ERROR: %s [ ]\n", argv[0]); + if (argc < 3) { + printf("ERROR: %s \n", argv[0]); return 1; } - if (!validate_hourstring(argv[1]) - || !validate_minutestring(argv[2])) { + if (!validate_hourstring(argv[1]) || !validate_minutestring(argv[2])) { printf("ERROR: one or more invalid arguments\n"); return 1; } - if (argc == 5) { - if (!validate_hourstring(argv[3]) - || !validate_minutestring(argv[4])) { - printf("ERROR: one or more invalid arguments\n"); - return 1; - } - } - printf("Version: %s\n\n", PROJECT_VERSION); - const time_t now = time(NULL); - const struct tm* tmp_now_tm = localtime(&now); - - struct tm begin_tm; - struct tm end_tm; - memcpy(&begin_tm, tmp_now_tm, sizeof(struct tm)); - memcpy(&end_tm, tmp_now_tm, sizeof(struct tm)); - - begin_tm.tm_hour = atoi(argv[1]); - begin_tm.tm_min = atoi(argv[2]); - if (argc == 5) { - end_tm.tm_hour = atoi(argv[3]); - end_tm.tm_min = atoi(argv[4]); - } - - const time_t begin = mktime(&begin_tm); - const time_t end = mktime(&end_tm); + const struct tm begin_tm = _init_tm_with_time(argv[1], argv[2]); + const struct tm end_tm = _init_tm_with_time(NULL, NULL); + const time_t begin = mktime((struct tm*) &begin_tm); + const time_t end = mktime((struct tm*) &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 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); + 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"); diff --git a/src/xml.c b/src/xml.c index 0ef765b..32bed42 100644 --- a/src/xml.c +++ b/src/xml.c @@ -194,8 +194,8 @@ void _write_entry_node(xmlTextWriterPtr xmlWriter, { 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 begin = mktime((struct tm*) &begin_tm); + const time_t end = mktime((struct tm*) &end_tm); const time_t brutto_worktime = get_brutto_worktime(begin, end); const time_t netto_worktime = get_current_worktime(begin, end); const time_t overtime = get_current_worktime_diff_to_end_eight_hour(begin, end); -- 2.47.3