(dt)
| 151 | |
| 152 | |
| 153 | def dt_to_ts(dt): |
| 154 | if not isinstance(dt, datetime.datetime): |
| 155 | logging.warning('Expected datetime, got %s' % (type(dt))) |
| 156 | return dt |
| 157 | ts = dt.isoformat() |
| 158 | # Round microseconds to milliseconds |
| 159 | if dt.tzinfo is None: |
| 160 | # Implicitly convert local times to UTC |
| 161 | return ts + 'Z' |
| 162 | # isoformat() uses microsecond accuracy and timezone offsets |
| 163 | # but we should try to use millisecond accuracy and Z to indicate UTC |
| 164 | return ts.replace('000+00:00', 'Z').replace('+00:00', 'Z') |
| 165 | |
| 166 | |
| 167 | def ts_to_dt_with_format(timestamp, ts_format): |
no outgoing calls