Allow to set a custom TimeZoneInfo on the ScriptEngine, and avoid DateTime.MinValue as invalid date#69
Open
kpreisser wants to merge 9 commits intopaulbartrum:masterfrom
Open
Allow to set a custom TimeZoneInfo on the ScriptEngine, and avoid DateTime.MinValue as invalid date#69kpreisser wants to merge 9 commits intopaulbartrum:masterfrom
kpreisser wants to merge 9 commits intopaulbartrum:masterfrom
Conversation
…hat is a valid .NET DateTime and can lead to errors when calling .NET APIs.
… valid when the year is set. This is also the behavior in other JS engines.
Collaborator
Author
|
Hi @paulbartrum, I rebased the PR on the current Additionally, I removed the usage of Instead, I'm using Can you review the PR? |
…Instance.ToString() method.
Conflicts:
Jurassic/Library/Date/DateParser.cs
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ScriptEngineallows to set a customTimeZoneInfoused 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 theScriptEnginelevel.This PR creates a new property
ScriptEngine.LocalTimeZonewhere 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.MinValueto 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
DateTimerange. In order to specify the full range, one would need to specifyDateTime.MinValueandDateTime.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.MinValueas valid date.Thanks!