class ApiResponseHelper implements ResponseGenerator {

  public String getDateStringInternal(Date inputDate) {
    if (inputDate == null) {
      return null;
    }

    final TimeZone tz = _usageSvc.getUsageTimezone();
    final Calendar cal = Calendar.getInstance(tz);
    cal.setTime(inputDate);

    final StringBuilder sb = new StringBuilder(32);
    sb.append(cal.get(Calendar.YEAR)).append('-');

    final int month = cal.get(Calendar.MONTH) + 1;
    if (month < 10) {
      sb.append('0');
    }
    sb.append(month).append('-');

    final int day = cal.get(Calendar.DAY_OF_MONTH);
    if (day < 10) {
      sb.append('0');
    }
    sb.append(day);

    sb.append("'T'");

    final int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (hour < 10) {
      sb.append('0');
    }
    sb.append(hour).append(':');

    final int minute = cal.get(Calendar.MINUTE);
    if (minute < 10) {
      sb.append('0');
    }
    sb.append(minute).append(':');

    final int seconds = cal.get(Calendar.SECOND);
    if (seconds < 10) {
      sb.append('0');
    }
    sb.append(seconds);

    double offset = cal.get(Calendar.ZONE_OFFSET);
    if (tz.inDaylightTime(inputDate)) {
      offset += 1.0 * tz.getDSTSavings(); // add the timezone's DST
      // value (typically 1 hour
      // expressed in milliseconds)
    }

    offset = offset / (1000d * 60d * 60d);
    final int hourOffset = (int)offset;
    final double decimalVal = Math.abs(offset) - Math.abs(hourOffset);
    final int minuteOffset = (int)(decimalVal * 60);

    if (hourOffset < 0) {
      if (hourOffset > -10) {
        sb.append("-0");
      } else {
        sb.append('-');
      }
      sb.append(Math.abs(hourOffset));
    } else {
      if (hourOffset < 10) {
        sb.append("+0");
      } else {
        sb.append("+");
      }
      sb.append(hourOffset);
    }

    sb.append(':');

    if (minuteOffset == 0) {
      sb.append("00");
    } else if (minuteOffset < 10) {
      sb.append('0').append(minuteOffset);
    } else {
      sb.append(minuteOffset);
    }

    return sb.toString();
  }

}