Coverage for pyguymer3/getmtime.py: 25%

4 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def getmtime( 

5 fname, 

6 /, 

7): 

8 """Get the modification time of a file as a timezone-aware datetime object. 

9 

10 This function aims to mimic ``os.path.getmtime()`` but instead of returning 

11 a integer or float it returns a timezone-aware ``datetime`` object. 

12 

13 Parameters 

14 ---------- 

15 fname : str 

16 the file name 

17 

18 Returns 

19 ------- 

20 ans : datetime.datetime 

21 the timezone-aware ``datetime`` object 

22 

23 Notes 

24 ----- 

25 Copyright 2017 Thomas Guymer [1]_ 

26 

27 References 

28 ---------- 

29 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3 

30 """ 

31 

32 # Import standard modules ... 

33 import datetime 

34 import os 

35 

36 # Return answer ... 

37 return datetime.datetime.fromtimestamp( 

38 os.path.getmtime(fname), 

39 tz = datetime.UTC, 

40 )