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 possibility to edit start/end time on entry #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ and use Emacs customization interface to set `reaper-api-key` to the
given value. On the same page at Harvest you should be able to see the
account id you'll need for `reaper-account-id`.

Harvest supports two timer modes to track time via hours duration and via start and end time.
Use `reaper-hours-timer-mode` to customize the timer mode.
Default value is `t` which means hours duration is used to track time.
Set variable to `nil` if you want to track time via start and end time.

## Usage

Use `M-x reaper` to open the buffer (or whatever key sequence you've bound it to).
Expand Down
17 changes: 15 additions & 2 deletions reaper.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
:type 'string
:group 'reaper)

(defcustom reaper-hours-timer-mode t
"Defines if Harvest is configured to track time via duration.
Non-t value means Harvest is configured to track time via start and end time."
:type 'boolean
:group 'reaper)

(defconst reaper--list-format
[("Project" 32 nil)
("Task" 20 nil)
Expand Down Expand Up @@ -189,6 +195,8 @@
(cons :task (reaper-alist-get '(task name) entry))
(cons :is_running (reaper-alist-get '(is_running) entry))
(cons :hours (reaper-alist-get '(hours) entry))
(cons :started_time (reaper-alist-get '(started_time) entry))
(cons :ended_time (reaper-alist-get '(ended_time) entry))
(cons :notes (let ((notes (reaper-alist-get '(notes) entry)))
(if notes (decode-coding-string notes 'utf-8) ""))))))
;; API returns newest entry first. Simply reverse the list.
Expand Down Expand Up @@ -415,9 +423,14 @@ Stops any previously running timers."
(entry (assoc entry-id reaper-timeentries))
;; If the timer is running add the time since the data was fetched.
(time (reaper--hours-to-time (reaper--hours-accounting-for-running-timer entry)))
(new-time (reaper--time-to-hours-calculation (read-string "New time: " time)))
(start-time (cdr (assoc :started_time entry)))
(end-time (cdr (assoc :ended_time entry)))
(harvest-payload (make-hash-table :test 'equal)))
(puthash "hours" new-time harvest-payload)
(if reaper-hours-timer-mode
(puthash "hours" (reaper--time-to-hours-calculation (read-string "New time: " time)) harvest-payload)
(progn
(puthash "started_time" (read-string "New start time: " start-time) harvest-payload)
(puthash "ended_time" (read-string "New end time: " end-time) harvest-payload)))
(reaper-api "PATCH" (format "time_entries/%s" entry-id) harvest-payload "Updated entry")
(reaper-refresh)))

Expand Down