コード例 #1
0
def test_parse_max_timestamp_when_given_magic_days_parses_successfully():
    actual_date = datetime.utcfromtimestamp(parse_max_timestamp("20d"))
    expected_date = datetime.utcfromtimestamp(
        convert_datetime_to_timestamp(get_test_date(days_ago=20)))
    expected_date = expected_date.replace(hour=23,
                                          minute=59,
                                          second=59,
                                          microsecond=999000)
    assert actual_date == expected_date
コード例 #2
0
def parse_min_timestamp(begin_date_str, max_days_back=90):
    if begin_date_str is None:
        return
    dt = _parse_timestamp(begin_date_str, _round_datetime_to_day_start)
    boundary_date = _round_datetime_to_day_start(
        datetime.utcnow() - timedelta(days=max_days_back)
    )
    if dt < boundary_date:
        raise click.BadParameter(
            message="must be within {} days.".format(max_days_back)
        )
    return convert_datetime_to_timestamp(dt)
コード例 #3
0
def test_parse_magic_minutes_parses_successfully():
    actual = parse_max_timestamp("20m")
    expected = convert_datetime_to_timestamp(get_test_date(minutes_ago=20))
    assert expected - actual < 0.01
コード例 #4
0
def test_parse_max_timestamp_when_given_magic_hours_parses_successfully():
    actual = parse_max_timestamp("20h")
    expected = convert_datetime_to_timestamp(get_test_date(hours_ago=20))
    assert expected - actual < 0.01
コード例 #5
0
def test_parse_max_timestamp_when_given_date_str_with_time_parses_successfully(
):
    actual = parse_min_timestamp(end_date_str_with_time)
    expected = convert_datetime_to_timestamp(
        datetime.strptime(end_date_str_with_time, "%Y-%m-%d %H:%M:%S"))
    assert actual == expected
コード例 #6
0
def test_parse_min_timestamp_when_given_date_str_parses_successfully():
    actual = parse_min_timestamp(begin_date_str)
    expected = convert_datetime_to_timestamp(
        datetime.strptime(begin_date_str, "%Y-%m-%d"))
    assert actual == expected
コード例 #7
0
def parse_max_timestamp(end_date_str):
    if end_date_str is None:
        return
    dt = _parse_timestamp(end_date_str, _round_datetime_to_day_end)
    return convert_datetime_to_timestamp(dt)