예제 #1
0
 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))
예제 #2
0
파일: _render.py 프로젝트: cegfdb/eliottree
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)))
예제 #3
0
 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'))
예제 #4
0
 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'))