|
16 | 16 | #include "test_config.h" |
17 | 17 | #include "ace/ACE.h" |
18 | 18 | #include "ace/Time_Value.h" |
| 19 | +#include "ace/Date_Time.h" |
19 | 20 | #include "ace/Numeric_Limits.h" |
20 | 21 | #include <sstream> |
21 | 22 | #include <type_traits> |
@@ -52,6 +53,38 @@ int timeval_test_func (const ACE_Time_Value* timeout) |
52 | 53 | return ret; |
53 | 54 | } |
54 | 55 |
|
| 56 | +// Test whether ACE_Time_Value is stored correctly for the specified year month |
| 57 | +int test_year_month (const ACE_Time_Value& time, long year, long month) |
| 58 | +{ |
| 59 | + int ret = 0; |
| 60 | + |
| 61 | + ACE_Date_Time dt (time); |
| 62 | + if (dt.year () != year) |
| 63 | + { |
| 64 | + ACE_ERROR ((LM_ERROR, |
| 65 | + ACE_TEXT ("time year should be %d not %d\n"), dt.year (), year)); |
| 66 | + ++ret; |
| 67 | + } |
| 68 | + else |
| 69 | + { |
| 70 | + ACE_DEBUG ((LM_DEBUG, |
| 71 | + ACE_TEXT ("time year is correct, it is %d\n"), dt.year ())); |
| 72 | + } |
| 73 | + if (dt.month () != month) |
| 74 | + { |
| 75 | + ACE_ERROR ((LM_ERROR, |
| 76 | + ACE_TEXT ("time month should be %d not %d\n"), dt.month (), month)); |
| 77 | + ++ret; |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + ACE_DEBUG ((LM_DEBUG, |
| 82 | + ACE_TEXT ("time month is correct, it is %d\n"), dt.month ())); |
| 83 | + } |
| 84 | + |
| 85 | + return ret; |
| 86 | +} |
| 87 | + |
55 | 88 | int |
56 | 89 | run_main (int, ACE_TCHAR *[]) |
57 | 90 | { |
@@ -261,6 +294,14 @@ run_main (int, ACE_TCHAR *[]) |
261 | 294 |
|
262 | 295 | ret += timeval_test_func ((ACE_Time_Value *) &ACE_Time_Value::zero); |
263 | 296 |
|
| 297 | + // Test whether some times in the past and the future are correctly converted to year/month, no need to check |
| 298 | + // day/time as that could be challenging due to timezones. |
| 299 | + ACE_Time_Value dt20250726 ((time_t)1753519444); |
| 300 | + ret += test_year_month (dt20250726, 2025, 7); |
| 301 | + ACE_Time_Value dt20370726 ((time_t)2132203444); |
| 302 | + ret += test_year_month (dt20370726, 2037, 7); |
| 303 | + ACE_Time_Value dt20570726 ((time_t)2763355444); |
| 304 | + ret += test_year_month (dt20570726, 2057, 7); |
264 | 305 | ACE_END_TEST; |
265 | 306 |
|
266 | 307 | return ret; |
|
0 commit comments