[SERVER-22925] ISODate from object key in shell Created: 02/Mar/16 Updated: 23/Mar/16 Resolved: 23/Mar/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 3.2.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Trivial - P5 |
| Reporter: | Eric Stobbart | Assignee: | Mira Carey |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Operating System: | ALL |
| Steps To Reproduce: | > var date = ISODate(); |
| Sprint: | Platforms 12 (04/01/16) |
| Participants: |
| Description |
|
I'm trying to make a unique set of ISODate's, the doc's mention ISODate being a wrapper around `new Date()`. When they're used as object keys they get converted to strings (as expected). If I try to put that string back through the constructor function the iso regex fails.. `throw Error("invalid ISO date");`. |
| Comments |
| Comment by Eric Stobbart [ 23/Mar/16 ] | ||||
|
Jason, -Eric | ||||
| Comment by Mira Carey [ 23/Mar/16 ] | ||||
|
Eric, ISODate only accepts ISO 8601 style date strings. I.e. YYYY-MM-DDTHH:MM:SS... style strings. It in turn returns regular JavaScript Date's. Those Date's have a toString() function which returns something localized like "Wed Mar 23 2016 14:01:24 GMT-0400 (EDT)", which you've noticed cannot be used as the argument to ISODate. If you'd like something that roundtrips, you can take advantage of the other serialization we offer for date's: date.tojson(). It's non-intuitive, but that's actually the serialization routine called when you default print objects in the shell, which I imagine is where the confusion is coming from. To use your example:
| ||||
| Comment by Kelsey Schubert [ 04/Mar/16 ] | ||||
|
Hi estobbart, Thank you for reporting this behavior. I am sending this ticket to the platform team; please continue to watch this ticket for updates. Kind regards, |