1

2012-12-11T00:00:00+00:00

One of the AWS service returned error for this

ErrorMessage    Attribute submission-date is an invalid ISO 8601 String

Code I used to convert epoch time to ISO 8601 is below:

datetime.fromtimestamp(<epochTimeHere>, timezone.utc).isoformat()
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Korba
  • 435
  • 1
  • 4
  • 18
  • 1
    yes, according to [the wiki on ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) (see also [ISO/TC154N](https://web.archive.org/web/20171020085148/https://www.loc.gov/standards/datetime/ISO_DIS%208601-2.pdf), p.29). But maybe the aws service expects `Z` instead of `+00:00`? (just do a string replace if so, see e.g. [here](https://stackoverflow.com/a/62769371/10197418)) – FObersteiner Jan 07 '21 at 10:27
  • Please let me know which service returned the error so I can let the team know that this may be a potentially misleading error message. – Dennis Traub Jan 07 '21 at 15:35
  • @DennisTraub it is AWS Kendra. Error reported while indexing the files. – Korba Jan 07 '21 at 17:04
  • @MrFuppes I did string replacement to come up with something like `2012-12-11T12:00:00.000Z` and it was accepted. (FWIW I am not concerned about hours/minutes/seconds in this particular use case) – Korba Jan 07 '21 at 17:06
  • 1
    Yes. I think the error message is misleading and have already relayed it to the Kendra team. Thanks for bringing this up! – Dennis Traub Jan 08 '21 at 08:24

1 Answers1

1

Yes, a format like 2012-12-11T00:00:00+00:00 is specified by ISO 8601 - see e.g. wikipedia/ISO8601 or C.4.2 Date and Time of ISO/TC154N, p.29.

From the comment section, it seems however that the AWS service (Kendra) expects a Z for UTC (see also Kendra docs) , instead of +00:00 as returned by the Python code. A simple work-around can be a string-replace:

datetime.fromtimestamp(<epochTimeHere>, timezone.utc).isoformat().replace('+00:00', 'Z')

Side note - Python offers a catch in the other direction as well, i.e. when parsing ISO 8601 timestamps: the built-in datetime.fromisoformat method won't parse Z to UTC, but only +00:00.

FObersteiner
  • 22,500
  • 8
  • 42
  • 72