Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#149 wrong date conversion in constructor Date(java.util.Date

Release
pending-invalid
Ben Fortuna
General (64)
5
2012-06-25
2012-04-20
Ana
No

Hi,

I just found out something strange that I think is a bug.
When I use the constructor method public Date(java.util.Date date) (under the package net.fortuna.ical4j.model), the date created is wrong.

For example, see my code:

String zFEC_FIN = "2012-05-17 00:00:00";
String zFEC_INICIO = "2012-05-17 00:00:00";

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date startDate = formatter.parse(zFEC_INICIO.substring(0, zFEC_INICIO.indexOf(" ")));
java.util.Date finishDate = formatter.parse(zFEC_FIN.substring(0, zFEC_FIN.indexOf(" ")));

System.out.println("java.util.date start: "+startDate + " finish: "+finishDate);
System.out.println("iCal4j start: "+new Date(startDate) + " finish: "+new Date(finishDate));

The screen output is as follows:

java.util.date start: Thu May 17 00:00:00 CEST 2012 finish: Thu May 17 00:00:00 CEST 2012
iCal4j start: 20120516 finish: 20120516

So the constructor is basically substracting one day in the conversion process.
I thought you would want to know :)

Also, I would like to thank you for your effort since the iCal4j library has been very useful to me. Keep up the good work!

Best regards,
Ana

Discussion

  • Ben Fortuna
    Ben Fortuna
    2012-04-22

    • status: open --> pending-invalid
     
  • Ben Fortuna
    Ben Fortuna
    2012-04-22

    Hi,

    I think this is because, by default, ical4j creates dates in GMT timezone. So midnight CEST on May 17, I am guessing, is still May 16 in GMT.

    You can have dates use the local default timezone if you prefer, by setting the following property in your ical4j.properties file:

    net.fortuna.ical4j.timezone.date.floating=true

    regards,
    ben

     
  • Ana
    Ana
    2012-04-23

    Hi ben,

    thanks for your answer. Yes, you are right... setting that property to true solved it.

    Is there any way to set that property to true programatically?

    Thanks!!

     
  • Ana
    Ana
    2012-04-23

    • status: pending-invalid --> open-invalid
     
  • Ben Fortuna
    Ben Fortuna
    2012-06-25

    Hi Ana,

    Sorry I didn't see your last comment. You can also set this flag via a system property (i.e. System.setProperty("net.fortuna.ical4j.timezone.date.floating", "true") )

    regards,
    ben

     
  • Ben Fortuna
    Ben Fortuna
    2012-06-25

    • status: open-invalid --> pending-invalid