Add helper function to parse taskwarrior timestamps

This commit is contained in:
Patrick Winter 2019-11-07 19:01:18 +01:00
parent 738d01b6b9
commit 3e5dea2aaf
2 changed files with 23 additions and 0 deletions

View file

@ -471,5 +471,23 @@
("w" "wait" taskwarrior-set-wait)
("u" "until" taskwarrior-set-untl)]])
(defun taskwarrior--parse-date (timestamp &optional format)
"Parse a taskwarrior TIMESTAMP into a readable string with FORMAT."
(let* ((format (or format :date))
(datetime (timezone-parse-date timestamp))
(year (elt datetime 0))
(month (elt datetime 1))
(day (elt datetime 2))
(time (timezone-parse-time (elt datetime 3)))
(hour (elt time 0))
(minute (elt time 1))
(second (elt time 2)))
(cond
((eq format :date)
(format "%s-%s-%s" day month year hour minute second))
((eq format :datetime)
(format "%s-%s-%s %s:%s:%s" day month year hour minute second)))))
(provide 'taskwarrior)
;;; taskwarrior.el ends here

View file

@ -23,6 +23,11 @@
(should (string= (taskwarrior--parse-created-task-id "Created task 1000.") "1000"))
(should (string= (taskwarrior--parse-created-task-id "Some invalid input") nil)))
(ert-deftest taskwarrior--parse-date ()
(should (string= (taskwarrior--parse-date "20191108T225959Z") "08-11-2019"))
(should (string= (taskwarrior--parse-date "20191108T225959Z" :date) "08-11-2019"))
(should (string= (taskwarrior--parse-date "20191108T225959Z" :datetime) "08-11-2019 22:59:59")))
(provide 'taskwarrior-test)
;;; taskwarrior-test.el ends here