Home Forums WPF controls Xceed DataGrid for WPF Filter row is filering data according to the utc not local time

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #41531 |

    hi,

    i am filterrow to filtring functionality enabled. For datetime column i defined custom editor template and passing filter criteria/ filter is working according to UTC time and not local time how to fix it. 

    Imported from legacy forums. Posted by Ravindra (had 166 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Ravindra,

     

    Can you send me a simple stand alone sample project which reproduces the issue so that I can have a closer look. You can send it to: support@xceed.com 

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 37 views)

    User (Old forums)
    Member
    Post count: 23064
    this sample code will show the issue. event value in local time is in range still criteria is returning false. 
     class Program
        {
            static void Main(string[] args)
            {
                DateTime dt = DateTime.Now;
                var dtutc = dt.ToUniversalTime();
                var dtlocal = dt.ToLocalTime();
                if(dtutc.Equals(dtutc))
                    Console.WriteLine(“utc and local are same”);
                var StartDate = DateTime.Now.AddHours(-1).ToUniversalTime();
                var EndDate = DateTime.Now.AddHours(1).ToUniversalTime();
                FilterCriterion abc = new AndFilterCriterion(
                  new GreaterThanOrEqualToFilterCriterion(StartDate),
                  new LessThanOrEqualToFilterCriterion(EndDate));
                if(abc.IsMatch(dtlocal))
                Console.WriteLine(“xcedd criteria is in range “);
                Console.ReadLine();
            }
        }

    Imported from legacy forums. Posted by Ravindra (had 48 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

     

    The problem seems to be within your code.  In the attached snippet, you have the following line:

    if( dtutc.Equals( dtutc ) )
    {
      Console.WriteLine( “utc and local are same” );
    }

    The message is wrong since the compared values are the same UTC date time.  To make the message right, the “Equals” parameter should have been set to “dtlocal”.

    if( dtutc.Equals( dtlocal ) )
    {
      Console.WriteLine( “utc and local are same” );
    }


    Internally, the IsMatch method simply calls the IComparable.CompareTo method.  According to MSDN, the comparison for DateTime values is based on their Ticks and not their Kind.

    https://msdn.microsoft.com/en-us/library/ces8tc4z(v=vs.110).aspx
    https://msdn.microsoft.com/en-us/library/x79949f0(v=vs.110).aspx


    Having that said, for this to work you would have to make sure that every date time value is of the same kind.  

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 52 views)

    User (Old forums)
    Member
    Post count: 23064

    YES.The line you mentioned is correct. I am pointing at problem with Ismatch Method. 

    var StartDate = DateTime.Now.AddHours(-1).ToUniversalTime();
                var EndDate = DateTime.Now.AddHours(1).ToUniversalTime();
                FilterCriterion abc = new AndFilterCriterion(
                  new GreaterThanOrEqualToFilterCriterion(StartDate),
                  new LessThanOrEqualToFilterCriterion(EndDate));
                if(abc.IsMatch(dtlocal))

                Console.WriteLine(“xcedd criteria is in range “);

    This is not returning correct value.  As defined in code dateTime.Now is within range defined in UTC Criteria return false.

    Imported from legacy forums. Posted by Ravindra (had 73 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Ravindra,

     

    Again, internally the IsMatch method simply calls the IComparable.CompareTo method.  According to MSDN, the comparison for DateTime values is based on their Ticks and not their Kind.

    Basically, a DateTime value contains a number of ticks and a kind.  MSDN says that the CompareTo method compares the ticks only and ignore the kind.  That means that 2 DateTime values that have the same ticks count are considered equal even if they have a different kind (local vs universal).

    If you run the following code, you would notice that the current local time is lesser than the current local time minus 1 hours converted to universal time.

    if( dtlocal < StartDate )
    {
      Console.WriteLine( “The local DateTime is before the StartDate.” );
    }

    If we forget about the remarks in MSDN about DateTime values, it makes no sense since the StartDate is dtlocal minus 1 hour.  The only little issue is that these 2 dates are not in the same timezone.  If we look again at MSDN, we’ll discover that this is the intended behavior, which is different from what we would expect in this scenario.

    To make the whole comparison work, you should use all local DateTime values or all universal DateTime values. 

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 66 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.