Announcement

Collapse
No announcement yet.

[CLOSED] [#3098] [16.3] DateTime Comparison and UTC

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

  • [CLOSED] [#3098] [16.3] DateTime Comparison and UTC

    Hi, I'm wondering if the following behavior is expected or not. Please see the following Deck.net sample:
    https://dev.deck.net/05a60bb4f5ba5d3a101c411dd0d8b691

    In the Deck sample, the console output at the end is "Equal". If I were to create a standard .NET console application with the same code, the last output would be "Not equal". The console application behavior is what I would typically expect.

    If this is the expected behavior, what would be the correct way to handle it? We have code shared between desktop and web applications, so we'd like the behavior to be consistent between both?

  • #2
    Hey if you need a work around i can suggest this.

    // Putting this in will solve that issue.
    if(now == utcNow && now.Kind == utcNow.Kind)
    {
    
    }

    Comment


    • #3
      Also you are looking at the ToString() value on the console. so essentially this is what you would need.

      now.ToString() == utcNow.ToString()

      Comment


      • #4
        Also https://dotnetfiddle.net/Z5zBqD shows as those values being equal (never mind i think that there kind for local is UTC haha)
        Last edited by samuelgrahame; 2017-08-30 @ 12:00 AM. Reason: sorry

        Comment


        • #5
          It appears the check is not comparing the Ticks value properly.

          You can work around the defect by comparing .Ticks of each DateTime object.

          if(now.Ticks == utcNow.Ticks)
          {
          
          }
          We will create an Issue and try to fix right away.

          Thanks for the report!

          Comment


          • #6
            Issue #3098 has been created to track this defect. The fix will be added soon.

            Comment


            • #7
              Fix for issue #3098 merged into v16.3 branch and will be included in the next Bridge.NET release.

              Comment


              • #8
                I checked, and it looks like there are similar issues with other operators. See this Deck for how it behaves with the other operators.

                https://dev.deck.net/e6df4716033345e5e955772f0d167efc

                EDIT I've made this more comprehensive
                Last edited by SBeanland; 2017-09-14 @ 08:53 PM.

                Comment


                • #9
                  Hi SBeanland – Thanks for reporting this operator issue on DateTime. We will fix right away.

                  As a temporary workaround, you can compare the .Ticks property values.

                  https://deck.net/47c1d79789d732746d685236609d81cf

                  public class Program
                  {
                      public static void Main()
                      {
                          DateTime        now            = DateTime.Now;
                          DateTime        utcNow        = now.ToUniversalTime();
                  
                          Console.WriteLine(now);        
                          Console.WriteLine(utcNow);
                  
                          if (now.Ticks < utcNow.Ticks)
                              Console.WriteLine("Less than"); // Expected
                          else
                              Console.WriteLine("Not less than"); // Not expected
                      }
                  }

                  Comment


                  • #10
                    Hi SBeanland – This issue has been fixed and will be included in the upcoming Bridge 16.3.1 release.

                    https://github.com/bridgedotnet/Bridge/issues/3138

                    Hope this helps.
                    Last edited by geoffrey.mcgill; 2017-09-16 @ 04:43 AM.

                    Comment

                    Working...
                    X