Skip to content

Commit

Permalink
Improve date parsing by utilizing MimeKit logic (#1434)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Feb 16, 2023
1 parent 12bc40e commit 83206f4
Show file tree
Hide file tree
Showing 4 changed files with 1,116 additions and 200 deletions.
8 changes: 8 additions & 0 deletions CREDITS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ Jint number serialization is based on the Java port of the FastDtoa algorithm fr
Website: http://mozilla.org/
Copyright: Copyright (c) Mozilla
License: MPL 2.0 - http://mozilla.org/MPL/2.0/

MimeKit
-----
Jint date parsing utilizes code extracted from the excellent MimeKit library.

Website: https://github.com/jstedfast/MimeKit
Copyright: Copyright (C) 2012-2022 .NET Foundation and Contributors
License: MIT - https://github.com/jstedfast/MimeKit/blob/master/LICENSE
14 changes: 14 additions & 0 deletions Jint.Tests/Runtime/DateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,18 @@ public void ToStringFollowsJavaScriptFormat()
Assert.Equal("Tue Feb 01 2022 00:00:00 GMT+0800 (China Standard Time)", engine.Evaluate("new Date(2022,1,1).toString()"));
Assert.Equal("Tue Feb 01 2022 00:00:00 GMT+0800 (China Standard Time)", engine.Evaluate("new Date(2022,1,1)").ToString());
}

[Theory]
[InlineData("Thu, 30 Jan 2020 08:00:00 PST", 1580400000000)]
[InlineData("Thursday January 01 1970 00:00:25 UTC", 25000)]
[InlineData("Wednesday 31 December 1969 18:01:26 MDT", 86000)]
[InlineData("Wednesday 31 December 1969 19:00:08 EST", 8000)]
[InlineData("Wednesday 31 December 1969 17:01:59 PDT", 119000)]
[InlineData("December 31 1969 17:01:14 MST", 74000)]
[InlineData("January 01 1970 01:46:06 +0145", 66000)]
[InlineData("December 31 1969 17:00:50 PDT", 50000)]
public void CanParseLocaleString(string input, long expected)
{
Assert.Equal(expected, _engine.Evaluate($"new Date('{input}') * 1").AsNumber());
}
}

0 comments on commit 83206f4

Please sign in to comment.