Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

JFOREX-3336 GMT Calender is wrong in CET TimeZone
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=88&t=43723
Page 1 of 1

Author:  SFXbernhard [ Mon 21 Nov, 2011, 15:39 ]
Post subject:  JFOREX-3336 GMT Calender is wrong in CET TimeZone

I live and run JForex in CET TimeZone.
JForex displays charts and ticks in GMT TimeZone only.
Therefore I want to set the parameters in the GMT TimeZone.
I tried the following

@Configurable("Start Date 1")                         
public Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));


but the Calendar object is always displayed in CET time (offset 1 h at the moment).
It should be displayed in the TimeZone I have select in the programed code!

Author:  API Support [ Thu 24 Nov, 2011, 16:44 ]
Post subject:  Re: JFOREX-3336 GMT Calender is wrong in CET TimeZone

Calendar has a TimeZone property, but setting or modifying it does not convert the date and time that the calendar holds to a different timezone. I.e. calendar.getTime() always returns the same set value independent from calendar's time zone.
On the other hand, e.g. calendar.get(Calendar.HOUR) / calendar.get(Calendar.HOUR_OF_DAY) returns the correct hour corresponding to calendar's time zone.

Please, use a DateFormat object with corresponding TimeZone set (GMT/UTC in your case) to parse/format Calendar / Date objects, e.g:

 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{ setTimeZone(TimeZone.getTimeZone("GMT 0")); }}; 
 Calendar calendar = Calendar.getInstance();
 System.out.println(String.format("Default TimeZone: %1$s; Current Date: %2$s; Formatted Date to GMT TimeZone: %3$s; Parsed Date from GMT TimeZone: %4$s",
                                          TimeZone.getDefault().getDisplayName(), // 1
                                          calendar.getTime(), // 2
                                          formatter.format(calendar.getTime()), // 3
                                          formatter.parse(formatter.format(calendar.getTime())))); // 4


Prints out in such case:
"Default TimeZone: Eastern European Time; Current Date: Thu Nov 24 16:46:47 EET 2011; Formatted Date to GMT TimeZone: 2011-11-24 14:46:47.200+0000; Parsed Date from GMT TimeZone: Thu Nov 24 16:46:47 EET 2011"

Additionally, we have fixed the issue with @Configurable strategy parameter with java.util.Calendar type which had not been supported.

  Page 1 of 1