Skip to content

Commit c716ddd

Browse files
committed
Merge branch 'jwi-timevaluebcc64x2' of https://github.com/jwillemsen/ATCD into jwi-timevaluebcc64x2
2 parents 520d39e + 7130cea commit c716ddd

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

ACE/tests/Time_Value_Test.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "test_config.h"
1717
#include "ace/ACE.h"
1818
#include "ace/Time_Value.h"
19+
#include "ace/Date_Time.h"
1920
#include "ace/Numeric_Limits.h"
2021
#include <sstream>
2122
#include <type_traits>
@@ -52,6 +53,38 @@ int timeval_test_func (const ACE_Time_Value* timeout)
5253
return ret;
5354
}
5455

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+
5588
int
5689
run_main (int, ACE_TCHAR *[])
5790
{
@@ -261,6 +294,14 @@ run_main (int, ACE_TCHAR *[])
261294

262295
ret += timeval_test_func ((ACE_Time_Value *) &ACE_Time_Value::zero);
263296

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);
264305
ACE_END_TEST;
265306

266307
return ret;

0 commit comments

Comments
 (0)