Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation failure in date cell #117

Closed
masashi68 opened this issue Dec 1, 2016 · 3 comments
Closed

Calculation failure in date cell #117

masashi68 opened this issue Dec 1, 2016 · 3 comments

Comments

@masashi68
Copy link

Please fix calculation.

The following calculation fails
=IF(A1 = "","A","B")
A1 <- Date cell

I propose the following corrections.

in ClosedXml.Excel.CalcEngine.Expression

	public static implicit operator DateTime(Expression x)
	{
		// evaluate
		var v = x.Evaluate();

		// handle dates
		if (v is DateTime)
		{
			return (DateTime)v;
		}

		// handle doubles
		if (v is double || v is int)
		{
			return DateTime.FromOADate((double)x);
		}

		// !!!!!NEW CODE !!!!!
		if (v is string || (string)v == "")
		{
			return DateTime.MinValue;
		}
		// !!!!!NEW CODE !!!!!

		 // handle everything else
		  CultureInfo _ci = Thread.CurrentThread.CurrentCulture;
		  return (DateTime)Convert.ChangeType(v, typeof(DateTime), _ci);
	}

Thanks!

@masashi68
Copy link
Author

ClosedXmlTest.zip

@igitur
Copy link
Member

igitur commented Dec 2, 2016

Thanks, but your changes break a lot of other tests. I will look into a different solution to the problem.

@masashi68
Copy link
Author

Thanks!
I am looking forward to installing from nget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants