Skip to content

Commit 8c9b04d

Browse files
authored
fix(ui): use birthtime for creation time on mac & win (#472)
* fix(PreviewPanel): Use birthtime for creation time 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. * mypy errors
1 parent 5995e4d commit 8c9b04d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tagstudio/src/qt/widgets/preview_panel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ def add_field_to_selected(self, field_list: list[QModelIndex]):
492492
def update_date_label(self, filepath: Path | None = None) -> None:
493493
"""Update the "Date Created" and "Date Modified" file property labels."""
494494
if filepath and filepath.is_file():
495-
created: dt = dt.fromtimestamp(filepath.stat().st_ctime)
495+
created: dt = None
496+
if platform.system() == "Windows" or platform.system() == "Darwin":
497+
created = dt.fromtimestamp(filepath.stat().st_birthtime) # type: ignore[attr-defined]
498+
else:
499+
created = dt.fromtimestamp(filepath.stat().st_ctime)
496500
modified: dt = dt.fromtimestamp(filepath.stat().st_mtime)
497501
self.date_created_label.setText(
498502
f"<b>Date Created:</b> {dt.strftime(created, "%a, %x, %X")}"

0 commit comments

Comments
 (0)