From: Bastian Dehn Date: Mon, 23 Feb 2026 15:29:33 +0000 (+0100) Subject: change init time without struct tm X-Git-Tag: 1.3.18^2~10 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=0134a0029ad530b5925e49cd407bdb791f1bf793;p=feierabend.git change init time without struct tm --- diff --git a/src/feierabend.c b/src/feierabend.c index 96994d9..56a4109 100644 --- a/src/feierabend.c +++ b/src/feierabend.c @@ -46,8 +46,9 @@ void _print_german_long_date(const struct tm time_info) weekday = NULL; } -void _print_long_date_time(const char* label, const struct tm time_tm) +void _print_long_date_time(const char* label, const time_t time) { + const struct tm time_tm = _get_tm_from_time(time); printf("%-27s", label); _print_german_long_date(time_tm); printf("\n"); @@ -92,20 +93,14 @@ void _print_time_to_end(const uint8_t soll_hour, timestr = NULL; } -struct tm _init_tm_with_time(const char* hour, const char* min) +time_t _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); + struct tm now_tm = _get_tm_from_time(now); + now_tm.tm_hour = atoi(hour); + now_tm.tm_min = atoi(min); - if (min != NULL) - value.tm_min = atoi(min); - - return value; + return mktime(&now_tm); } int _few_arguments(const char* argv[]) @@ -132,10 +127,8 @@ int main(const int argc, const char* argv[]) printf("Version: %s\n\n", PROJECT_VERSION); - const struct tm now_tm = _init_tm_with_time(NULL, NULL); - const time_t now = mktime((struct tm*) &now_tm); - const struct tm begin_tm = _init_tm_with_time(hour, min); - const time_t begin = mktime((struct tm*) &begin_tm); + const time_t now = time(NULL); + const time_t begin = _init_tm_with_time(hour, min); const time_t worktime_eight_end = get_eight_hour_end_worktime(begin); const time_t worktime_max_end = get_ten_hour_end_worktime(begin); @@ -145,10 +138,10 @@ int main(const int argc, const char* argv[]) const time_t diff_to_end = get_current_worktime_diff_to_end_eight_hour(begin, now); const time_t diff_to_max_end = get_current_worktime_diff_to_end_ten_hour(begin, now); - _print_long_date_time(CURRENT_TIME, now_tm); + _print_long_date_time(CURRENT_TIME, now); printf("\n"); - _print_long_date_time(WORK_BEGIN, begin_tm); + _print_long_date_time(WORK_BEGIN, begin); _print_long_work_end_time(SOLL_HOUR, SOLL_MINUTES, worktime_eight_end); _print_long_work_end_time(MAX_HOUR, MAX_MINUTES, worktime_max_end); printf("\n");