From 4a6babf9d6936bf694a936c5e9bda7e904eca05c Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Sat, 26 Jul 2025 10:49:48 +0200 Subject: [PATCH 1/2] Test whether time_t is correctly converted to year/month, also with dates after 2038 which requires a 64bit time_t * ACE/tests/Time_Value_Test.cpp: --- ACE/tests/Time_Value_Test.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ACE/tests/Time_Value_Test.cpp b/ACE/tests/Time_Value_Test.cpp index 61aee96f8f0ce..3a20f01267d08 100644 --- a/ACE/tests/Time_Value_Test.cpp +++ b/ACE/tests/Time_Value_Test.cpp @@ -16,6 +16,7 @@ #include "test_config.h" #include "ace/ACE.h" #include "ace/Time_Value.h" +#include "ace/Date_Time.h" #include "ace/Numeric_Limits.h" #include #include @@ -52,6 +53,38 @@ int timeval_test_func (const ACE_Time_Value* timeout) return ret; } +// Test whether ACE_Time_Value is stored correctly for the specified year month +int test_year_month (const ACE_Time_Value& time, long year, long month) +{ + int ret = 0; + + ACE_Date_Time dt (time); + if (dt.year () != year) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("time year should be %d not %d\n"), year, dt.year ())); + ++ret; + } + else + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("time year is correct, it is %d\n"), dt.year ())); + } + if (dt.month () != month) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("time month should be %d not %d\n"), month, dt.month ())); + ++ret; + } + else + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("time month is correct, it is %d\n"), dt.month ())); + } + + return ret; +} + int run_main (int, ACE_TCHAR *[]) { @@ -261,6 +294,14 @@ run_main (int, ACE_TCHAR *[]) ret += timeval_test_func ((ACE_Time_Value *) &ACE_Time_Value::zero); + // Test whether some times in the past and the future are correctly converted to year/month, no need to check + // day/time as that could be challenging due to timezones. + ACE_Time_Value dt20250726 ((time_t)1753519444); + ret += test_year_month (dt20250726, 2025, 7); + ACE_Time_Value dt20370726 ((time_t)2132203444); + ret += test_year_month (dt20370726, 2037, 7); + ACE_Time_Value dt20570726 ((time_t)2763355444); + ret += test_year_month (dt20570726, 2050, 7); ACE_END_TEST; return ret; From ed9030438e89bf72d69a17e3d9de1366034e6a0f Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Sat, 26 Jul 2025 11:02:49 +0200 Subject: [PATCH 2/2] Correct test * ACE/tests/Time_Value_Test.cpp: --- ACE/tests/Time_Value_Test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ACE/tests/Time_Value_Test.cpp b/ACE/tests/Time_Value_Test.cpp index 3a20f01267d08..66b16f0428be9 100644 --- a/ACE/tests/Time_Value_Test.cpp +++ b/ACE/tests/Time_Value_Test.cpp @@ -62,7 +62,7 @@ int test_year_month (const ACE_Time_Value& time, long year, long month) if (dt.year () != year) { ACE_ERROR ((LM_ERROR, - ACE_TEXT ("time year should be %d not %d\n"), year, dt.year ())); + ACE_TEXT ("time year should be %d not %d\n"), dt.year (), year)); ++ret; } else @@ -73,7 +73,7 @@ int test_year_month (const ACE_Time_Value& time, long year, long month) if (dt.month () != month) { ACE_ERROR ((LM_ERROR, - ACE_TEXT ("time month should be %d not %d\n"), month, dt.month ())); + ACE_TEXT ("time month should be %d not %d\n"), dt.month (), month)); ++ret; } else @@ -301,7 +301,7 @@ run_main (int, ACE_TCHAR *[]) ACE_Time_Value dt20370726 ((time_t)2132203444); ret += test_year_month (dt20370726, 2037, 7); ACE_Time_Value dt20570726 ((time_t)2763355444); - ret += test_year_month (dt20570726, 2050, 7); + ret += test_year_month (dt20570726, 2057, 7); ACE_END_TEST; return ret;