Skip to content

Add set of helper methods to simplify work with dates

Piotr Batko requested to merge pbatko/time-utils into master

Add methods which allows:

  • parsing and serialization of dates in hive-supported format (by default) and in custom format (with tt.Time.parse and tt.Time.serialize)
  • define timedeltas (e.g. tt.Time.seconds(5))
  • compare datetimes (tt.Time.are_close(today, tomorrow, absolute_tolerance=tt.Time.days(1)))

It allows to write tests like on example:

def test_startup_with_modified_time():
    requested_start_time = tt.Time.parse('2020-01-01T00:00:00')

    init_node = tt.InitNode()
    init_node.run(time_offset=tt.Time.serialize(requested_start_time, format_=tt.Time.TIME_OFFSET_FORMAT))

    node_time = tt.Time.parse(init_node.api.database.get_dynamic_global_properties()['time'])

    assert tt.Time.are_close(requested_start_time, node_time, absolute_tolerance=tt.Time.seconds(15))
Edited by Piotr Batko

Merge request reports

Loading