arthurai.util.format_timestamp#
- arthurai.util.format_timestamp(timestamp, tz=None)#
Check if timestamp is time aware and convert to ISO8601 conventioned string.
This helper function converts datetime objects into timezone aware ISO8601 strings, which is necessary when sending JSON to Arthur’s backend. If timestamp argument is timezone aware, no location needs to be provided; otherwise, a string pytz location like “US/Eastern” needs to be provided to establish timezone. String timestamp are supported for backwards compatability and for simplicity are assumed to already be in UTC format, but string support will be deprecated.
- Parameters
timestamp (
Union
[datetime
,str
]) – timestamp to formattz (
Union
[timezone
,str
,None
]) – datetime timezone object or timezone string
- Return type
str
- Returns
ISO8601 formatted timestamp
- Raises
TypeError – timestamp is not of type datetime.datetime
ValueError – timestamp is not timezone aware and no location data is provided to remedy