[QFJ-228] Weekly session schedule calculates wrong day for non-GMT timezone Created: 24/Aug/07  Updated: 11/Feb/09  Resolved: 25/Aug/07

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.0.5
Fix Version/s: 1.3.0

Type: Bug Priority: Critical
Reporter: Christian Braeuner Assignee: Steve Bate
Resolution: Fixed Votes: 0
Labels: None
Environment:

Any. Bug is happening on various Unix and Windows JREs



 Description   

This Friday morning our production system stopped at 00:30:00, rather than tomorrow, Saturday at 00:30:00, which caused a lot of trouble.

We have changed the time zone of our session scheduling in the production system from GMT to America/Chicago to switch correctly for the US Daylight saving later this year. We have adjusted the start end end time accordingly to accomodate the new time zone. The setting is the following now:
TZ=America/Chicago
End Day=Friday
End Time=19:30:00

This equates to the same settings in GMT, which we had previously:
End Day=Saturday
End Time=00:30:00

So QF should have shut down tomorrow morning and not today on Friday morning.

I've had a look into the QF source code and found that the start and end time do not wrap the day when the TZ offset is applied, because schedule days and times are treated separately.
The result is that if the start or end time in the target timezone is not on the same day than on GMT then QF gets it wrong.

I have done the following temporary fix to correct this:

SessionSchedule::SessionSchedule(...)
{
...
Calendar localTime = SystemTime.getUtcCalendar();
localTime.setTimeZone(sessionTimeZone);
localTime.set(Calendar.MILLISECOND, 0);
localTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(1)));
localTime.set(Calendar.MINUTE, Integer.parseInt(matcher.group(2)));
localTime.set(Calendar.SECOND, Integer.parseInt(matcher.group(3)));
< //moved down: Calendar startTime = SystemTime.getUtcCalendar();
< //moved down: startTime.setTime(localTime.getTime());
int startDay = -1;
if (weeklySession)

{ startDay = getDay(settings, sessionID, Session.SETTING_START_DAY, -1); > localTime.set(Calendar.DAY_OF_WEEK,startDay); //set weekday in start calendar }

> Calendar startTime = SystemTime.getUtcCalendar();
> startTime.setTime(localTime.getTime());

matcher = TIME_PATTERN.matcher(endTimeString);
if (!matcher.find())

{ throw new ConfigError("Session " + sessionID + ": could not parse end time '" + endTimeString + "'."); }

localTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(1)));
localTime.set(Calendar.MINUTE, Integer.parseInt(matcher.group(2)));
localTime.set(Calendar.SECOND, Integer.parseInt(matcher.group(3)));
< //moved down :Calendar endTime = SystemTime.getUtcCalendar();
< //moved down :endTime.setTime(localTime.getTime());
int endDay = -1;
if (weeklySession)

{ endDay = getDay(settings, sessionID, Session.SETTING_END_DAY, -1); > localTime.set(Calendar.DAY_OF_WEEK,endDay); //set week day in end calendar }

> Calendar endTime = SystemTime.getUtcCalendar();
> endTime.setTime(localTime.getTime());

  • this.startTime = new TimeEndPoint(startTime); //removed weekday parameter
  • this.endTime = new TimeEndPoint(endTime); //removed weekday parameter
    }
  • TimeEndPoint::TimeEndPoint(Calendar c) //removed weekday parameter { * this( c.get(Calendar.DAY_OF_WEEK) , c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND)); //use calendar's weekday instead of separate weekday }


 Comments   
Comment by Steve Bate [ 24/Aug/07 ]

Added unit test and modified code to handle this situation properly. Thanks for the report.

Generated at Thu Apr 18 02:20:27 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.