time zone confusion?

3,742 views
Skip to first unread message

Roy Smith

unread,
Nov 3, 2010, 5:23:22 PM11/3/10
to mongodb-user
I'm brand new to Mongo, and just started playing with a database set
up by somebody else. I did a query with the mongo command-line tool,
asking for a field which is a timestamp. The results are shown
below. What's strange is that some of the result print in GMT-4 and
some in GMT-5, but they're all labeled "EST" (the GMT-4 ones should be
"EDT"). I'm assuming this is a bug?


> db.songs.find({'title': 'Chiquitita'}, {'avail_date_aac':1}, 10)
{ "_id" : ObjectId("4ccee3cfd6403840e6708ef3"), "avail_date_aac" :
"Mon Apr 17 1995 20:00:00 GMT-0400 (EST)" }
{ "_id" : ObjectId("4ccee3dbd6403840e6721d88"), "avail_date_aac" :
"Wed Dec 31 1969 19:00:00 GMT-0500 (EST)" }
{ "_id" : ObjectId("4ccee3dbd6403840e67230d4"), "avail_date_aac" :
"Mon Jul 12 2004 20:00:00 GMT-0400 (EST)" }
{ "_id" : ObjectId("4ccee3dbd6403840e67230d9"), "avail_date_aac" :
"Mon Jul 12 2004 20:00:00 GMT-0400 (EST)" }
{ "_id" : ObjectId("4ccee3fcd6403840e6765be4"), "avail_date_aac" :
"Mon Sep 20 1993 20:00:00 GMT-0400 (EST)" }
{ "_id" : ObjectId("4ccee3fcd6403840e6766257"), "avail_date_aac" :
"Mon Nov 29 1999 19:00:00 GMT-0500 (EST)" }
{ "_id" : ObjectId("4ccee3fcd6403840e6766be6"), "avail_date_aac" :
"Wed Dec 31 1969 19:00:00 GMT-0500 (EST)" }
{ "_id" : ObjectId("4ccee402d6403840e6772b6a"), "avail_date_aac" :
"Mon Nov 05 2001 19:00:00 GMT-0500 (EST)" }
{ "_id" : ObjectId("4ccee417d6403840e679e950"), "avail_date_aac" :
"Wed Dec 31 1969 19:00:00 GMT-0500 (EST)" }
{ "_id" : ObjectId("4ccee417d6403840e679f01d"), "avail_date_aac" :
"Mon Nov 22 2004 19:00:00 GMT-0500 (EST)" }

Eliot Horowitz

unread,
Nov 3, 2010, 6:48:49 PM11/3/10
to mongod...@googlegroups.com
What version are you running?
I don't think those are actually stored as dates in Mongo but strings,
but its hard to tell in older versions (we've made it a lot easier)

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Roy Smith

unread,
Nov 3, 2010, 8:05:55 PM11/3/10
to mongod...@googlegroups.com
On Nov 3, 2010, at 6:48 PM, Eliot Horowitz wrote:

> What version are you running?

dpkg says:

ii mongodb 1:1.6.3-1~s7.4 An object/document-oriented database (metapa
ii mongodb-clients 1:1.6.3-1~s7.4 An object/document-oriented database (client
ii mongodb-dev 1:1.6.3-1~s7.4 An object/document-oriented database (develo
ii mongodb-server 1:1.6.3-1~s7.4 An object/document-oriented database (server
ii php5-mongo 1.0.10-1.1~s7.1 mongo extension module for PHP5
ii python-pymongo 1.9-1~s7.1

FWIW, I'm running on Debian Lucid


--
Roy Smith
r...@panix.com

Eliot Horowitz

unread,
Nov 4, 2010, 3:38:32 AM11/4/10
to mongod...@googlegroups.com
How did you insert the dates?

Markus Gattol

unread,
Nov 4, 2010, 5:19:36 AM11/4/10
to mongodb-user
1)
There is no Debian Lucid; you probably mean Ubuntu ;)

2)
I see you're using PyMongo, have a look at
http://api.mongodb.org/python/1.9%2B/faq.html#how-can-i-save-a-datetime-date-instance

Roy Smith

unread,
Nov 4, 2010, 2:41:06 PM11/4/10
to mongod...@googlegroups.com, S7 Development Team
OK, I've got this down to a minimal test case.  If I run the following python script:

--------------------------------------------------------
from pymongo import Connection
import datetime

connection = Connection()
test = connection['test_db']['test']
test.drop()

dt1 = datetime.datetime(2008, 5, 4, 20, 0, 0)
dt2 = datetime.datetime(2010, 3, 4, 19, 0, 0)

test.insert({'dt': dt1})
test.insert({'dt':dt2})

for record in test.find():
    print record
--------------------------------------------------------

It prints:

{u'dt': datetime.datetime(2008, 5, 4, 20, 0), u'_id': ObjectId('4cd2fb9f86a188263b000000')}
{u'dt': datetime.datetime(2010, 3, 4, 19, 0), u'_id': ObjectId('4cd2fb9f86a188263b000001')}


So far, so good.  The above values are in UTC.  If I then look at the collection with the mongo command-line tool, I get:

> db.test.find()
{ "_id" : ObjectId("4cd2fb9f86a188263b000000"), "dt" : "Sun May 04 2008 16:00:00 GMT-0400 (EST)" }
{ "_id" : ObjectId("4cd2fb9f86a188263b000001"), "dt" : "Thu Mar 04 2010 14:00:00 GMT-0500 (EST)" }

These have been converted to local time.  The conversions themselves are correct; the date in May is during daylight savings time, so New York is GMT-4, and the date in March is standard time in New York, so it's GMT-5.  The problem is that BOTH of these were annotated with "(EST)".  I'm guessing this is a bug in the command-line tool's print formatting routines.
Reply all
Reply to author
Forward
0 new messages