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

The getDate() method returns 0 for December 31st before 1970. #1746

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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