DateTimeField always reads a 0 calendar from the DB

65 views
Skip to first unread message

Daniel Eggert

unread,
May 18, 2012, 10:48:52 AM5/18/12
to lif...@googlegroups.com
I can write a Calendar instance to MongoDB, but when I read it back, it's always
    java.util.GregorianCalendar[time=0,…

My record looks like this:

class LogEntry extends MongoRecord[LogEntry] with MongoId[LogEntry] {
def meta = LogEntry
object text extends StringField(this, 1000)
object entryType extends EnumField(this, LogEntryType)
object date extends DateTimeField(this)
}

It gets writing to MongoDB like this

{ "text" : "A", "date" : ISODate("2012-05-18T14:34:42.768Z"), "_id" : ObjectId("4fb65e0296466a4e7c761601"), "entryType" : 0 }

but when I read it back in the date is 0. I have no idea what's going on here…

/Daniel

Tim Nelson

unread,
May 18, 2012, 12:08:34 PM5/18/12
to lif...@googlegroups.com
Hi Daniel,

I'm not sure what the problem is. I just checked the tests and I have DateTimeField commented out, so it's not being tested.

I'll look into it when I have some time. For now I'd suggest using DateField, I use it exclusively in my code and I know it works.

Tim

Daniel Eggert

unread,
May 21, 2012, 9:46:47 AM5/21/12
to lif...@googlegroups.com
Thanks.

Should I file a bug report? Where?

Might be a stupid question, but: How does DateField differ from DateTimeField? They both store date & time as ISODate, right?

/Daniel

Tim Nelson

unread,
May 21, 2012, 10:00:03 AM5/21/12
to lif...@googlegroups.com
Hi Daniel,

I'll file a bug when I look into, if necessary.

DateTimeField uses Calendar and DateField uses Date.

Tim

Daniel Eggert

unread,
May 21, 2012, 10:30:13 AM5/21/12
to lif...@googlegroups.com
Hi Tim,

The reason I ask about Date vs. Calendar is because I know (even) less about Java than I know about Scala. Seems like Date is deprecated, and Calendar is the new hot thing, but I'm unsure why/how Date is bad. I'm use joda.DateTime anyway, so converting to Date in stead of to Calendar is easy.

/Daniel

Daniel Eggert

unread,
May 22, 2012, 9:42:46 AM5/22/12
to lif...@googlegroups.com
Now I'm using DateField, but the values are always the current date&time, not what's in the database. Just as bad as before. I can still save correct dates to the db, just not read from it.

object creationDate extends DateField(this)

/Daniel

Tim Nelson

unread,
May 22, 2012, 4:13:52 PM5/22/12
to lif...@googlegroups.com
Hi Daniel,

Can you post an example app [1] to github. I know that DateField works properly, and I'm pretty sure DateTimeField does as well, so I'm not sure why you're having problems with them.

Tim

Daniel Eggert

unread,
May 25, 2012, 6:14:10 AM5/25/12
to lif...@googlegroups.com
I finally got around to posting a simple app that shows the issue:


It should be trivial enough to understand. All it requires is a MongoDB server and curl. There's more info in the README.md It's a Play! 2 app using liftweb and rogue. I hope I won't get flamed for combining these two competing frameworks.

% ./post
class models.Foo={dateA=Sun Apr 01 12:00:00 CEST 2012, dateB=Sun Apr 01 12:00:00 CEST 2012, _id=4fbf5afe9646f765928cea6c}
% ./get 
class models.Foo={dateA=Sun Apr 01 12:00:00 CEST 2012, dateB=Sun Apr 01 12:00:00 CEST 2012, _id=4fbf5afe9646f765928cea6c}

But the content of the DB shows the correct date:

% mongodb
MongoDB shell version: 2.0.4
> use datetimetest
> db.foo.find()
{ "_id" : ObjectId("4fbf5afe9646f765928cea6c"), "dateA" : ISODate("2012-04-01T10:00:00Z"), "dateB" : ISODate("2012-04-01T10:00:00Z") }


Thanks in advance for any help!

Daniel

Tim Nelson

unread,
May 25, 2012, 8:17:46 AM5/25/12
to lif...@googlegroups.com
Hi Daniel,

What you're seeing is that the dates in Mongo are in UTC and when you are retrieving them and calling toString on them, they will print out in local time, notice the CEST part that shows the timezone.

Tim

Daniel Eggert

unread,
May 25, 2012, 10:35:53 AM5/25/12
to lif...@googlegroups.com
Oh, I see. This is actually not the behavior I was seeing in my real project. Time do debug more...

/Daniel
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Daniel Eggert

unread,
May 25, 2012, 11:30:00 AM5/25/12
to lif...@googlegroups.com
Ha, I removed casbah from my (main) project and now it works as a charm. Thanks for the time and patience.

/Daniel
Reply all
Reply to author
Forward
0 new messages