Skip to content

Commit

Permalink
fix(PreviewPanel): Use birthtime for creation time
Browse files Browse the repository at this point in the history
st_ctime does not provide accurate creation time on MacOS, and as of
Python 3.12 is deprecated for Windows. On these two platforms use
st_birthtime, but fall back to st_ctime on linux.
  • Loading branch information
seakrueger committed Sep 8, 2024
1 parent fc714e0 commit e5d8c0a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tagstudio/src/qt/widgets/preview_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ def add_field_to_selected(self, field_list: list[QModelIndex]):
def update_date_label(self, filepath: Path | None = None) -> None:
"""Update the "Date Created" and "Date Modified" file property labels."""
if filepath and filepath.is_file():
created: dt = dt.fromtimestamp(filepath.stat().st_ctime)
if platform.system() == "Windows" or platform.system() == "Darwin":
created: dt = dt.fromtimestamp(filepath.stat().st_birthtime)

Check failure on line 496 in tagstudio/src/qt/widgets/preview_panel.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] tagstudio/src/qt/widgets/preview_panel.py#L496

"stat_result" has no attribute "st_birthtime" [attr-defined]
Raw output
/home/runner/work/TagStudio/TagStudio/tagstudio/src/qt/widgets/preview_panel.py:496:48: error: "stat_result" has no attribute "st_birthtime"  [attr-defined]
else:
created: dt = dt.fromtimestamp(filepath.stat().st_ctime)

Check failure on line 498 in tagstudio/src/qt/widgets/preview_panel.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] tagstudio/src/qt/widgets/preview_panel.py#L498

Name "created" already defined on line 496 [no-redef]
Raw output
/home/runner/work/TagStudio/TagStudio/tagstudio/src/qt/widgets/preview_panel.py:498:17: error: Name "created" already defined on line 496  [no-redef]
modified: dt = dt.fromtimestamp(filepath.stat().st_mtime)
self.date_created_label.setText(
f"<b>Date Created:</b> {dt.strftime(created, "%a, %x, %X")}"
Expand Down

0 comments on commit e5d8c0a

Please sign in to comment.