From f268afe2d4e00482fc7612d312eb7a744bd8eb7b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 12 Sep 2022 21:42:58 +0200 Subject: add Cask dep persist --- Cask | 1 + 1 file changed, 1 insertion(+) (limited to 'Cask') diff --git a/Cask b/Cask index 3f7825f..a960f81 100644 --- a/Cask +++ b/Cask @@ -6,6 +6,7 @@ (depends-on "request" "0.3.0") (depends-on "seq") +(depends-on "persist") (development (depends-on "ert-runner") -- cgit v1.2.3 From 10c5926d75a67ab799e63f896546f54e3706d65d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 5 Nov 2022 13:39:31 +0100 Subject: use ts library to format poll expiry --- Cask | 1 + lisp/mastodon-tl.el | 22 ++++++++++++---------- lisp/mastodon.el | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'Cask') diff --git a/Cask b/Cask index a960f81..c193326 100644 --- a/Cask +++ b/Cask @@ -7,6 +7,7 @@ (depends-on "request" "0.3.0") (depends-on "seq") (depends-on "persist") +(depends-on "ts") (development (depends-on "ert-runner") diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2db5700..6f53f93 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -5,7 +5,7 @@ ;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 -;; Package-Requires: ((emacs "27.1")) +;; Package-Requires: ((emacs "27.1") (ts "0.3")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. @@ -32,6 +32,7 @@ ;;; Code: (require 'shr) +(require 'ts) (require 'thingatpt) ; for word-at-point (require 'time-date) (require 'cl-lib) @@ -982,19 +983,20 @@ this just means displaying toot client." 'face 'font-lock-comment-face) (let ((str (if expired-p "Poll expired." - (matodon-tl--format-poll-expiry expiry)))) + (mastodon-tl--format-poll-expiry expiry)))) (propertize str 'face 'font-lock-comment-face)) "\n"))) -(defun matodon-tl--format-poll-expiry (timestamp) +(defun mastodon-tl--format-poll-expiry (timestamp) "Convert poll expiry TIMESTAMP into a descriptive string." - (let ((parsed (iso8601-parse timestamp))) - (cond ((> (decoded-time-day parsed) 0) - (format "%s days left" (decoded-time-day parsed))) - ((> (decoded-time-hour parsed) 0) - (format "%s hours left" (decoded-time-hour parsed))) - ((> (decoded-time-minute parsed) 0) - (format "%s minutes left" (decoded-time-minute parsed)))))) + (let ((parsed (ts-human-duration + (ts-diff (ts-parse timestamp) (ts-now))))) + (cond ((> (plist-get parsed :days) 0) + (format "%s days, %s hours left" (plist-get parsed :days) (plist-get parsed :hours))) + ((> (plist-get parsed :hours) 0) + (format "%s hours, %s minutes left" (plist-get parsed :hours) (plist-get parsed :minutes))) + ((> (plist-get parsed :minutes) 0) + (format "%s minutes left" (plist-get parsed :minutes)))))) (defun mastodon-tl--poll-vote (option) "If there is a poll at point, prompt user for OPTION to vote on it." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a5ba9e4..5ec48b6 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -5,7 +5,7 @@ ;; Author: Johnson Denen ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 -;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4")) +;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4") (ts "0.3")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. -- cgit v1.2.3