Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

update git log time formatting to display local time locally

Dane Schneiderfbeaabbcf3ee
diff --git a/app/cli/cmd/log.go b/app/cli/cmd/log.go
index 0a9c636c..f1596916 100644
--- a/app/cli/cmd/log.go
+++ b/app/cli/cmd/log.go
@@ -6,6 +6,8 @@ import (
"plandex/auth"
"plandex/lib"
"plandex/term"
+ "regexp"
+ "time"
"github.com/spf13/cobra"
)
@@ -34,11 +36,51 @@ func runLog(cmd *cobra.Command, args []string) {
return
}
- res, err := api.Client.ListLogs(lib.CurrentPlanId, lib.CurrentBranch)
+ res, apiErr := api.Client.ListLogs(lib.CurrentPlanId, lib.CurrentBranch)
+ if apiErr != nil {
+ fmt.Printf("Error getting logs: %v\n", apiErr)
+ return
+ }
+
+ withLocalTimestamps, err := convertTimestampsToLocal(res.Body)
+
if err != nil {
- fmt.Printf("Error: %v\n", err)
+ fmt.Printf("Error converting timestamps: %v\n", err)
return
}
- term.PageOutput(res.Body)
+ term.PageOutput(withLocalTimestamps)
+}
+
+func convertTimestampsToLocal(input string) (string, error) {
+ t := time.Now()
+ zone, _ := t.Zone()
+
+ parseFmt := "3:04:05pm UTC"
+ re := regexp.MustCompile(`\d{1,2}:\d{2}:\d{2}(am|pm) UTC`)
+
+ // Function to convert matched timestamps assuming they are in UTC to local time.
+ replaceFunc := func(match string) string {
+ t, err := time.Parse(parseFmt, match)
+ if err != nil {
+ // In case of an error, return the original match.
+ return match
+ }
+
+ localDt := t.Local()
+ formattedTs := localDt.Format("Mon Jan 2, 2006 | 3:04:05pm")
+ if localDt.Day() == time.Now().Day() {
+ formattedTs = localDt.Format("Today | 3:04:05pm")
+ } else if localDt.Day() == time.Now().AddDate(0, 0, -1).Day() {
+ formattedTs = localDt.Format("Yesterday | 3:04:05pm")
+ }
+
+ // Convert to local time and format back to a string without the timezone to match the original format.
+ return formattedTs + " " + zone
+ }
+
+ // Find all matches and replace them.
+ result := re.ReplaceAllStringFunc(input, replaceFunc)
+
+ return result, nil
}
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go
index d047a056..be3e6421 100644
--- a/app/cli/lib/context_load.go
+++ b/app/cli/lib/context_load.go
@@ -90,7 +90,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
}
contextCh <- &shared.LoadContextParams{
- ContextType: shared.ContextFileType,
+ ContextType: shared.ContextDirectoryTreeType,
Name: name,
Body: body,
FilePath: inputFilePath,
diff --git a/app/server/db/git.go b/app/server/db/git.go
index dcac80cd..43a31fca 100644
--- a/app/server/db/git.go
+++ b/app/server/db/git.go
@@ -229,12 +229,7 @@ func processGitHistoryOutput(raw string) [][2]string {
}
dt := time.Unix(timestamp, 0).Local()
- formattedTs := dt.Format("Mon Jan 2, 2006 | 3:04:05pm MST")
- if dt.Day() == time.Now().Day() {
- formattedTs = dt.Format("Today | 3:04:05pm MST")
- } else if dt.Day() == time.Now().AddDate(0, 0, -1).Day() {
- formattedTs = dt.Format("Yesterday | 3:04:05pm MST")
- }
+ formattedTs := dt.Format("3:04:05pm MST")
// Prepare the header with colors.
headerColor := color.New(color.FgCyan, color.Bold)