Skip to content

Commit

Permalink
Ensure DateTime.MinValue can be passed via interop (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Feb 19, 2023
1 parent fedd680 commit 4eb7fc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Jint.Tests/Runtime/InteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3140,5 +3140,20 @@ public void CanConstructOptionalRecordClass()
Assert.Equal(null, _engine.Evaluate("Context.method({});").ToObject());
Assert.Equal(5, _engine.Evaluate("Context.method({ value: 5 });").AsInteger());
}

[Fact]
public void CanPassDateTimeMinViaInterop()
{
var engine = new Engine(cfg => cfg.AllowClrWrite());

var dt = DateTime.UtcNow;
engine.SetValue("capture", new Action<object>(o => dt = (DateTime) o));
engine.SetValue("minDate", DateTime.MinValue);

engine.Execute("capture(minDate);");
Assert.Equal(DateTime.MinValue, dt);

// DateTime.MaxValue cannot be handled due to internal presentation that would require tick precision
}
}
}
2 changes: 1 addition & 1 deletion Jint/Native/Date/DateConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static long FromDateTimeOffset(DateTimeOffset dt, bool negative = false)

internal long FromDateTime(DateTime dt, bool negative = false)
{
var convertToUtcAfter = dt.Kind == DateTimeKind.Unspecified;
var convertToUtcAfter = dt.Kind == DateTimeKind.Unspecified && dt != DateTime.MinValue;

var dateAsUtc = dt.Kind == DateTimeKind.Local
? dt.ToUniversalTime()
Expand Down

0 comments on commit 4eb7fc5

Please sign in to comment.