@@ -121,15 +121,26 @@ TEST(TestTime, TestCastTimestamp) {
121121 " Not a valid time for timestamp value 2000-01-01 00:00:100" );
122122 context.Reset ();
123123
124- EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.0001" , 24 ), 0 );
125- EXPECT_EQ (context.get_error (),
126- " Invalid millis for timestamp value 2000-01-01 00:00:00.0001" );
127- context.Reset ();
128-
129- EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.1000" , 24 ), 0 );
130- EXPECT_EQ (context.get_error (),
131- " Invalid millis for timestamp value 2000-01-01 00:00:00.1000" );
132- context.Reset ();
124+ // Test truncation of subseconds to 3 digits (milliseconds)
125+ // "2000-01-01 00:00:00.0001" should truncate to "2000-01-01 00:00:00.000"
126+ EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.0001" , 24 ),
127+ castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.000" , 23 ));
128+
129+ // "2000-01-01 00:00:00.1000" should truncate to "2000-01-01 00:00:00.100"
130+ EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.1000" , 24 ),
131+ castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.100" , 23 ));
132+
133+ // "2000-01-01 00:00:00.123456789" should truncate to "2000-01-01 00:00:00.123"
134+ EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.123456789" , 29 ),
135+ castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.123" , 23 ));
136+
137+ // "2000-01-01 00:00:00.1999" should truncate to "2000-01-01 00:00:00.199"
138+ EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.1999" , 24 ),
139+ castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.199" , 23 ));
140+
141+ // "2000-01-01 00:00:00.1994" should truncate to "2000-01-01 00:00:00.199"
142+ EXPECT_EQ (castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.1994" , 24 ),
143+ castTIMESTAMP_utf8 (context_ptr, " 2000-01-01 00:00:00.199" , 23 ));
133144}
134145
135146TEST (TestTime, TestCastTimeUtf8) {
@@ -165,13 +176,26 @@ TEST(TestTime, TestCastTimeUtf8) {
165176 EXPECT_EQ (context.get_error (), " Not a valid time value 00:00:100" );
166177 context.Reset ();
167178
168- EXPECT_EQ (castTIME_utf8 (context_ptr, " 00:00:00.0001" , 13 ), 0 );
169- EXPECT_EQ (context.get_error (), " Invalid millis for time value 00:00:00.0001" );
170- context.Reset ();
179+ // Test truncation of subseconds to 3 digits (milliseconds)
180+ // "00:00:00.0001" should truncate to "00:00:00.000"
181+ EXPECT_EQ (castTIME_utf8 (context_ptr, " 00:00:00.0001" , 13 ),
182+ castTIME_utf8 (context_ptr, " 00:00:00.000" , 12 ));
171183
172- EXPECT_EQ (castTIME_utf8 (context_ptr, " 00:00:00.1000" , 13 ), 0 );
173- EXPECT_EQ (context.get_error (), " Invalid millis for time value 00:00:00.1000" );
174- context.Reset ();
184+ // "00:00:00.1000" should truncate to "00:00:00.100"
185+ EXPECT_EQ (castTIME_utf8 (context_ptr, " 00:00:00.1000" , 13 ),
186+ castTIME_utf8 (context_ptr, " 00:00:00.100" , 12 ));
187+
188+ // "9:45:30.123456789" should truncate to "9:45:30.123"
189+ EXPECT_EQ (castTIME_utf8 (context_ptr, " 9:45:30.123456789" , 17 ),
190+ castTIME_utf8 (context_ptr, " 9:45:30.123" , 11 ));
191+
192+ // "00:00:00.1999" should truncate to "00:00:00.199"
193+ EXPECT_EQ (castTIME_utf8 (context_ptr, " 00:00:00.1999" , 13 ),
194+ castTIME_utf8 (context_ptr, " 00:00:00.199" , 12 ));
195+
196+ // "00:00:00.1994" should truncate to "00:00:00.199"
197+ EXPECT_EQ (castTIME_utf8 (context_ptr, " 00:00:00.1994" , 13 ),
198+ castTIME_utf8 (context_ptr, " 00:00:00.199" , 12 ));
175199}
176200
177201#ifndef _WIN32
0 commit comments