Skip to content

Commit

Permalink
Added custom variable to switch between Harvest time modes.
Browse files Browse the repository at this point in the history
  • Loading branch information
akoppela committed Sep 9, 2019
1 parent 7497669 commit 9e665e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
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 customize `reaper-api-key` to the given value. On the same page
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
25 changes: 10 additions & 15 deletions reaper.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
: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 @@ -392,24 +398,13 @@ 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 (read-string "New time: " time)))
(harvest-payload (make-hash-table :test 'equal)))
(puthash "hours" new-time harvest-payload)
(reaper-api "PATCH" (format "time_entries/%s" entry-id) harvest-payload "Updated entry")
(reaper-refresh)))

(defun reaper-edit-entry-start-end-time ()
"Edit start/end time of entry at point."
(interactive)
(let* ((entry-id (tabulated-list-get-id))
(entry (assoc entry-id reaper-timeentries))
(start-time (cdr (assoc :started_time entry)))
(new-start-time (read-string "New start time: " start-time))
(end-time (cdr (assoc :ended_time entry)))
(new-end-time (read-string "New end time: " end-time))
(harvest-payload (make-hash-table :test 'equal)))
(puthash "started_time" new-start-time harvest-payload)
(puthash "ended_time" new-end-time harvest-payload)
(if reaper-hours-timer-mode
(puthash "hours" (reaper--time-to-hours (read-string "New time: " time)) harvest-payload)
(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

0 comments on commit 9e665e1

Please sign in to comment.