photoprism/pkg/fs/modtime.go
Michael Mayer e5c5ce2348 Metadata: Use file mod time instead of birth time as fallback #4157
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-04-08 20:44:57 +02:00

20 lines
398 B
Go

package fs
import (
"time"
"github.com/djherbis/times"
)
// ModTime returns the last modification time of a file or directory in UTC.
func ModTime(filePath string) time.Time {
stat, err := times.Stat(filePath)
// Return the current time if Stat() call failed.
if err != nil {
return time.Now().UTC()
}
// Return modification time as reported by Stat().
return stat.ModTime().UTC()
}