Skip to content

Commit

Permalink
The getDate() method returns 0 for December 31st before 1970 (#1746)
Browse files Browse the repository at this point in the history
Co-authored-by: Pisotskyi Pavel <[email protected]>
  • Loading branch information
2 people authored and lahma committed Jan 19, 2024
1 parent 2220592 commit 831150e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Jint.Tests/Runtime/DateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ public void CanParseLocaleString(string input, long expected)
Assert.Equal(expected, _engine.Evaluate($"new Date('{input}') * 1").AsNumber());
}

[Theory]
[InlineData("December 31 1900 12:00:00 +0300", 31)]
[InlineData("January 1 1969 12:00:00 +0300", 1)]
[InlineData("December 31 1969 12:00:00 +0300", 31)]
[InlineData("January 1 1970 12:00:00 +0300", 1)]
[InlineData("December 31 1970 12:00:00 +0300", 31)]
public void CanParseDate(string input, int expectedDate)
{
TimeZoneInfo timeZoneInfo;
try
{
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Europe/Kiev");
}
catch
{
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time");
}
var engine = new Engine(options => options.LocalTimeZone(timeZoneInfo));
Assert.Equal(expectedDate, _engine.Evaluate($"new Date('{input}').getDate()").AsNumber());
}

[Fact]
public void CanUseMoment()
{
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Date/DatePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ private static bool AreFinite(double value1, double value2, double value3, doubl

private static readonly int[] kDaysInMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

private static Date YearMonthDayFromTime(DatePresentation t) => YearMonthDayFromDays(t.Value / 1000 / 60 / 60 / 24);
private static Date YearMonthDayFromTime(DatePresentation t) => YearMonthDayFromDays((long) System.Math.Floor(t.Value / 1000 / 60 / 60 / 24d));

private static Date YearMonthDayFromDays(long days)
{
Expand Down

0 comments on commit 831150e

Please sign in to comment.