]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change method get tm from time
authorBastian Dehn <hhaalo@arcor.de>
Sat, 14 Feb 2026 12:32:37 +0000 (13:32 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 14 Feb 2026 12:32:37 +0000 (13:32 +0100)
src/feierabend.c

index fc6f59a9475087ce0e5b1b4caaade95f32623082..a143c08eed50391737062f18e72c5009ad14e5ad 100644 (file)
@@ -107,6 +107,15 @@ 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 tm_value;
+       const struct tm* time_tm = localtime(&time);
+       memcpy(&tm_value, time_tm, sizeof(struct tm));
+
+       return tm_value;
+}
+
 int main(int argc, const char* argv[])
 {
        if (argc < 3 || (argc > 3 && argc < 5)) {
@@ -147,17 +156,10 @@ int main(int argc, const char* argv[])
 
        const time_t begin = mktime(&begin_tm);
        const time_t end = mktime(&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* tmp_work_eight_end = localtime(&worktime_eight_end);
-       struct tm work_eight_end_tm;
-       memcpy(&work_eight_end_tm, tmp_work_eight_end, sizeof(struct tm));
-
-       const struct tm* tmp_max_work_end = localtime(&worktime_max_end);
-       struct tm max_work_end_tm;
-       memcpy(&max_work_end_tm, tmp_max_work_end, sizeof(struct tm));
+       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");