From ad8d2abbfc92f217c4bdbd272345803167788344 Mon Sep 17 00:00:00 2001 From: Andrey Koppel Date: Tue, 10 Sep 2019 00:37:55 +0800 Subject: [PATCH 1/2] Added function to edit start/end time of entry. --- reaper.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/reaper.el b/reaper.el index 3e5fe42..122ca9d 100644 --- a/reaper.el +++ b/reaper.el @@ -189,6 +189,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. @@ -421,6 +423,21 @@ Stops any previously running timers." (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) + (reaper-api "PATCH" (format "time_entries/%s" entry-id) harvest-payload "Updated entry") + (reaper-refresh))) + (defun reaper-read-project (&optional default) "Read a project from the user. Default to DEFAULT." (let* ((projects (mapcar (lambda (project) From 5955910b3ad81bdfc566487e662ed2a7e50ae4d9 Mon Sep 17 00:00:00 2001 From: Andrey Koppel Date: Tue, 10 Sep 2019 04:07:44 +0800 Subject: [PATCH 2/2] Added custom variable to switch between Harvest time modes. --- README.md | 5 +++++ reaper.el | 26 +++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 20063f0..ccd4a82 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/reaper.el b/reaper.el index 122ca9d..f778aef 100644 --- a/reaper.el +++ b/reaper.el @@ -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) @@ -417,24 +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))) - (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-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)))