12
12
#include " flang/Runtime/time-intrinsic.h"
13
13
#include < algorithm>
14
14
#include < cctype>
15
- #include < charconv >
15
+ #include < cerrno >
16
16
#include < string>
17
17
18
18
using namespace Fortran ::runtime;
@@ -104,10 +104,9 @@ TEST(TimeIntrinsics, DateAndTime) {
104
104
EXPECT_TRUE (true );
105
105
} else {
106
106
count_t number{-1 };
107
- auto [_, ec]{
108
- std::from_chars (date.data (), date.data () + date.size (), number)};
109
- ASSERT_TRUE (ec != std::errc::invalid_argument &&
110
- ec != std::errc::result_out_of_range);
107
+ // Use stol to allow GCC 7.5 to build tests
108
+ number = std::stol (date);
109
+ ASSERT_TRUE (errno != ERANGE);
111
110
EXPECT_GE (number, 0 );
112
111
auto year = number / 10000 ;
113
112
auto month = (number - year * 10000 ) / 100 ;
@@ -121,14 +120,15 @@ TEST(TimeIntrinsics, DateAndTime) {
121
120
}
122
121
123
122
// Validate time is hhmmss.sss or blank.
123
+ std::string acceptedPattern (" hhmmss.sss" );
124
124
if (isBlank (time)) {
125
125
EXPECT_TRUE (true );
126
126
} else {
127
127
count_t number{-1 };
128
- auto [next, ec]{
129
- std::from_chars (time. data (), time. data () + date. size (), number)} ;
130
- ASSERT_TRUE (ec ! = std::errc::invalid_argument &&
131
- ec != std::errc::result_out_of_range );
128
+ // Use stol to allow GCC 7.5 to build tests
129
+ auto dotPosition = acceptedPattern. find ( ' . ' ) ;
130
+ number = std::stol (time. substr ( 0 , dotPosition));
131
+ ASSERT_TRUE (errno != ERANGE );
132
132
ASSERT_GE (number, 0 );
133
133
auto hours = number / 10000 ;
134
134
auto minutes = (number - hours * 10000 ) / 100 ;
@@ -137,15 +137,11 @@ TEST(TimeIntrinsics, DateAndTime) {
137
137
EXPECT_LE (minutes, 59 );
138
138
// Accept 60 for leap seconds.
139
139
EXPECT_LE (seconds, 60 );
140
- ASSERT_TRUE (next != time.data () + time.size ());
141
- EXPECT_EQ (*next, ' .' );
140
+ EXPECT_EQ (time.substr (dotPosition, 1 ), " ." );
142
141
143
142
count_t milliseconds{-1 };
144
- ASSERT_TRUE (next + 1 != time.data () + time.size ());
145
- auto [_, ec2]{
146
- std::from_chars (next + 1 , time.data () + date.size (), milliseconds)};
147
- ASSERT_TRUE (ec2 != std::errc::invalid_argument &&
148
- ec2 != std::errc::result_out_of_range);
143
+ milliseconds = std::stol (time.substr (dotPosition + 1 , 3 ));
144
+ ASSERT_TRUE (errno != ERANGE);
149
145
EXPECT_GE (milliseconds, 0 );
150
146
EXPECT_LE (milliseconds, 999 );
151
147
}
@@ -157,10 +153,9 @@ TEST(TimeIntrinsics, DateAndTime) {
157
153
ASSERT_TRUE (zone.size () > 1 );
158
154
EXPECT_TRUE (zone[0 ] == ' +' || zone[0 ] == ' -' );
159
155
count_t number{-1 };
160
- auto [next, ec]{
161
- std::from_chars (zone.data () + 1 , zone.data () + zone.size (), number)};
162
- ASSERT_TRUE (ec != std::errc::invalid_argument &&
163
- ec != std::errc::result_out_of_range);
156
+ // Use stol to allow GCC 7.5 to build tests
157
+ number = std::stol (zone.substr (1 , 4 ));
158
+ ASSERT_TRUE (errno != ERANGE);
164
159
ASSERT_GE (number, 0 );
165
160
auto hours = number / 100 ;
166
161
auto minutes = number % 100 ;
0 commit comments