Пример #1
0
    def do(self, event):
        record = dict(event.record)
        time = Chronyk(record[self._key])
        if self._format is None:
            record[self._key] = time.timestamp()
        else:
            record[self._key] = time.timestring(self._format)

        return Event(event.tag, event.timestamp, record)
Пример #2
0
def timeslate():
    input_time = request.args.get('input')
    output_format = request.args.get('format')
    tz = int(request.args.get('tz', '0'))
    if not input_time:
        return error("input parameter is required"), 500
    try:
        input_time = int(input_time)
    except ValueError:
        pass
    try:
        sanitized = Chronyk(input_time, timezone=tz)
    except:
        return error("Timeslate does not accept this input format."), 500
    output = {'ctime': sanitized.ctime(),
              'timestring': sanitized.timestring(),
              'timestamp': sanitized.timestamp(),
              'input': input_time}
    if output_format:
        output['formatted'] = sanitized.timestring(output_format)
    return json.dumps(output)
Пример #3
0
def timeslate():
    input_time = request.args.get('input')
    output_format = request.args.get('format')
    tz = int(request.args.get('tz', '0'))
    if not input_time:
        return error("input parameter is required"), 500
    try:
        input_time = int(input_time)
    except ValueError:
        pass
    try:
        sanitized = Chronyk(input_time, timezone=tz)
    except:
        return error("Timeslate does not accept this input format."), 500
    output = {
        'ctime': sanitized.ctime(),
        'timestring': sanitized.timestring(),
        'timestamp': sanitized.timestamp(),
        'input': input_time
    }
    if output_format:
        output['formatted'] = sanitized.timestring(output_format)
    return json.dumps(output)
Пример #4
0
    def do(self, event):
        record = event.record
        timestamp = Chronyk(record[self._time_key])
        tablename = timestamp.timestring(self._table_template)
        tablename = tablename.format(**record)
        if tablename not in self._buffer:
            self._buffer[tablename] = list()

        self._buffer[tablename].append(record)

        if len(self._buffer[tablename]) > self._buffer_size:
            self.flush_one(tablename)

        return event
Пример #5
0
def test_operators_str():
    t = Chronyk()
    assert str(t) == t.timestring()