MCPcopy
hub / github.com/YelpArchive/elastalert / dt_to_ts

Function dt_to_ts

elastalert/util.py:153–164  ·  view source on GitHub ↗
(dt)

Source from the content-addressed store, hash-verified

151
152
153def 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
167def ts_to_dt_with_format(timestamp, ts_format):

Callers 15

test_agg_matchtimeFunction · 0.90
test_agg_not_matchtimeFunction · 0.90
test_agg_cronFunction · 0.90
test_silenceFunction · 0.90
test_silence_query_keyFunction · 0.90
test_realertFunction · 0.90
test_countFunction · 0.90
writebackMethod · 0.85
inc_tsFunction · 0.85

Calls

no outgoing calls

Tested by 9

test_agg_matchtimeFunction · 0.72
test_agg_not_matchtimeFunction · 0.72
test_agg_cronFunction · 0.72
test_silenceFunction · 0.72
test_silence_query_keyFunction · 0.72
test_realertFunction · 0.72
test_countFunction · 0.72