diff --git a/lua/pendulum/handlers.lua b/lua/pendulum/handlers.lua index 633c81d..90abc92 100644 --- a/lua/pendulum/handlers.lua +++ b/lua/pendulum/handlers.lua @@ -51,15 +51,14 @@ end ---@param active_time integer? ---@return table local function log_activity(is_active, opts, active_time) - -- TODO: allow adding a specific time, (last active, but in actual datetime format) - -- https://stackoverflow.com/questions/32022898/subtracting-hours-from-os-date local _ = active_time local ft = vim.bo.filetype if ft == "" then ft = "unknown_filetype" end local data = { - time = vim.fn.strftime("%Y-%m-%d %H:%M:%S"), + -- time = vim.fn.strftime("%Y-%m-%d %H:%M:%S"), -- Use local time zone instead + time = os.date("!%Y-%m-%d %H:%M:%S"), active = tostring(is_active), -- file = vim.fn.expand("%:t+"), -- only file name file = vim.fn.expand("%:p"), -- file name with path diff --git a/remote/internal/metrics.go b/remote/internal/metrics.go index 0c060ea..8e64ae2 100644 --- a/remote/internal/metrics.go +++ b/remote/internal/metrics.go @@ -155,14 +155,11 @@ func aggregatePendulumMetric( log.Printf("Error parsing boolean at row %d, value: %s, error: %v", i, data[i][0], err) } - // FIX: hour timeframe is broken (likely others as well -- probably caused by timezones) // TODO: add header to popup window showing the timeframe used (in buffer.go) - // PERF: this check anecdotally makes the popup feel slower inRange, err := isTimestampInRange(data[i][timecol], rangeType) if err != nil { return } - if !inRange { continue } diff --git a/remote/internal/utils.go b/remote/internal/utils.go index 38875e5..aa1026b 100644 --- a/remote/internal/utils.go +++ b/remote/internal/utils.go @@ -70,16 +70,16 @@ func truncatePath(path string) string { } // DOC: -// FIX: potential time zone issue (hour timeframe is empty) func isTimestampInRange(timestampStr, rangeType string) (bool, error) { layout := "2006-01-02 15:04:05" + // WARN: input timestamp format has to be in UTC for hour filtering (or allow a TZ config option) timestamp, err := time.Parse(layout, timestampStr) if err != nil { return false, fmt.Errorf("error parsing timestamp: %v", err) } - now := time.Now() + now := time.Now().UTC() var startOfRange, endOfRange time.Time @@ -103,7 +103,7 @@ func isTimestampInRange(timestampStr, rangeType string) (bool, error) { startOfRange = startOfWeek.AddDate(0, 0, (week-1)*7) endOfRange = startOfRange.Add(7 * 24 * time.Hour).Add(-time.Nanosecond) case "hour": - startOfRange = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) + startOfRange = time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-1, now.Minute(), now.Second(), 0, now.Location()) endOfRange = startOfRange.Add(1 * time.Hour).Add(-time.Nanosecond) default: // default to "all" range if input is invalid or not provided