No announcement yet.

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

  • 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 sample:

    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)


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

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


      • #4
        Also 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


        • #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!


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


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


              • #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.


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


                • #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.


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


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


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