]> Kevux Git Server - kevux-tools/commitdiff
Progress: Continue working on completing the remove program.
authorKevin Day <Kevin@kevux.org>
Sun, 23 Mar 2025 22:54:06 +0000 (17:54 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 23 Mar 2025 22:54:06 +0000 (17:54 -0500)
Finish setting up any remaining start and stop values.
Make sure the timezone adjustments apply to the stop times.

Remove redundant code in the setting of the timezone.

Use `uint8_t` rather than `f_status_t` for `result` to avoid any potential confusion.

Fix the `time_spec_clocks` date and the `Not` check.

sources/c/program/kevux/tools/remove/main/convert.c
sources/c/program/kevux/tools/remove/main/preprocess.c
tests/unit/remove/c/test-remove-date_changed.c

index 36c8e15181a78e7fc86658d8c5fefb0e52ea81e5..b8856d8aebba58d9be86578a6c836acc47f23431 100644 (file)
@@ -192,12 +192,9 @@ extern "C" {
     if (matches & kt_remove_flag_convert_match_d) {
       fl_conversion_data_t conversion_data = fl_conversion_data_base_10_c;
 
-      date->start_year = 0;
-      date->start_second = 0;
-      date->start_nanosecond = 0;
-      date->stop_second = 0;
-      date->stop_nanosecond = 0;
-      date->stop_year = 0;
+      date->start_nanosecond = date->stop_nanosecond = 0;
+      date->start_second = date->stop_second = 0;
+      date->start_year = date->stop_year = 0;
       date->type = 0;
 
       // Process the first character.
@@ -325,11 +322,8 @@ extern "C" {
         memset(&time, 0, sizeof(struct tm));
 
         if (strptime(buffer.string, formats[i], &time) != 0) {
-          date->start_year = kt_remove_time_year_unix_epoch_d;
-          date->start_nanosecond = 0;
-          date->stop_second = 0;
-          date->stop_nanosecond = 0;
-          date->stop_year = 0;
+          date->start_nanosecond = date->stop_nanosecond = 0;
+          date->start_year = date->stop_year = kt_remove_time_year_unix_epoch_d;
           date->type = kt_remove_flag_date_string_d;
 
           #ifdef _available_timegm_
@@ -341,7 +335,7 @@ extern "C" {
             date->start_second += time.tm_yday * kt_remove_time_seconds_in_day_d;
           #endif // _available_timegm_
 
-          date->start_nanosecond = 0;
+          date->stop_second = date->start_second;
           matches = 1;
 
           break;
@@ -369,30 +363,31 @@ extern "C" {
     main->setting.state.status = f_time_clock_get(CLOCK_REALTIME, &now);
     if (F_status_is_error(main->setting.state.status)) return;
 
-    date->start_year = date->stop_year = kt_remove_time_year_unix_epoch_d;
-    date->start_second = date->stop_second = now.tv_sec;
     date->start_nanosecond = date->stop_nanosecond = 0;
+    date->start_second = date->stop_second = now.tv_sec;
+    date->start_year = date->stop_year = kt_remove_time_year_unix_epoch_d;
 
     if (date->type == kt_remove_flag_date_now_d) {
       date->start_nanosecond = date->stop_nanosecond = now.tv_nsec;
-
-      if (!(main->setting.flag & kt_remove_main_flag_utc_d)) {
-        kt_remove_convert_timezone(main, &date->start_year, &date->start_second);
-        if (F_status_is_error(main->setting.state.status)) return;
-      }
-
-      main->setting.state.status = F_okay;
-
-      return;
     }
 
     // Determine start of day.
     if (!(main->setting.flag & kt_remove_main_flag_utc_d)) {
       kt_remove_convert_timezone(main, &date->start_year, &date->start_second);
       if (F_status_is_error(main->setting.state.status)) return;
+
+      date->stop_second = date->start_second;
+      date->stop_year = date->start_year;
+    }
+
+    if (date->type == kt_remove_flag_date_now_d) {
+      main->setting.state.status = F_okay;
+
+      return;
     }
 
     date->start_second -= date->start_second % kt_remove_time_seconds_in_day_d;
+    date->stop_second = date->start_second;
 
     if (date->type == kt_remove_flag_date_today_d) {
       date->stop_second = date->start_second + kt_remove_time_seconds_in_day_d;
@@ -404,6 +399,8 @@ extern "C" {
       }
     }
     else if (date->type == kt_remove_flag_date_tomorrow_d) {
+      date->start_second += kt_remove_time_seconds_in_day_d;
+
       if (date->start_second > kt_remove_time_seconds_in_year_d) {
         date->stop_year = ++date->start_year;
         date->start_second -= kt_remove_time_seconds_in_year_d;
index 6b0b3251fb7bc4601fbb6ed8c60222b11b28cdfd..35ec594a9fd0ccfb33d91d59b8cc2f832759ef85 100644 (file)
@@ -482,7 +482,7 @@ extern "C" {
       kt_remove_long_updated_s,
     };
 
-    f_status_t result = F_false;
+    uint8_t result = F_false;
     f_string_static_t name_type = f_string_empty_s;
     f_number_unsigned_t match_second = 0;
     f_number_unsigned_t match_year = 0;
@@ -506,15 +506,15 @@ extern "C" {
         start_year = dates[i]->array[j].start_year + (dates[i]->array[j].start_second / kt_remove_time_seconds_in_year_d);
         start_second = dates[i]->array[j].start_second % kt_remove_time_seconds_in_year_d;
 
+        stop_year = dates[i]->array[j].stop_year + (dates[i]->array[j].stop_second / kt_remove_time_seconds_in_year_d);
+        stop_second = dates[i]->array[j].stop_second % kt_remove_time_seconds_in_year_d;
+
         start_is_stop = dates[i]->array[j].start_year == dates[i]->array[j].stop_year && dates[i]->array[j].start_second == dates[i]->array[j].stop_second && dates[i]->array[j].start_nanosecond == dates[i]->array[j].stop_nanosecond;
 
         name_type = f_string_empty_s;
-        result = F_okay;
+        result = F_false;
 
         if (dates[i]->array[j].type == kt_remove_flag_date_today_d || dates[i]->array[j].type == kt_remove_flag_date_tomorrow_d || dates[i]->array[j].type == kt_remove_flag_date_yesterday_d) {
-          stop_year = dates[i]->array[j].stop_year + (dates[i]->array[j].stop_second / kt_remove_time_seconds_in_year_d);
-          stop_second = dates[i]->array[j].stop_second % kt_remove_time_seconds_in_year_d;
-
           if (dates[i]->array[j].operation == kt_remove_flag_date_equal_d) {
             name_type = kt_remove_date_symbol_equal_s;
             result = F_false;
index 6867e363f2f586be0e7d1d7f4b90b8fe01e6dc98..0a60abae7f8a5af7175857bb9aac555fb7e880d7 100644 (file)
@@ -86,7 +86,7 @@ void test__kt_remove__date_changed__now_works(void **state) {
     macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
   };
 
-  const f_time_spec_t time_spec_clocks = macro_f_time_spec_t_initialize_1(2 * 86400, 234);
+  const f_time_spec_t time_spec_clocks = macro_f_time_spec_t_initialize_1(2 * 86400, 345);
 
   bool time_spec_removes[] = {
     F_true, // Equal
@@ -265,7 +265,7 @@ void test__kt_remove__date_changed__tomorrow_works(void **state) {
     F_false,
     F_true, // Not
     F_true,
-    F_true,
+    F_false,
     F_true,
   };