diff --git a/backend/backend.go b/backend/backend.go index a55a83d..9ba9ae4 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -10,21 +10,29 @@ import ( "time" ) -func getLocalTime() time.Time { +// Returns the current time in the timezone specified in the config file +func GetLocalTime() time.Time { timezone, _ := time.LoadLocation(globals.AppConfig.Timezone) return time.Now().In(timezone) } -func getLocalTimePretty() string { - return getLocalTime().Format("02.01.2006 15:04") +// Returns the current localtime in the RFC3339 format +func GetLocalTimeRFC() string { + return GetLocalTime().Format(time.RFC3339) +} + +// Returns the current localtime in custom pretty print format +func GetLocalTimePretty() string { + return GetLocalTime().Format("02.01.2006 15:04") } func LogLine(message string) { - logline := "\n" + getLocalTime().Format(time.RFC3339) + " - " + message + logline := "\n" + GetLocalTimeRFC() + " - " + message globals.LogFile.WriteString(logline) } // Helper for configReader() that does the actual reading +// // Also validates the populated fields func configReaderParse(filePath string, configOptionStorage *globals.Config) error { jsonData, err := os.ReadFile(filePath) @@ -45,9 +53,11 @@ func configValidator(config globals.Config) error { } // Reads config file and stores the options in configOptionStorage -// Tries executable/path/configFileName -// %LOCALAPPDATA%\servtex\configFileName -// ~/.config/servtex/configFileName +// +// Tries the following paths +// executable/path/configFileName +// %LOCALAPPDATA%\servtex\configFileName +// ~/.config/servtex/configFileName func ConfigReader(configFileName string, configOptionStorage *globals.Config) error { exePath, err := os.Executable() if err == nil { @@ -71,6 +81,7 @@ func ConfigReader(configFileName string, configOptionStorage *globals.Config) er } // Watches a specified directory and calls a function on change +// // Optionally, a minimum time to wait for consecutive changes can be specified func ChangeWatch(path string, callOnChange func()) { LogLine("File change noticed") @@ -97,7 +108,7 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro default: execution.ExecutionState = "Unknown Latex Engine" execution.Output = []byte{} - execution.Timestamp = getLocalTimePretty() + execution.Timestamp = GetLocalTimePretty() execution.ExecutionLock.Unlock() return errors.New("Unknown Latex Engine") } @@ -110,7 +121,7 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro } execution.Output = stdout - execution.Timestamp = getLocalTimePretty() + execution.Timestamp = GetLocalTimePretty() execution.ExecutionState = "Done" execution.ExecutionLock.Unlock() return nil diff --git a/frontend/templates/body.html b/frontend/templates/body.html index 8544776..5d12c8e 100644 --- a/frontend/templates/body.html +++ b/frontend/templates/body.html @@ -2,17 +2,17 @@