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

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

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.2.0, 2.6.3
    • Fix Version/s: None
    • Component/s: Indexing, Querying
    • Labels:
      None

      Description

      //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)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                renctan Randolph Tan
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: