Skip to content

Commit

Permalink
Enable ruff DTZ rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tpwo committed Jul 22, 2024
1 parent 11c93e3 commit becb4c6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extend-select = [
"FBT",
"A",
"C4",
# "DTZ",
"DTZ",
"ISC",
"LOG",
"INP",
Expand Down
1 change: 1 addition & 0 deletions src/pyzet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ZETDIR = 'docs'
ZETTEL_FILENAME = 'README.md'

PRETTY_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
ZULU_DATETIME_FORMAT = '%Y%m%d%H%M%S'
ZULU_FORMAT_LEN = 14

Expand Down
3 changes: 2 additions & 1 deletion src/pyzet/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import subprocess
from collections import Counter
from datetime import datetime
from datetime import timezone
from glob import glob
from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -91,7 +92,7 @@ def _is_empty(folder: Path) -> bool:

def add_zettel(config: Config) -> int:
"""Adds zettel and commits changes with zettel title as the message."""
id_ = datetime.utcnow().strftime(C.ZULU_DATETIME_FORMAT)
id_ = datetime.now(tz=timezone.utc).strftime(C.ZULU_DATETIME_FORMAT)

zettel_dir = Path(config.repo, C.ZETDIR, id_)
zettel_dir.mkdir(parents=True, exist_ok=True)
Expand Down
5 changes: 4 additions & 1 deletion src/pyzet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
from argparse import ArgumentParser
from datetime import datetime
from datetime import timezone
from typing import TYPE_CHECKING
from typing import Iterable

Expand Down Expand Up @@ -153,7 +154,9 @@ def valid_id(id_: str) -> str:
f"'{id_}' is not a valid zettel id ({_get_id_err_details(id_)})"
)
try:
datetime.strptime(id_, C.ZULU_DATETIME_FORMAT)
datetime.strptime(id_, C.ZULU_DATETIME_FORMAT).replace(
tzinfo=timezone.utc
)
except ValueError:
raise argparse.ArgumentTypeError(f"'{id_}' is not a valid zettel id")
else:
Expand Down
11 changes: 8 additions & 3 deletions src/pyzet/zettel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import subprocess
from datetime import datetime
from datetime import timezone
from pathlib import Path
from typing import TYPE_CHECKING
from typing import NamedTuple
Expand Down Expand Up @@ -184,9 +185,13 @@ def get_repr(zet: Zettel, args: Namespace) -> str:
return f'{zet.id} -- {zet.title}{tags}'


def get_timestamp(id_: str) -> datetime:
"""Parses zettel ID into a datetime object."""
return datetime.strptime(id_, C.ZULU_DATETIME_FORMAT)
def get_timestamp(id_: str) -> str:
"""Parses zettel ID into a `YYYY-MM-DD HH:MM:SS` str."""
return (
datetime.strptime(id_, C.ZULU_DATETIME_FORMAT)
.replace(tzinfo=timezone.utc)
.strftime(C.PRETTY_DATETIME_FORMAT)
)


def get_md_link(zet: Zettel) -> str:
Expand Down

0 comments on commit becb4c6

Please sign in to comment.