QuickFIX/J
  1. QuickFIX/J
  2. QFJ-228

Weekly session schedule calculates wrong day for non-GMT timezone

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0.5
    • Fix Version/s: 1.3.0
    • Component/s: Engine
    • 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
          }

        Activity

        Hide
        Steve Bate added a comment -

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

        Show
        Steve Bate added a comment - Added unit test and modified code to handle this situation properly. Thanks for the report.

          People

          • Assignee:
            Steve Bate
            Reporter:
            Christian Braeuner
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development