How to use the humanize.time.date_and_delta function in humanize

To help you get started, we’ve selected a few humanize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmoiron / humanize / tests / test_time.py View on Github external
def test_date_and_delta():
    now = dt.datetime.now()
    td = dt.timedelta
    int_tests = (3, 29, 86399, 86400, 86401 * 30)
    date_tests = [now - td(seconds=x) for x in int_tests]
    td_tests = [td(seconds=x) for x in int_tests]
    results = [(now - td(seconds=x), td(seconds=x)) for x in int_tests]
    for t in (int_tests, date_tests, td_tests):
        for arg, result in zip(t, results):
            date, d = time.date_and_delta(arg)
            assertEqualDatetime(date, result[0])
            assertEqualTimedelta(d, result[1])
    assert time.date_and_delta("NaN") == (None, "NaN")
github jmoiron / humanize / tests / test_time.py View on Github external
def test_date_and_delta():
    now = dt.datetime.now()
    td = dt.timedelta
    int_tests = (3, 29, 86399, 86400, 86401 * 30)
    date_tests = [now - td(seconds=x) for x in int_tests]
    td_tests = [td(seconds=x) for x in int_tests]
    results = [(now - td(seconds=x), td(seconds=x)) for x in int_tests]
    for t in (int_tests, date_tests, td_tests):
        for arg, result in zip(t, results):
            date, d = time.date_and_delta(arg)
            assertEqualDatetime(date, result[0])
            assertEqualTimedelta(d, result[1])
    assert time.date_and_delta("NaN") == (None, "NaN")