How to correctly use MappedDateTime

51 views
Skip to first unread message

tclendenen

unread,
Mar 21, 2009, 9:34:57 PM3/21/09
to Lift
As an exercise I've added a deadline object to the ToDo class. It
works as expected except that the time is always set to midnight (ex.
2009-07-16 00:00:00.0) in the database. Is this the expected
behavior? Any help is appreciated.

TylerWeir

unread,
Mar 22, 2009, 8:30:32 AM3/22/09
to Lift
Can you add some of your code?
How you're using MappedDateTime in your snippet and the definition in
the model would be a good start.

tclendenen

unread,
Mar 22, 2009, 10:52:02 AM3/22/09
to Lift
Except for the <todo:deadline> I added to index.html, I believe the
following are the only changes made to the original tutorial code

Additions to TD.scala

val dateFormat = new SimpleDateFormat("MM/dd/yyyy, hh:mm a")

private def deadline(td: ToDo, reDraw: () => JsCmd) =
swappable(<span class="deadline">{td.deadline}</span>,
<span class="deadline">
{ajaxText(td.deadline.toString,
v => {td.deadline(dateFormat.parse(v)).save;
reDraw()})}
</span>)

This was added to bind in the toList method.
"deadline" -> deadline(td, reDraw)

and this was added to bind in doBind within the add method
"deadline" -> todo.deadline.toForm,

Addition to ToDo.scala

object deadline extends MappedDateTime(this){
val dateFormat = new SimpleDateFormat("MM/dd/yyyy, hh:mm a")
override def defaultValue = time(millis + days(5))
override def asHtml = Text(toString)
override def toString = dateFormat.format(is)

Derek Chen-Becker

unread,
Mar 23, 2009, 4:30:18 PM3/23/09
to lif...@googlegroups.com
I think the reason that it's set to midnight is because when the date parser parses a date with only the MM/dd/yyyy format string, it sets HMS to zeros.

Derek

tclendenen

unread,
Mar 23, 2009, 6:31:39 PM3/23/09
to Lift
That would make sense but the format string is "MM/dd/yyyy, hh:mm a".
My initial question, although not asked correctly, came from looking
through the code and seeing the DateExtension class in TimeHelpers.
It states "This class adds a noTime method the Date class, in order to
get at Date object starting at 00:00" and it is created by an implicit
conversion. However, I couldn't see where the implicit converison
would be invoked and didn't know if that was the expected behavior. I
don't know that the parse/format on the Java side of things is not
causing the issue, so I will look into that further.

Derek Chen-Becker

unread,
Mar 23, 2009, 6:42:51 PM3/23/09
to lif...@googlegroups.com
Ah, sorry, I misread. The parse should be working fine, then. The MappdeDateTime really should be saving the full Date instance that's passed to it, so please let me know if the Date that you're setting as the value is losing the time info. Also, what DB engine are you running against?

Derek

tclendenen

unread,
Mar 23, 2009, 8:40:17 PM3/23/09
to Lift
I overrode the save method of the ToDo class and placed println
(toString) before and after the getSingleton.save(this) call. Both
print the correctly formatted date, but it still shows up on the page
and in the database as 12:00. I am using the Derby 10.4.2.0

Derek Chen-Becker

unread,
Mar 27, 2009, 10:06:44 AM3/27/09
to lif...@googlegroups.com
I've confirmed this. I'll add a bug on it and we'll see what's going on.

Derek
Reply all
Reply to author
Forward
0 new messages