-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaScript usually does not care a lot about timezones, but since the conversion happens via milliseconds since epoch (which is UTC based) one needs to be a bit careful about which conversions to do where. Added/moved tests to a central place so there is an overview over all date related tests.
- Loading branch information
1 parent
16791dc
commit d3713b0
Showing
6 changed files
with
82 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using FluentAssertions; | ||
|
||
namespace Noesis.Javascript.Tests | ||
{ | ||
[TestClass] | ||
public class DateTest | ||
{ | ||
private JavascriptContext _context; | ||
|
||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
_context = new JavascriptContext(); | ||
} | ||
|
||
[TestCleanup] | ||
public void TearDown() | ||
{ | ||
_context.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public void SetDateTime() | ||
{ | ||
_context.SetParameter("val", new DateTime(2010, 10, 10, 0, 0, 0, DateTimeKind.Utc)); | ||
|
||
_context.Run("val.getUTCFullYear()").Should().BeOfType<int>().Which.Should().Be(2010); | ||
_context.Run("val.getUTCMonth()").Should().BeOfType<int>().Which.Should().Be(9); | ||
_context.Run("val.getUTCDate()").Should().BeOfType<int>().Which.Should().Be(10); | ||
} | ||
|
||
[TestMethod] | ||
public void SetAndReadDateTimeUtc() | ||
{ | ||
var dateTime = new DateTime(2010, 10, 10, 0, 0, 0, DateTimeKind.Utc); | ||
_context.SetParameter("val", dateTime); | ||
|
||
var dateFromV8 = (DateTime) _context.Run("val"); | ||
dateFromV8.ToUniversalTime().Should().Be(dateTime); | ||
} | ||
|
||
[TestMethod] | ||
public void SetAndReadDateTimeLocal() | ||
{ | ||
var dateTime = new DateTime(2010, 10, 10, 0, 0, 0, DateTimeKind.Local); | ||
_context.SetParameter("val", dateTime); | ||
|
||
_context.Run("val").Should().Be(dateTime); | ||
} | ||
|
||
[TestMethod] | ||
public void SetAndReadDateTimeUnspecified() | ||
{ | ||
var dateTime = new DateTime(2010, 10, 10); | ||
_context.SetParameter("val", dateTime); | ||
|
||
_context.Run("val").Should().Be(dateTime); | ||
} | ||
|
||
[TestMethod] | ||
public void CreateCurrentDateInJavaScript() | ||
{ | ||
DateTime currentTimeAsReportedByV8 = (DateTime)_context.Run("new Date()"); | ||
(currentTimeAsReportedByV8 - DateTime.Now).TotalSeconds.Should().BeLessThan(1, "Dates should be mostly equal"); | ||
} | ||
|
||
[TestMethod] | ||
public void CreateFixedDateInJavaScript() | ||
{ | ||
DateTime dateAsReportedByV8 = (DateTime)_context.Run("new Date(2010, 9, 10)"); | ||
dateAsReportedByV8.Should().Be(new DateTime(2010, 10, 10)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters