Parses an NGINX timestamp from  "30/Apr/2014:07:32:09 +0000" and returns it as ISO 8601"

def to_ts(s):
        """Parses an NGINX timestamp from  "30/Apr/2014:07:32:09 +0000" and returns it as ISO 8601" """

        # Strip TZ portion if present
        m = Nginx.DATE_FMT.match(s)
        if m:
            s = m.group(1)
            delta = timedelta(seconds=int(m.group(3)) * (-1 if m.group(2) == '-' else 1)) # Offset from GMT
        else:
            delta = timedelta(seconds=0)
        dt = datetime.strptime(s, "%d/%b/%Y:%H:%M:%S")
        dt += delta
        return dt.strftime('%Y-%m-%dT%H:%M:%SZ')