title: .NET DirectoryServices Find methods use UTC or local time?
body: <p><a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.userprincipal.findbylogontime%28v=vs.100%29.aspx" rel="nofollow">According to MSDN</a>, the find methods (like FindByLogonTime and FindByBadPasswordAttempt) of the <code>UserPrinciple</code> and <code>ComputerPrinciple</code> classes use UTC time to filter results.  However, testing shows these methods seem to take local time as input, while the resulting objects use UTC for their time properties and need to be converted to local time.</p>
  
  <p>Here's an example that seems to correctly list all users with a failed login attempt on the server since 6am local time:</p>
  
  <pre><code>    static void Main()
      {
          var pc = new PrincipalContext(ContextType.Domain, dcServer);
          PrincipalSearchResult&lt;UserPrincipal&gt; uFailed = UserPrincipal.FindByBadPasswordAttempt(pc, DateTime.Now.Date.AddHours(6), MatchType.GreaterThan);
          string s = "";
          foreach (UserPrincipal u in uFailed)
          {
              s += u.SamAccountName + ": " + Convert.ToDateTime(u.LastBadPasswordAttempt).ToLocalTime().ToString() + "\r\n";
          }
          Console.Write(s);
          Console.Read();
      }
  </code></pre>
  
  <p>Note the UTC conversion for the LastBadPasswordAttempt property, but not in the FindByBadPasswordAttempt filter.</p>
  
  <p>I'm nervous about putting this into production without knowing if I'm missing something (likely) or if the MSDN docs are wrong.  The code runs on the DC it's querying, so should be no timezone issues.</p>