[SERVER-7588] mongo shell ISODate return bug Created: 08/Nov/12 Updated: 11/Jul/16 Resolved: 18/Mar/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript |
| Affects Version/s: | 2.2.0 |
| Fix Version/s: | 2.2.6, 2.4.4, 2.5.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Samuel Ahn | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 0 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu 10.04.3 |
||
| Issue Links: |
|
||||
| Backwards Compatibility: | Fully Compatible | ||||
| Operating System: | ALL | ||||
| Participants: | |||||
| Description |
|
For some input strings, mongo shell ISODate() return value has 1 sec difference. > ISODate("2012-10-02 19:28:16.926") |
| Comments |
| Comment by auto [ 01/Jul/13 ] | ||||||||||||
|
Author: {u'username': u'monkey101', u'name': u'Dan Pasette', u'email': u'dan@10gen.com'}Message: Do not use floating point for seconds, only for milliseconds. Adjust other Code backported from Tad Marshall's master branch commit: | ||||||||||||
| Comment by auto [ 13/May/13 ] | ||||||||||||
|
Author: {u'date': u'2013-03-18T14:13:45Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: Do not use floating point for seconds, only for milliseconds. Adjust other | ||||||||||||
| Comment by auto [ 18/Mar/13 ] | ||||||||||||
|
Author: {u'date': u'2013-03-18T14:13:45Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: Do not use floating point for seconds, only for milliseconds. Adjust other | ||||||||||||
| Comment by Tad Marshall [ 17/Mar/13 ] | ||||||||||||
|
Hi Samuel, Thanks for the great bug report! Yes, the parsing of certain time values in the ISODate() constructor is faulty. The problem is some poor use of floating point. The JavaScript code in the ISODate constructor assumes that it can use integer math to compute the fractional number of seconds and then subtract that from the original number to get an integer. Depending on the value and its floating point representation, this doesn't work.
When this calculated value is truncated to an integer, you lose a second. Rewriting some of the calculation logic should fix this. Tad |