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