[DOCS-4086] How to store local time in MongoDB? Created: 25/Sep/14  Updated: 17/Oct/14  Resolved: 17/Oct/14

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: v1.3.12

Type: Improvement Priority: Major - P3
Reporter: Asko Kauppi Assignee: Andrew Aldridge
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Casbah driver (Scala) on OS X


Issue Links:
Related
related to DOCS-4082 Update documentation on timestamp con... Closed
Participants:
Days since reply: 9 years, 17 weeks, 5 days ago

 Description   

I'm developing my first commercial project using MongoDB. Otherwise very pleased with the quality of the product and documentation, but the corner of handling local times would seriously need more effort, either in the API and/or a tutorial describing good practices.

StackOverflow.com has multiple cases where people are equally puzzled by this, it's not only me. It should be easy and explicit to:

  • save UTC date and retrieve one, without conversions to the local time zone
  • save local time and retrieve one, as above

Our customer case is that we want UTC time stamps for the normal reasons, but also wish to see what "wall clock time" and e.g. day of week the stored data fits, in the local context. A tutorial describing how to do this would have helped.

  • should we store local times as BsonDateTime (as if they were UTC)
  • should we store using "minutes from the beginning of the week" (fine grained time would come from the UTC time stamp)
  • should we do something else?

I think much of the confusion is due to Joda DateTime. I'm considering not using it, later, and dealing with BsonDateTime objects directly. However, for now things are reasonably okay so this must wait.

Other things being so nice and trivial with MongoDB, how about fixing the local time corner as well?

Links to StackOverflow issues regarding these:
http://stackoverflow.com/questions/26023835/how-to-read-back-a-datetime-as-utc-in-mongodb-casbah
http://stackoverflow.com/questions/16901393/storing-utc-and-local-datetime-in-mongo



 Comments   
Comment by Githook User [ 17/Oct/14 ]

Author:

{u'username': u'i80and', u'name': u'Andrew Aldridge', u'email': u'i80and@foxquill.com'}

Message: DOCS-4086: Guide to handling localtime

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/6956cf16b087b34932dc943f49e29b0aa5fb05f2

Comment by Asko Kauppi [ 25/Sep/14 ]

A third SO entry: http://stackoverflow.com/questions/12830521/how-to-translate-utc-time-to-arbitrary-local-time-in-mongo-j-s

Comment by Asko Kauppi [ 25/Sep/14 ]

Ideally, the MongoDB API could allow storing "local time", maintaining the time zone information as well. If I store local time "as UTC", I will wipe out the time zone info.

But most importantly, conversions between local and UTC (and the particular machine's local time zone, which may be yet something else) should not happen as implicitly as they now seem to happen. Any such conversions should be explicit, by the Scala compiler.

Generated at Thu Feb 08 07:47:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.