@@ -206,6 +206,10 @@ public object Test_ObjectConversion_SimpleValues(object value, Type targetType)
206
206
return result ;
207
207
}
208
208
209
+ /// <remarks>
210
+ /// This assumes en-US locale.
211
+ /// See <see cref="Test_US_format_String_To_Date_Localized"/> for localization behavior
212
+ /// </remarks>
209
213
[ Test ]
210
214
[ TestCase ( true , typeof ( DateTime ) , ExpectedResult = "1899-12-29 00:00:00" ) ]
211
215
[ TestCase ( false , typeof ( DateTime ) , ExpectedResult = "1899-12-30 00:00:00" ) ]
@@ -216,6 +220,7 @@ public object Test_ObjectConversion_SimpleValues(object value, Type targetType)
216
220
[ TestCase ( "04/12/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-12 00:00:00" ) ]
217
221
[ TestCase ( "12/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-12-04 00:00:00" ) ]
218
222
[ TestCase ( "13/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
223
+ [ TestCase ( "04/13/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
219
224
[ TestCase ( 1.0 , typeof ( DateTime ) , ExpectedResult = "1899-12-31 00:00:00" ) ]
220
225
[ TestCase ( 0.0 , typeof ( DateTime ) , ExpectedResult = "1899-12-30 00:00:00" ) ]
221
226
[ TestCase ( - 0.0 , typeof ( DateTime ) , ExpectedResult = "1899-12-30 00:00:00" ) ]
@@ -232,7 +237,36 @@ public object Test_ObjectConversion_SimpleValues(object value, Type targetType)
232
237
[ TestCase ( - 0.5d , typeof ( DateTime ) , ExpectedResult = "1899-12-30 12:00:00" ) ]
233
238
public string Test_ObjectConversion_SimpleValues_To_Date ( object value , Type targetType )
234
239
{
235
- var result = VariantConverter . ChangeType ( value , targetType ) ;
240
+ var culture = new CultureInfo ( "en-US" ) ;
241
+ var result = VariantConverter . ChangeType ( value , targetType , culture ) ;
242
+ if ( result is DateTime dt )
243
+ {
244
+ return dt . ToString ( TheOneTrueDateFormat ) ;
245
+ }
246
+
247
+ // Invalid result
248
+ return string . Empty ;
249
+ }
250
+
251
+ /// <remarks>
252
+ /// Note that de-DE results differ from fr-CA and en-US
253
+ /// </remarks>
254
+ [ TestCase ( "fr-CA" , "04/12/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-12 00:00:00" ) ]
255
+ [ TestCase ( "fr-CA" , "12/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-12-04 00:00:00" ) ]
256
+ [ TestCase ( "fr-CA" , "13/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
257
+ [ TestCase ( "fr-CA" , "04/13/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
258
+ [ TestCase ( "de-DE" , "04/12/2000" , typeof ( DateTime ) , ExpectedResult = "2000-12-04 00:00:00" ) ]
259
+ [ TestCase ( "de-DE" , "12/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-12 00:00:00" ) ]
260
+ [ TestCase ( "de-DE" , "13/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
261
+ [ TestCase ( "de-DE" , "04/13/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
262
+ [ TestCase ( "en-US" , "04/12/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-12 00:00:00" ) ]
263
+ [ TestCase ( "en-US" , "12/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-12-04 00:00:00" ) ]
264
+ [ TestCase ( "en-US" , "13/04/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
265
+ [ TestCase ( "en-US" , "04/13/2000" , typeof ( DateTime ) , ExpectedResult = "2000-04-13 00:00:00" ) ]
266
+ public string Test_US_format_String_To_Date_Localized ( string locale , object value , Type targetType )
267
+ {
268
+ var culture = new CultureInfo ( locale ) ;
269
+ var result = VariantConverter . ChangeType ( value , targetType , culture ) ;
236
270
if ( result is DateTime dt )
237
271
{
238
272
return dt . ToString ( TheOneTrueDateFormat ) ;
0 commit comments