Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3590

created_at field comparison not working properly

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I ran into this issue trying to solve this Stackoverflow question

      problem is

      Unable to find source-code formatter for language: rb. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class Post
      include Mongoid::Timestamps
      # ... yada yada
      end
      

      suppose we have these posts

      {"post":"1","created_at": "2014-03-25 13:04:43"}
      {"post":"2","created_at": "2014-03-25 13:04:44"}
      {"post":"3","created_at": "2014-03-25 13:04:45"}
      

      i've tried querying the posts using the following

      Unable to find source-code formatter for language: rb. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Post.where(:created_at.gt => "2014-03-25 13:04:44").first.try(:id)
      #=> 2 #wrong
      Post.where(:created_at.gt => "2014-03-25 13:04:44 UTC").first.try(:id)
      #=> 2 #wrong
      Post.where(:created_at.gt => DateTime.parse("2014-03-25 13:04:44 UTC")).first.try(:id)
      #=> 2 #wrong
      Post.where(:created_at.gt => DateTime.parse("2014-03-25 13:04:44 UTC").mongoize).first.try(:id)
      #=> 2 #wrong
      Post.where(:created_at.gt => "2014-03-25 13:04:44 UTC".mongoize).first.try(:id)
      #=> 2 #wrong
      Post.where(:created_at.lte => "2014-03-25 13:04:43").first.try(:id)
      #=> nil #wrong
      Post.where(:created_at.lte => "2014-03-25 13:04:43 UTC").first.try(:id)
      #=> nil #wrong
      Post.where(:created_at.gt => second_post.created_at).first.try(:id)
      #=> 3 #correct
      

      it's really weird , i've tried parsing the string using Date, DateTime and Time but no difference in the result ?

            Assignee:
            Unassigned Unassigned
            Reporter:
            artmees artmees
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: