I believe that file.stat().st_time
is a POSIX timestamp (i.e. a number, whether int
or float
).
Therefore it would seem to me that it is the very definition of a timezone-naive value.
Unless... bearing in mind that a file can be saved on one OS and then copied/moved to another (and from one timezone to another for that matter)... So unless you can be sure that every way of saving a file in every possible OS takes the trouble to stamp with a UTC value... which seems not to be the case: see here, for example. Windoze (surprise!) does not consistently seem to save with UTC values.
I note that the questioner references the "Unix epoch", although it is not clear what his OS is. But as I say, even a Unix OS user can receive a file from somewhere else.
So it seems to me that there is no justification to transform this value into a timezone-aware value. Instead:
naive_last_modif_datetime = datetime.fromtimestamp(path.stat().st_mtime)
It is in fact terribly misleading to let a false validation (in this case of tz-awareness of a datetime
) be slipped in inadvertently like this, and could lead to some very strange and baffling anomalies down the line.