Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime auto convert to UTC #124

Open
alexhome82 opened this issue Apr 14, 2018 · 4 comments
Open

DateTime auto convert to UTC #124

alexhome82 opened this issue Apr 14, 2018 · 4 comments

Comments

@alexhome82
Copy link

engine.DefineVariable("myCallObject").Assign(JSValue.Marshal(new MyCallObject));

public class MyCallObject {
    public void SetDateTime(JSValue dt) {
        var t = dt; <-------------------------------------- !!!! Time translates into UTC why?
    }
}
engine.Eval(@"
myCallObject.SetDateTime(new Date());
")

And how do I make the time come the same as in Javascript?

@jsobell
Copy link
Contributor

jsobell commented Apr 16, 2018

In your code you're looking at the JSValue so I'm not sure exactly what you wanted back out at that point. All times in javascript are UTC, but when you convert them to a string or request individual elements (date/hours/minutes) the browser looks at your local timezone and adjusts the output accordingly.
So it depends what you want to do with the output. Do you want it as a .NET DateTime object?

I just ran your code, and I got this:
image

This looks fine to me, as that is the local time here. What were you expecting to see?
There are issues with daylight saving times in the existing code (there's a fixed version I wrote here: https://github.com/questmetrics/NiL.JS/blob/develop/NiL.JS/BaseLibrary/Date.cs ) but I'm not sure if this is related to your problem.

@alexhome82
Copy link
Author

must be 09.04.2018 00:00:00
image

@jsobell
Copy link
Contributor

jsobell commented Apr 16, 2018

Well it says your TimeZoneOffset is zero for some reason. Can you see what TimeZoneInfo.Local.GetUtcOffset(DateTime.Now) gives on your PC?
I'm not sure why you get this, but you can try building my fork locally and see if it has the same issue on your PC.

@Wassili-Hense
Copy link

Приветствую.
Тоже на этот баг напоролся.

    [TestMethod]
    public void DateStringify() {
      var dt  = new DateTime(2018, 05, 15, 10, 05, 02);  // {15.05.2018 10:05:02}
      var dt_j = JSC.JSObject.Marshal(dt);  //  {Tue May 15 2018 10:05:02 GMT+0200 (W. Europe Daylight Time)}
      var json = JSL.JSON.stringify(dt_j);  // "2018-05-15T08:05:02.000Z"
      var j_s = JSL.JSON.parse(json);
      var j_dt = new JSL.Date(new JSC.Arguments() { j_s });  // {Tue May 15 2018 08:05:02 GMT+0200 (W. Europe Daylight Time)}
      var dt_o = j_dt.ToDateTime();  // {15.05.2018 08:05:02}
      Assert.AreEqual(dt, dt_o);  // failed. Expected:<15.05.2018 10:05:02>. Actual:<15.05.2018 08:05:02>.
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants