Announcement

Collapse
No announcement yet.

[CLOSED] [#869] [1.12] Subtracting DateTimes does not handle DST in the same manner as .NET

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#869] [1.12] Subtracting DateTimes does not handle DST in the same manner as .NET

    If you subtract two dates that span a DST boundary the resulting timespan does not match the result from .NET. For example the following code will generate 164.95833333333334 from the generated javascript, but 165 when running in .NET.

    using System;
    using Bridge.Html5;
    
    namespace BridgeTest1._10._4
    {
        public class App
        {
    
            [Ready]
            public static void Main()
            {
                var edtDate = new DateTime(2014, 6, 20);
                var estDate = new DateTime(2014, 1, 6);
    
                var test = (edtDate - estDate).TotalDays;
                Global.Alert(test.ToString());
            }
        }
    }

    #2
    Sorry but I cannot reproduce it (i see 165 in alert window)
    http://live.bridge.net/#695f08749373229fab41

    Which browser do you use?

    Comment


      #3
      Mac OS, Firefox (latest)

      Same result in Max OS, Chrome (latest)

      Click image for larger version

Name:	Screenshot 2016-01-25 16.36.06.png
Views:	1
Size:	74.9 KB
ID:	1463

      Comment


        #4
        That is strange, may be it is related with different time zones
        What you see for such sample?
        http://live.bridge.net/#919973c17067994f4a6a

        Comment


          #5
          Second test:

          Click image for larger version

Name:	Screenshot 2016-01-25 16.44.58.png
Views:	1
Size:	69.9 KB
ID:	1466

          Comment


            #6
            Hmm, I have another number in all browsers.
            If I run this script in console var edtDate = new Date(2014, 5, 20); var estDate = new Date(2014, 0, 6); edtDate - estDate then i see 14256000000
            The same number if i try Date.UTC(2014, 5, 20) - Date.UTC(2014, 0, 6)
            Last edited by geoffrey.mcgill; 2016-02-01 @ 06:26 PM.

            Comment


              #7
              Initially I could not reproduce, but then I played with a time zone setting in Windows and got it reproducible. I tried a few time zones and it appears to be always reproducible with time zones with DST and it is not reproducible without DST.

              Comment


                #8
                Yes this is definitely a DST issue, I'm in the eastern standard timezone which is why I'm seeing it for the dates provided in the test.

                Comment


                  #9
                  Vladimir, do you think there is a possibility we can do something?

                  Comment


                    #10
                    One of our devs had suggested modifying DateTime.cs like below to take into account the timezone offsets:

                            [Template("new Bridge.TimeSpan((({a} - {b}) + Math.abs(({a}.getTimezoneOffset() - {b}.getTimezoneOffset()) * 60000)) * 10000)")]
                            public static TimeSpan operator -(DateTime a, DateTime b)
                            {
                                return default(TimeSpan);
                            }
                    
                            [Template("new Bridge.TimeSpan((({this} - {value}) + Math.abs(({this}.getTimezoneOffset() - {value}.getTimezoneOffset()) * 60000)) * 10000)")]
                            public TimeSpan Subtract(DateTime value)
                            {
                                return default(TimeSpan);
                            }

                    Comment


                      #11
                      Need to fix DateTime operator - (not TimeSpan only)
                      We will introduce the following js method for DateTime
                      dateDiff: function (a, b) {
                                  var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate(), a.getHours(), a.getMinutes(), a.getSeconds(), a.getMilliseconds());
                                  var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate(), b.getHours(), b.getMinutes(), b.getSeconds(), b.getMilliseconds());
                      
                                  return utc1 - utc2;
                              },
                      but thank you for your suggestion

                      Comment


                        #12
                        A dedicated GitHub issue:
                        https://github.com/bridgedotnet/Bridge/issues/869

                        Comment


                          #13
                          It seems both solutions don't work in IE (IE11 for me)

                          Comment


                            #14
                            We currently cannot find a cross-browser solution. Everybody is welcome with possible solutions.

                            Comment


                              #15
                              Hey Vladimir, what tests are not working in IE11 for you?

                              We've tested your proposed solution of adding the dateDiff function and using for date time subtraction and it appears to work as expected (at least in our scenario) for Chrome, FireFox, and IE11.

                              Comment

                              Working...
                              X