Ejemplo n.º 1
0
        def test_from_absolute_DDMMYYHHmmss(self):
            datetime = "13/12/21 11:23:45"
            from_absolute = XArrow.from_absolute(datetime)
            assert from_absolute.day == 13
            assert from_absolute.month == 12
            assert from_absolute.year == 2021
            assert from_absolute.hour == 11
            assert from_absolute.minute == 23
            assert from_absolute.second == 45

            datetime = "13/12 11:23:45"
            from_absolute = XArrow.from_absolute(datetime)
            assert from_absolute.day == 13
            assert from_absolute.month == 12
            assert from_absolute.hour == 11
            assert from_absolute.minute == 23
            assert from_absolute.second == 45

            datetime = "13/12/21 11:23"
            from_absolute = XArrow.from_absolute(datetime)
            assert from_absolute.day == 13
            assert from_absolute.month == 12
            assert from_absolute.year == 2021
            assert from_absolute.hour == 11
            assert from_absolute.minute == 23
            assert from_absolute.second == 0

            datetime = "13/12 11:23"
            from_absolute = XArrow.from_absolute(datetime)
            assert from_absolute.day == 13
            assert from_absolute.month == 12
            assert from_absolute.hour == 11
            assert from_absolute.minute == 23
            assert from_absolute.second == 00
Ejemplo n.º 2
0
def test_arrows2rel_time():
    present = XArrow.now()
    past = present.shift(weeks=-3, days=-3)
    assert arrows2rel_time(present, past) == '3 weeks & 3 days ago'

    present = XArrow.from_absolute('21/12/21')
    past = XArrow.from_absolute('01/12/21')
    secs = int((present - past).total_seconds())
    assert 20 * 24 * 3600 <= secs <= 21 * 24 * 3600
    ret = arrows2rel_time(present, past)
    assert ret == '2 weeks & 6 days ago'
Ejemplo n.º 3
0
        def test_from_absolute_HHmmss(self):
            HHmmss = "02:00:00"
            from_absolute = XArrow.from_absolute(HHmmss)
            assert from_absolute.hour == 2
            assert from_absolute.minute == 0
            assert from_absolute.second == 0

            HHmmss = "02:53:49"
            from_absolute = XArrow.from_absolute(HHmmss)
            assert from_absolute.hour == 2
            assert from_absolute.minute == 53
            assert from_absolute.second == 49
Ejemplo n.º 4
0
    def test_on_got_to_office_08_20(self):
        work = Work()
        '''{ "02/11/21" : Day }'''
        assert isinstance(work, Work)
        assert isinstance(work, dict)
        assert not work
        assert len(work) == 0

        entry = Entry(start="02:20")
        assert entry
        assert entry.start
        assert isinstance(entry.start, XArrow)
        absolute = XArrow.from_absolute("02:20")
        entry_start = entry.start
        assert_arrows_soft_eq(entry_start, absolute)

        name = "Got to office"
        activity = Activity(name=name)
        assert not activity  # because list
        assert len(activity) == 0
        assert isinstance(activity.name, Colored)
        assert activity.name == name

        activity.append(entry)
        assert activity
        assert len(activity) == 1
        assert activity[0] == entry

        day = work[entry.start.DDMMYY]
        assert isinstance(day, Day)
        day[name] = activity
        assert day[
            name] == activity, f"{day[str(activity.name)] = }, {activity = }"
        assert work
        assert len(work) == 1
Ejemplo n.º 5
0
        def test_from_absolute_now(self):
            now = XArrow.now().replace(second=0)
            from_absolute_now = XArrow.from_absolute(now)
            assert_arrows_soft_eq(from_absolute_now, now)
            assert from_absolute_now is now

            for fmt in [  # FORMATS.date,
                    # FORMATS.short_date:       ['month', 'day'],
                    FORMATS.time,
                    FORMATS.short_time,
                    # FORMATS.datetime:         ['year', 'month', 'day', 'hour', 'minute', 'second'],
                    # FORMATS.shorter_datetime: ['year', 'month', 'day', 'hour', 'minute'],
                    # FORMATS.short_datetime:   ['month', 'day', 'hour', 'minute'],
            ]:
                formatted = now.format(fmt)
                from_absolute_formatted: XArrow = XArrow.from_absolute(
                    formatted)
                assert_arrows_soft_eq(from_absolute_formatted, now)
Ejemplo n.º 6
0
 def test_init_with_all_fields(self):
     entry = Entry(start="02:00:00",
                   end="03:00:00",
                   synced=True,
                   notes=[{
                       "02:30:00": "PR-5000"
                   }],
                   tags=["meeting"])
     assert entry
     assert entry.start == XArrow.from_absolute("02:00:00")
     assert entry.end == XArrow.from_absolute("03:00:00")
     assert entry.synced is True
     assert entry.notes
     assert isinstance(entry.notes, list)
     assert entry.notes == [Note({"02:30:00": "PR-5000"})]
     assert isinstance(entry.notes[0], Note)
     assert entry.notes[0] == Note({"02:30:00": "PR-5000"})
     assert entry.notes[0].time == XArrow.from_absolute("02:30:00")
     assert entry.notes[0].content == "PR-5000"
     assert entry.tags == [Tag("meeting")]
     assert next(iter(entry.tags)) == Tag("meeting")
     assert isinstance(next(iter(entry.tags)), Tag)
Ejemplo n.º 7
0
 def test_sanity(self):
     note = Note({"17:00": "PR-6091"})
     assert isinstance(note.time, XArrow)
     assert note.time == XArrow.from_absolute("17:00")
     assert note.time.hour == 17
     assert note.time.minute == 0
     assert note.time.second == 0, note.time.second
     assert note.content == "PR-6091"
     if not os.getenv('TIMEFRED_REPR', '').lower() in ('no', 'disable'):
         assert repr(
             note
         ) == f"Note(content = 'PR-6091', time = XArrow ⟨{TEST_START_ARROW.DDMMYY} 17:00:00⟩)", repr(
             note)
Ejemplo n.º 8
0
def test_log_01_12_21(capsys):
    raw_data = dedent('''
    ["01/12/21"]
    "Got to office" = "10:00"
    
    [["01/12/21"."Integration"]]
    synced = true
    start = 10:30:00
    end = 11:00:00
    
    [["01/12/21"."Integration"]]
    synced = true
    start = 11:20:00
    end = 11:40:00
    
    [["01/12/21"."Integration - Weak WIFI Password"]]
    synced = true
    start = 13:30:00
    end = 13:40:00
    notes = {"13:40:00" = "With Vlad, tested, done, everything as expected"}
    
    [["01/12/21"."immediate endTime quiet time default value is empty str"]]
    start = 14:00:00
    end = 17:30:00
    jira = "ASM-13925"
    synced = true
    ''')
    sheet_path = '/tmp/timefred-sheet--test-action--test-log--test-log-01-12-21.toml'
    with open(sheet_path, 'w') as sheet:
        sheet.write(raw_data)

    with temp_sheet(sheet_path):
        log_action('01/12/21')

    captured = capsys.readouterr()
    output = captured.out
    output_lines = output.splitlines()
    now = XArrow.now()
    past = XArrow.from_absolute('01/12/21')
    from timefred.time.timeutils import arrows2rel_time
    assert decolor(output_lines[0]
                   ) == f'Wednesday, 01/12/21 | {arrows2rel_time(now, past)}'
Ejemplo n.º 9
0
        def test_from_absolute_time(self):
            from datetime import time
            abs_time = time(hour=11, minute=0, second=0)
            from_absolute = XArrow.from_absolute(abs_time)
            assert from_absolute.hour == 11
            assert from_absolute.minute == 0
            assert from_absolute.second == 0

            abs_time = time(hour=11, minute=23, second=0)
            from_absolute = XArrow.from_absolute(abs_time)
            assert from_absolute.hour == 11
            assert from_absolute.minute == 23
            assert from_absolute.second == 0

            abs_time = time(hour=11, minute=23, second=45)
            from_absolute = XArrow.from_absolute(abs_time)
            assert from_absolute.hour == 11
            assert from_absolute.minute == 23
            assert from_absolute.second == 45

            abs_time = time(hour=11, minute=0, second=45)
            from_absolute = XArrow.from_absolute(abs_time)
            assert from_absolute.hour == 11
            assert from_absolute.minute == 0
            assert from_absolute.second == 45

            abs_time = time(hour=0, minute=0, second=45)
            from_absolute = XArrow.from_absolute(abs_time)
            assert from_absolute.hour == 0
            assert from_absolute.minute == 0
            assert from_absolute.second == 45

            abs_time = time(hour=0, minute=23, second=45)
            from_absolute = XArrow.from_absolute(abs_time)
            assert from_absolute.hour == 0
            assert from_absolute.minute == 23
            assert from_absolute.second == 45
Ejemplo n.º 10
0
 def test_from_absolute_DDMMYY(self):
     DDMMYY = "13/12/21"
     from_absolute = XArrow.from_absolute(DDMMYY)
     assert from_absolute.day == 13
     assert from_absolute.month == 12
     assert from_absolute.year == 2021
Ejemplo n.º 11
0
 def test_from_absolute_HHmm(self):
     HHmm = "02:00"
     from_absolute = XArrow.from_absolute(HHmm)
     assert from_absolute.hour == 2
     assert from_absolute.minute == 0
     assert from_absolute.second == 0