Skip to content

Commit

Permalink
fix/change: changed logging timestamps to UTC for report filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ptdewey committed Oct 21, 2024
1 parent 5e49f4c commit c84381e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
5 changes: 2 additions & 3 deletions lua/pendulum/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions remote/internal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions remote/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit c84381e

Please sign in to comment.