From ffbb2c201a8ce9c5a936d2032b361720e567f809 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 23 Mar 2025 17:54:06 -0500 Subject: [PATCH] Progress: Continue working on completing the remove program. 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. --- .../c/program/kevux/tools/remove/main/convert.c | 43 ++++++++++------------ .../c/program/kevux/tools/remove/main/preprocess.c | 10 ++--- tests/unit/remove/c/test-remove-date_changed.c | 4 +- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/sources/c/program/kevux/tools/remove/main/convert.c b/sources/c/program/kevux/tools/remove/main/convert.c index 36c8e15..b8856d8 100644 --- a/sources/c/program/kevux/tools/remove/main/convert.c +++ b/sources/c/program/kevux/tools/remove/main/convert.c @@ -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; diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.c b/sources/c/program/kevux/tools/remove/main/preprocess.c index 6b0b325..35ec594 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.c +++ b/sources/c/program/kevux/tools/remove/main/preprocess.c @@ -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; diff --git a/tests/unit/remove/c/test-remove-date_changed.c b/tests/unit/remove/c/test-remove-date_changed.c index 6867e36..0a60aba 100644 --- a/tests/unit/remove/c/test-remove-date_changed.c +++ b/tests/unit/remove/c/test-remove-date_changed.c @@ -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, }; -- 1.8.3.1