Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7141

Consider making timestamp and date non-comparable or make comparison symmetrical

    • Type: Icon: Task Task
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.0, 2.6.3
    • Component/s: Index Maintenance, Querying
    • Labels:
      None

      //from compareElementValues:
              case Timestamp:
                  // unsigned compare for timestamps - note they are not really dates but (ordinal + time_t)
                  if ( l.date() < r.date() )
                      return -1;
                  return l.date() == r.date() ? 0 : 1;
              case Date:
                  {
                      long long a = (long long) l.Date().millis;
                      long long b = (long long) r.Date().millis;
                      if( a < b ) 
                          return -1;
                      return a == b ? 0 : 1;
                  }
      

      As from the code above doing a comparison with l as TimeStamp and r as Date is fine, but doing a comparison with l as Date and r as TimeStamp will throw an assertion because of it uses Date() instead of date() which has strict checking.

      P.S. also pay attention to the comment:
      // unsigned compare for timestamps - note they are not really dates but (ordinal + time_t)

            Assignee:
            Unassigned Unassigned
            Reporter:
            randolph@mongodb.com Randolph Tan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: