[SERVER-6239] Better semantics for $add and $subtract with Dates Created: 28/Jun/12  Updated: 28/Oct/15  Resolved: 17/Dec/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 2.3.2

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Mathias Stearn
Resolution: Done Votes: 18
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-6196 'can't add two dates together' assert... Closed
Duplicate
is duplicated by SERVER-6547 $subtract in aggregation framwork wit... Closed
is duplicated by SERVER-12043 $unixDays, $unixYears, $unixHours lik... Closed
Related
is related to SERVER-6240 Disable math with Dates in agg Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Currently we treat numbers added or subtracted to dates as whole days (24*60*60*1000 millis). I think we should treat them as milliseconds instead. This way adding 30 minutes looks like {$add:['$date', 30*60*1000]} rather than {$add:['$date', 30.0/24/60]} or {$add:['$date', 1.0/24/2]}

Also currently subtracting two dates yields a Date-typed result when the result should probably be a NumberLong of the number of milliseconds between the dates. Currently it would return a result around 1970-01-01 for dates that are near each other.

Expected results

Date - Date : NumberLong(Milliseconds between times)
Num - Date : Error
Date - Num : Date(original - Num as milliseconds)

Date + Date : Error (current behavior)
Num + Date : Date(with num treated as millis)
Date + Num : Same as above.



 Comments   
Comment by auto [ 15/Dec/12 ]

Author:

{u'date': u'2012-12-14T23:10:44Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: SERVER-6239 support $add and $subtract with dates

Date - Date : NumberLong(Milliseconds between times)
Num - Date : Error
Date - Num : Date(original - Num as milliseconds)

Date + Date : Error
Num + Date : Date(with num treated as millis)
Date + Num : Same as Num+Date
Branch: master
https://github.com/mongodb/mongo/commit/8479fc32086bce15e5392e4091df881695792e20

Comment by Arseny Tolmachev [ 09/Dec/12 ]

This would be a very very useful feature.

Comment by Paul Grinchenko [ 06/Dec/12 ]

We would love to have this feature.

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