def test_local(self): """ Timestamps can be converted to local time. """ timestamp = 1433631432.0 utc = format.timestamp(utc_timestamps=True)(timestamp) local = format.timestamp(utc_timestamps=False)(timestamp + time.timezone) # Strip the "Z" off the end. self.assertThat(utc[:-1], ExactlyEquals(local))
def _default_value_formatter( human_readable, field_limit, utc_timestamps=True, encoding='utf-8', ): """ Create a value formatter based on several user-specified options. """ fields = {} if human_readable: fields = { eliot_ns(u'timestamp'): format.timestamp(include_microsecond=False, utc_timestamps=utc_timestamps), eliot_ns(u'duration'): format.duration(), } return compose( # We want tree-format to handle newlines. partial(format.escape_control_characters, overrides={0x0a: u'\n'}), partial(format.truncate_value, field_limit) if field_limit else identity, format.some(format.fields(fields), format.text(), format.binary(encoding), format.anything(encoding)))
def test_float(self): """ Timestamps as floats are converted to ISO 8601. """ self.assertThat(format.timestamp()(1433631432.0), ExactlyEquals(u'2015-06-06 22:57:12'))
def test_text(self): """ Timestamps as text are converted to ISO 8601. """ self.assertThat(format.timestamp()(u'1433631432'), ExactlyEquals(u'2015-06-06 22:57:12'))