Ofer Reichman
2015-09-25 08:08:36 UTC
I've spent some time trying to figure out how to store a *time_point* using
the C++ driver.
I'm posting my code for review and to help anyone who might need it (until
the driver supports it <https://jira.mongodb.org/browse/CXX-626>).
Storing:
using std::chrono::system_clock;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
system_clock::time_point tp = system_clock::now(); // for example
document << "someTimePoint" << b_date{duration_cast<milliseconds>(tp.
time_since_epoch()).count()};
Retrieving:
system_clock::time_point tp(duration_cast<system_clock::duration>(
milliseconds{doc->view()["someTimePoint"].get_date().value}));
Note: Different clocks have different epochs, so this code may not work
correctly if the machine that stores the time_point is different than the
one that retrieves it.
Hope this is helpful.
Any reviews are welcome!
Ofer
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/ae1dedb3-7e91-40d6-a6fb-409440492446%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
the C++ driver.
I'm posting my code for review and to help anyone who might need it (until
the driver supports it <https://jira.mongodb.org/browse/CXX-626>).
Storing:
using std::chrono::system_clock;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
system_clock::time_point tp = system_clock::now(); // for example
document << "someTimePoint" << b_date{duration_cast<milliseconds>(tp.
time_since_epoch()).count()};
Retrieving:
system_clock::time_point tp(duration_cast<system_clock::duration>(
milliseconds{doc->view()["someTimePoint"].get_date().value}));
Note: Different clocks have different epochs, so this code may not work
correctly if the machine that stores the time_point is different than the
one that retrieves it.
Hope this is helpful.
Any reviews are welcome!
Ofer
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/ae1dedb3-7e91-40d6-a6fb-409440492446%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.