Skip to content

Commit

Permalink
Do not convert DateAndTime to DateTime
Browse files Browse the repository at this point in the history
Closes icsharpcode#261

# Conflicts:
#	Tests/CSharp/ExpressionTests.cs
  • Loading branch information
mrmonday authored and GrahamTheCoder committed Apr 19, 2019
1 parent 3f19f62 commit 5886011
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ICSharpCode.CodeConverter/Util/ISymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace ICSharpCode.CodeConverter.Util
#endif
static class ISymbolExtensions
{
private static readonly string[] TypesToConvertToDateTime = new[] {"DateTime", "DateAndTime" };
// A lot of symbols in DateAndTime do not exist in DateTime, eg. DateSerial(),
// and some have different names/arguments, eg. DateAdd(). This needs to be handled properly
// as part of #174
private static readonly string[] TypesToConvertToDateTime = new[] { "DateTime" };

/// <summary>
/// Checks if 'symbol' is accessible from within 'within'.
Expand Down
18 changes: 18 additions & 0 deletions Tests/CSharp/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,24 @@ public string StringInter(string t, DateTime dt)
}");
}

[Fact]
public void DateTimeToDateAndTime()
{
TestConversionVisualBasicToCSharpWithoutComments(@"Public Class Class1
Sub Foo()
Dim x = DateAdd(""m"", 5, Now)
End Sub
End Class", @"using Microsoft.VisualBasic;
public class Class1
{
public void Foo()
{
var x = DateAndTime.DateAdd(""m"", 5, DateAndTime.Now);
}
}");
}

[Fact]
public void BaseFinalizeRemoved()
{
Expand Down
3 changes: 2 additions & 1 deletion Tests/CSharp/StatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,14 +1346,15 @@ Private Function IsSqlAlive() As Boolean
Return True
End Function
End Class", @"using System;
using Microsoft.VisualBasic;
public class TestClass2
{
public bool CanDoWork(object Something)
{
switch (true)
{
case object _ when DateTime.Today.DayOfWeek == DayOfWeek.Saturday | DateTime.Today.DayOfWeek == DayOfWeek.Sunday:
case object _ when DateAndTime.Today.DayOfWeek == DayOfWeek.Saturday | DateAndTime.Today.DayOfWeek == DayOfWeek.Sunday:
{
// we do not work on weekends
return false;
Expand Down

0 comments on commit 5886011

Please sign in to comment.