Allow to set a custom TimeZoneInfo on the ScriptEngine, and avoid DateTime.MinValue as invalid date #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
it would be cool if Jurassic's
ScriptEngine
allows to set a customTimeZoneInfo
used to convert between UTC and local time. This is useful for example if you run user-defined scripts on a server, but each script should run with the user's timezone (Jint also allows to set the engine's timezone).While setting the current
CultureInfo
(for number-formatting etc.) can be done on the current thread (so this works without modifying theScriptEngine
), there is not thread-specific timezone setting, so this would need to be done on theScriptEngine
level.This PR creates a new property
ScriptEngine.LocalTimeZone
where a custom timezone can be set, which is then used by theDateInstance
. The default value isTimeZoneInfo.Local
.The DateInstance's internal DateTime value is now also always UTC, whereas previously it sometimes was local time and sometimes was UTC.
Update: Additionally, this PR also avoids using
DateTime.MinValue
to represent an invalid date. Generally, such uses of data types should be avoided because this can lead to problems where such a value is actually expected to be used.For example, we use Jurassic in a product where users can call .NET APIs, and one of them expects a
DateTime
range. In order to specify the full range, one would need to specifyDateTime.MinValue
andDateTime.MaxValue
(in JS:new Date(-62135596800000)
andnew Date(253402300799999)
(although the latter is actually a bit lower because it doesn't include the nanoSeconds). Therefore, I think Jurassic should allow to useDateTime.MinValue
as valid date.Thanks!