]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change init time without struct tm
authorBastian Dehn <hhaalo@arcor.de>
Mon, 23 Feb 2026 15:29:33 +0000 (16:29 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 23 Feb 2026 15:29:33 +0000 (16:29 +0100)
src/feierabend.c

index 96994d972b63be96b70a751f03c0e87f5621a536..56a4109ddfee17aa6d003ab93f41d2eef21f8344 100644 (file)
@@ -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");