You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Lothar Krenzien <lk...@web.de> on 2006/12/05 14:26:56 UTC

how does cayenne handle java.util.date values ?

Hi there,

I posted this yesterday again. But have just seen that I forgott the subject. Sorry for that
What I would like to know is how does cayenne handle java.util.date values ?

My problem is, that I have to import xml files with datetime values in it of different timezones. For example the file contains the following tag: date="30.11.2006 22:14:28". In my case it should represents a datetime value of german format (dd.MM.yyyy hh.mm.ss) BUT in local korean time. Korean time has an offset of +9h to GMT. So in GMT the time part is "13:14:28" and in german time (GMT +1h) it's "14:14:28". For some "historical" reasons I have to persistent the local datetime value ("28.10.2006 22:14:28"), but of course as date object instead of a string value.

When I now try to convert the string value into a date-object using standard java methods I will get an object which reflects GMT time. But when I try to print it out on a console it will be converted to local date (thus german date). And that date will be saved by cayenne in the database. So for me it looks like  that cayenne tries to call toString() on the date object and will get a recalculated date instead of the original date. If it's true I think it would be better to use a SimpleDateFormatter instance because than the you will get a correct datetime string.

I've provided a simple demo class to show what I mean. I used Java 5, cayenne 2.1 and jtds with MS SQL Server 2000.

Thanks
Lothar


______________________________________________________________________________
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!


Re: how does cayenne handle java.util.date values ?

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Dec 5, 2006, at 14:26 , Lothar Krenzien wrote:

> I've provided a simple demo class to show what I mean. I used Java  
> 5, cayenne 2.1 and jtds with MS SQL Server 2000.

Looks like the attachment are striped by the mail-list software.  
Could you copy/paste the code into the mail instead of attaching the  
java file?

  - Tore.

Re: how does cayenne handle java.util.date values ?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Attachments are stripped from the messages sent to the list, so I  
can't check your example. So let me ask you this - are you using  
Cayenne XMLEncoder/XMLDecoder? It won't handle the dates properly ...  
the rest of Cayenne will. If this doesn't help, could you please post  
a relevant code example inline (not as an attachment).

Andrus



On Dec 5, 2006, at 3:26 PM, Lothar Krenzien wrote:

> Hi there,
>
> I posted this yesterday again. But have just seen that I forgott  
> the subject. Sorry for that
> What I would like to know is how does cayenne handle java.util.date  
> values ?
>
> My problem is, that I have to import xml files with datetime values  
> in it of different timezones. For example the file contains the  
> following tag: date="30.11.2006 22:14:28". In my case it should  
> represents a datetime value of german format (dd.MM.yyyy hh.mm.ss)  
> BUT in local korean time. Korean time has an offset of +9h to GMT.  
> So in GMT the time part is "13:14:28" and in german time (GMT +1h)  
> it's "14:14:28". For some "historical" reasons I have to persistent  
> the local datetime value ("28.10.2006 22:14:28"), but of course as  
> date object instead of a string value.
>
> When I now try to convert the string value into a date-object using  
> standard java methods I will get an object which reflects GMT time.  
> But when I try to print it out on a console it will be converted to  
> local date (thus german date). And that date will be saved by  
> cayenne in the database. So for me it looks like  that cayenne  
> tries to call toString() on the date object and will get a  
> recalculated date instead of the original date. If it's true I  
> think it would be better to use a SimpleDateFormatter instance  
> because than the you will get a correct datetime string.
>
> I've provided a simple demo class to show what I mean. I used Java  
> 5, cayenne 2.1 and jtds with MS SQL Server 2000.
>
> Thanks
> Lothar
>