Add helper function to parse taskwarrior timestamps
This commit is contained in:
parent
738d01b6b9
commit
3e5dea2aaf
2 changed files with 23 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue