Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for setting timezone for timestamps #35

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cmd/ftrove/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func main() {
listSessions := flag.BoolP("list-sessions", "l", false, "List session information for all scans. Useful for exports.")
projectname := flag.StringP("project", "p", "", "A name for the project or scan session.")
resumeuuid := flag.StringP("resume", "r", "", "Resume an aborted session. Provide the session uuid.")
timezone := flag.StringP("timezone", "z", "", "Set the time zone to a region in which the timestamps of files are to be translated. If this flag is not set, the local time zone is used. Example: Europe/Berlin")

// updateFT := flag.BoolP("update-all", "u", false, "Update FileTrove, siegfried and NSRL.")
printversion := flag.BoolP("version", "v", false, "Show version and build.")
Expand Down Expand Up @@ -404,9 +405,21 @@ func main() {
logger.Error("Could not get access, change or birth time for file.", slog.String("error", err.Error()))
}

filemd.Fileatime = filetime.Atime.String()
filemd.Filectime = filetime.Ctime.String()
filemd.Filemtime = filetime.Mtime.String()
// Use specific timezone for the translation of timestamps
if len(*timezone) != 0 {
// Check if timezone string is valid
timeIn, err := time.LoadLocation(*timezone)
if err != nil {
logger.Error("Timezone string is not valid. Example: Europe/Berlin", slog.String("error", err.Error()))
}
filemd.Fileatime = filetime.Atime.In(timeIn).String()
filemd.Filectime = filetime.Ctime.In(timeIn).String()
filemd.Filemtime = filetime.Mtime.In(timeIn).String()
} else {
filemd.Fileatime = filetime.Atime.String()
filemd.Filectime = filetime.Ctime.String()
filemd.Filemtime = filetime.Mtime.String()
}

// Check if the hash sum of the file is in the NSRL.
// We use the db connection created by ft.ConnectNSRL()
Expand Down