Esempio n. 1
0
def test_parse_timespec0005(monkeypatch):
    """Test parsing minutes"""

    freeze_time(monkeypatch)
    tf = TimeFilter.from_arg("2M:1M")
    assert tf.start == TimeFilter.now() - timedelta(minutes=2)
    assert tf.stop == TimeFilter.now() - timedelta(minutes=1)
Esempio n. 2
0
def test_parse_timespec0004(monkeypatch):
    """Test parsing hours"""

    freeze_time(monkeypatch)
    tf = TimeFilter.from_arg("2h:1h")
    assert tf.start == TimeFilter.now() - timedelta(hours=2)
    assert tf.stop == TimeFilter.now() - timedelta(hours=1)
Esempio n. 3
0
def test_parse_timespec0003(monkeypatch):
    """Test parsing days"""

    freeze_time(monkeypatch)
    tf = TimeFilter.from_arg("2d:1d")
    assert tf.start == TimeFilter.now() - timedelta(days=2)
    assert tf.stop == TimeFilter.now() - timedelta(days=1)
Esempio n. 4
0
def test_parse_timespec0002(monkeypatch):
    """Test parsing months"""

    freeze_time(monkeypatch)
    tf = TimeFilter.from_arg("2m:1m")
    assert tf.start == TimeFilter.now() - timedelta(days=2 * 31)
    assert tf.stop == TimeFilter.now() - timedelta(days=31)
Esempio n. 5
0
def test_parse_timespec0001(monkeypatch):
    """Test parsing years"""

    freeze_time(monkeypatch)
    tf = TimeFilter.from_arg("2y:1y")
    assert tf.start == TimeFilter.now() - timedelta(days=2 * 365)
    assert tf.stop == TimeFilter.now() - timedelta(days=365)
Esempio n. 6
0
def test_time_filter0001(jrnl):  # noqa: F811
    """Test ':' is unrestricted"""

    filters = FilterSettings(time_filter=TimeFilter.from_arg(":"))
    insert_entry(jrnl, title="hello1", time=datetime.datetime.min)
    insert_entry(jrnl, title="hello2", time=datetime.datetime.max)
    insert_entry(jrnl, title="hello3")
    ents = jrnl._collect_entries(filters=filters)

    assert len(ents) == 3
Esempio n. 7
0
def test_time_filter0003(jrnl, now):  # noqa: F811
    """Test relative end time"""

    filters = FilterSettings(time_filter=TimeFilter.from_arg(":1d"))
    path1 = insert_entry(jrnl, title="old", time=now - timedelta(days=3))
    insert_entry(jrnl, title="new")
    ents = jrnl._collect_entries(filters)

    assert len(ents) == 1
    assert ents[0].path == path1
Esempio n. 8
0
def test_time_filter0006(jrnl, now):  # noqa: F811
    """Test absolute end time"""

    tstr = (now - timedelta(days=1)).strftime(":%Y-%m-%d")
    filters = FilterSettings(time_filter=TimeFilter.from_arg(tstr))
    path1 = insert_entry(jrnl, title="old", time=now - timedelta(days=3))
    insert_entry(jrnl, title="new")
    ents = jrnl._collect_entries(filters)

    assert len(ents) == 1
    assert ents[0].path == path1
Esempio n. 9
0
def test_time_filter0009(jrnl, now):  # noqa: F811
    """Checks that a immortal entry unconditionally passes the time filter"""

    tstr = (now - timedelta(days=2)).strftime("%Y-%m-%d")
    filters = FilterSettings(time_filter=TimeFilter.from_arg(tstr))
    path = insert_entry(jrnl,
                        title="old_immortal",
                        time=now - timedelta(days=500 * 365),
                        attrs="immortal")

    ents = jrnl._collect_entries(filters)
    assert len(ents) == 1
    assert ents[0].path == path
Esempio n. 10
0
def test_time_filter0008(jrnl, now):  # noqa: F811
    """Test absolute start and end time"""

    tstr1 = (now - timedelta(days=2)).strftime("%Y-%m-%d")
    tstr2 = (now - timedelta(days=1)).strftime("%Y-%m-%d")
    tstr = "%s:%s" % (tstr1, tstr2)
    filters = FilterSettings(time_filter=TimeFilter.from_arg(tstr))
    insert_entry(jrnl, title="old", time=now - timedelta(days=5))
    path2 = insert_entry(jrnl, title="new", time=now - timedelta(days=2))
    insert_entry(jrnl, title="newer", time=now + timedelta(days=5))
    ents = jrnl._collect_entries(filters)

    assert len(ents) == 1
    assert ents[0].path == path2