]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
add test for correct saldo seconds
authorBastian Dehn <hhaalo@arcor.de>
Sun, 23 Jun 2024 12:25:22 +0000 (14:25 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 23 Jun 2024 12:25:22 +0000 (14:25 +0200)
src/time_format.c
tests/time_format_tests.c

index eec05ed1e579bc23547983fd58abb03ed7cd5b23..66f74d33a07c3cbc2f82da6bff3cd054583ea1d4 100644 (file)
@@ -45,11 +45,20 @@ void get_seconds_from_string(const char* timestr, time_t* seconds)
        memset(str, 0, 7);
        strncpy(str, timestr, 7);
        first_str_pos = str;
+       int minus = 0;
+       
+       if (str[0] == '-')
+               minus = 1;
 
        str = strtok(str, ":");
        *seconds = atol(str) * ONE_HOUR;
        str = strtok(NULL, ":");
-       *seconds += atol(str) * 60;
+
+       if (minus)
+               *seconds += atol(str) * 60 * -1;
+       else
+               *seconds += atol(str) * 60;
+
 
        free(first_str_pos);
        first_str_pos = NULL;
index 011df3bac3019ed71b66f7d94b178391437afb31..ee159e8bdbf92d8cabad33375c8f8a60de827931 100644 (file)
@@ -290,6 +290,16 @@ void get_seconds_from_str()
        assert_int_equal(seconds, 15300);
 }
 
+void get_seconds_from_str_minus()
+{
+       const char* timestr = "-04:15";
+       time_t seconds = 0;
+
+       get_seconds_from_string(timestr, &seconds);
+
+       assert_int_equal(seconds, -15300);
+}
+
 int main()
 {
        const struct CMUnitTest tests[] = {
@@ -314,7 +324,8 @@ int main()
                cmocka_unit_test(get_short_thursday),
                cmocka_unit_test(get_short_friday),
                cmocka_unit_test(get_short_saturday),
-               cmocka_unit_test(get_seconds_from_str)
+               cmocka_unit_test(get_seconds_from_str),
+               cmocka_unit_test(get_seconds_from_str_minus)
        };
 
        return cmocka_run_group_tests(tests, NULL, NULL);