]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change only two args for print version
authorBastian Dehn <hhaalo@arcor.de>
Sat, 14 Feb 2026 13:00:33 +0000 (14:00 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 14 Feb 2026 13:00:33 +0000 (14:00 +0100)
src/feierabend.c
src/xml.c

index a143c08eed50391737062f18e72c5009ad14e5ad..148253f421c69bd34fa0f9813d2e7319dda9b1b4 100644 (file)
@@ -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 <begin_hours> <begin_minutes> [<end_hours> <end_minutes>]\n", argv[0]);
+       if (argc < 3) {
+               printf("ERROR: %s <begin_hours> <begin_minutes>\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");
index 0ef765b430fa73d4d7af928b3441d502150cd907..32bed42468f33ec8be429177b3851ec0caa2b78a 100644 (file)
--- 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);