Convert ISO 8601 to Jira datetime format

The JIRA REST API is not fully compliant with ISO 8601, so requires two changes to the format:

  1. Time zone offsets in the form [+-]hhmm instead of the ISO format, [+-]hh:mm.
  2. Fractional seconds, even if that fraction is 0 (e.g. 2023-06-25T20:32:13+0000 is not accepted while 2023-06-25T20:32:13.00+0000 is accepted).

Below is a Python code example to convert ISO 8601 format to the format accepted by JIRA:

import datetime

planned_finish_date = (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=5)).isoformat(sep='T', timespec='seconds')

planned_finish_date = planned_finish_date.rsplit("+", 1)[0] + ".00+" + planned_finish_date.rsplit("+", 1)[1].replace(":", "")

The Python code provided converts an ISO 8601 format to the format accepted by JIRA. Here is the modified code that incorporates the required changes:

import datetime

planned_finish_date = (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=5)).isoformat(sep='T', timespec='seconds')

planned_finish_date = planned_finish_date.replace(":", "") + ".00" + planned_finish_date[-6:]

print(planned_finish_date)

This code will output the JIRA compliant datetime format.