Skip to content

Commit

Permalink
Update GetUtcNow to return DateTimeOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Dec 12, 2023
1 parent 1e0513e commit 2aab2c8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="Jurassic" Version="3.2.7" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.116" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="MongoDB.Bson.signed" Version="2.19.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="MongoDB.Bson.signed" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NodaTime" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Jint.Tests.PublicInterface/TimeSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public TimeProviderTimeSystem(TimeProvider timeProvider) : base(TimeZoneInfo.Utc
_timeProvider = timeProvider;
}

public override DateTime GetUtcNow()
public override DateTimeOffset GetUtcNow()
{
return _timeProvider.GetUtcNow().DateTime;
return _timeProvider.GetUtcNow();
}
}
4 changes: 2 additions & 2 deletions Jint/Native/Date/DateConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static JsValue Utc(JsValue thisObject, JsValue[] arguments)

private JsValue Now(JsValue thisObject, JsValue[] arguments)
{
return (long) (_timeSystem.GetUtcNow() - Epoch).TotalMilliseconds;
return (long) (_timeSystem.GetUtcNow().DateTime - Epoch).TotalMilliseconds;
}

protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
Expand All @@ -120,7 +120,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
newTarget,
static intrinsics => intrinsics.Date.PrototypeObject,
static (engine, _, dateValue) => new JsDate(engine, dateValue),
(_timeSystem.GetUtcNow() - Epoch).TotalMilliseconds);
(_timeSystem.GetUtcNow().DateTime - Epoch).TotalMilliseconds);
}

return ConstructUnlikely(arguments, newTarget);
Expand Down
4 changes: 2 additions & 2 deletions Jint/Runtime/DefaultTimeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public DefaultTimeSystem(TimeZoneInfo timeZoneInfo, CultureInfo parsingCulture)
DefaultTimeZone = timeZoneInfo;
}

public virtual DateTime GetUtcNow()
public virtual DateTimeOffset GetUtcNow()
{
return DateTime.UtcNow;
return DateTimeOffset.UtcNow;
}

public TimeZoneInfo DefaultTimeZone { get; }
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/ITimeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ITimeSystem
/// Retrieves current UTC time.
/// </summary>
/// <returns>Current UTC time.</returns>
DateTime GetUtcNow();
DateTimeOffset GetUtcNow();

/// <summary>
/// Return the default time zone system is using. Usually <see cref="TimeZoneInfo.Local"/>, but can be altered via
Expand Down

0 comments on commit 2aab2c8

Please sign in to comment.