Improved events order
This commit is contained in:
parent
be0a30298d
commit
5255206cf4
|
@ -16,7 +16,7 @@ logger = getLogger(__name__)
|
|||
StatisticKey = str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@dataclasses.dataclass(frozen=True, order=True)
|
||||
class Event:
|
||||
start_time: datetime.time | None
|
||||
end_time: datetime.time | None
|
||||
|
@ -48,6 +48,8 @@ FILE_FORMAT = """
|
|||
{blocks_post_events}
|
||||
"""
|
||||
|
||||
MIDNIGHT = datetime.time(0,0,0)
|
||||
|
||||
|
||||
class ObsidianVault:
|
||||
def __init__(self, vault_path: Path, read_only: bool = 'silent'):
|
||||
|
@ -158,7 +160,9 @@ class ObsidianVault:
|
|||
MARKDOWN_RENDERER.render(b) for b in contents.blocks_post_events
|
||||
)
|
||||
|
||||
events = sorted(contents.events, key=lambda x: x.start_time or x.end_time)
|
||||
events = list(contents.events)
|
||||
events.sort()
|
||||
events.sort(key=lambda x: x.start_time or x.end_time or MIDNIGHT)
|
||||
block_events = '\n'.join(
|
||||
'- ' + format_event_string(e) for e in events
|
||||
)
|
||||
|
@ -235,8 +239,7 @@ def format_event_string(event: Event) -> str:
|
|||
buf.append(event.verb)
|
||||
buf.append(' [[')
|
||||
buf.append(event.subject)
|
||||
buf.append(']].')
|
||||
buf.append((' ' + event.comment).strip())
|
||||
buf.append((']]. ' + event.comment).strip())
|
||||
|
||||
return ''.join(buf)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user