[SERVER-7141] Consider making timestamp and date non-comparable or make comparison symmetrical Created: 24/Sep/12  Updated: 10/Dec/14  Resolved: 29/Sep/14

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: 2.2.0, 2.6.3
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Randolph Tan Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3304 Change comparison order so all Dates ... Closed
Related
related to SERVER-3304 Change comparison order so all Dates ... Closed
Participants:

 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)


Generated at Thu Feb 08 03:13:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.