Skip to content

Commit 4646c49

Browse files
committed
Revert the en-US locale and add additional localized tests around US-formatted dates as string in different locales to document the behavior of changing from strings to dates using US formatting.
1 parent a3a642c commit 4646c49

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

RubberduckTests/VBEditor/Variants/VariantConverterTests.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ public object Test_ObjectConversion_SimpleValues(object value, Type targetType)
206206
return result;
207207
}
208208

209+
/// <remarks>
210+
/// This assumes en-US locale.
211+
/// See <see cref="Test_US_format_String_To_Date_Localized"/> for localization behavior
212+
/// </remarks>
209213
[Test]
210214
[TestCase(true, typeof(DateTime), ExpectedResult = "1899-12-29 00:00:00")]
211215
[TestCase(false, typeof(DateTime), ExpectedResult = "1899-12-30 00:00:00")]
@@ -216,6 +220,7 @@ public object Test_ObjectConversion_SimpleValues(object value, Type targetType)
216220
[TestCase("04/12/2000", typeof(DateTime), ExpectedResult = "2000-04-12 00:00:00")]
217221
[TestCase("12/04/2000", typeof(DateTime), ExpectedResult = "2000-12-04 00:00:00")]
218222
[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")]
219224
[TestCase(1.0, typeof(DateTime), ExpectedResult = "1899-12-31 00:00:00")]
220225
[TestCase(0.0, typeof(DateTime), ExpectedResult = "1899-12-30 00:00:00")]
221226
[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)
232237
[TestCase(-0.5d, typeof(DateTime), ExpectedResult = "1899-12-30 12:00:00")]
233238
public string Test_ObjectConversion_SimpleValues_To_Date(object value, Type targetType)
234239
{
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);
236270
if (result is DateTime dt)
237271
{
238272
return dt.ToString(TheOneTrueDateFormat);

0 commit comments

Comments
 (0)