sebastienros / jint

Javascript Interpreter for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing and returning DateTimeOffset to Engine

denisbredikhin opened this issue · comments

Hello,

In our application, end-users can write scripts in one of the two languages: JS and C#. For JS, we are using Jint, and for C#, we use Roslyn.
We want to achieve that the results of the execution are consistent, doesn't matter which language is used.

Quite often, as a parameter of the script, we pass the DateTimeOffset value. This gives a problem because if we somehow process the DateTimeOffset input in the C# script, we get back DateTimeOffset, while if we do this with Jint, we get back DateTime.

I've written a small unit test (added to InteropTests), which should pass to be able to achieve what we want:

[Fact]
public void DateTimeOffsetIsConvertedToDateOffset()
{
    var o = new DateTimeOffset(1970, 1, 1, 0, 0, 0, new TimeSpan());
    _engine.SetValue("o", o);
    var result = _engine.Evaluate("o").ToObject();
    Assert.Equal(o, result);
}

Can you please tell me if this is something that can be added to Jint? Maybe it is already possible with some flags or with the import of some JavaScript libraries?