doc(TODO): remove separator parameter
This commit is contained in:
parent
f51ccf7333
commit
23b0376161
37
TODO.org
37
TODO.org
|
@ -489,40 +489,41 @@ Macro creates -
|
|||
Currently we have at least three ways of displaying durations - ="HH:MM:SS"= , ="XhYm"= , and =X hour(s), Y minutes(s)"= . Make a single function similar to =format-time-string=, but for durations. =ts-human-format-duration= from =ts.el= is not nearly as flexible as I'd like. When completed, we can have a single custom variable accepting a format string, which can be used to customize display of durations for the entire application with a uniform interface.
|
||||
|
||||
** spec
|
||||
User provides a duration (in seconds), a format string, and an optional separator string.
|
||||
+ format string - ="<escape character>[<zero value><separator>]<code>"=
|
||||
User provides a format string and a duration (in seconds).
|
||||
+ /format string/ is a mix of /unit specifiers/ and /unit separators/
|
||||
+ a /unit specifier/ is ="<escape character>[<zero value><value separator>]<code>"=
|
||||
* escape character can be either
|
||||
- =~= - no unit strings, e.g.
|
||||
#+BEGIN_SRC emacs-lisp :tangle no :load no
|
||||
(format-duration "~ss" 1) ;; => "1s"
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(format-duration "~ss" 1) ;; => "1s"
|
||||
#+END_SRC
|
||||
or
|
||||
- =%= long unit strings, e.g. "minute". If the value is >1, plurals are used.
|
||||
#+BEGIN_SRC emacs-lisp :tangle no :load no
|
||||
(format-duration "%s" 1) ;; => "1 second"
|
||||
(format-duration "%s" 5) ;; => "5 seconds"
|
||||
(format-duration "%m%s" 5) ;; => "5 seconds"
|
||||
(format-duration "%m%s" 60) ;; => "1 minute"
|
||||
(format-duration "%m%s" 125) ;; => "2 minutes 5 seconds"
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(format-duration "%s" 1) ;; => "1 second"
|
||||
(format-duration "%s" 5) ;; => "5 seconds"
|
||||
#+END_SRC
|
||||
* zero value - what to do when the unit has a value of 0
|
||||
+ with no unit strings
|
||||
- if omitted, print =""= and omit any text in the format string until the next escape character is encountered
|
||||
- if omitted, print =""= and omit the following unit separator, i.e. any text in the format string until the next escape character is encountered
|
||||
- if =0=, print ="0"=
|
||||
+ with long unit strings
|
||||
- if omitted, print =""= for a unit which has a value of 0, e.g. ="3 months"=
|
||||
- if omitted, print =""= for a unit which has a value of 0
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(format-duration "%m %s" 5) ;; => "5 seconds"
|
||||
(format-duration "%m %s" 60) ;; => "1 minute"
|
||||
(format-duration "%m %s" 125) ;; => "2 minutes 5 seconds"
|
||||
#+END_SRC
|
||||
- if =0=, print ="0 <units>"=, e.g. ="0 years, 3 months"=
|
||||
* separator is
|
||||
* value separator is
|
||||
- used between value and unit, i.e. only applicable with =%= escape character
|
||||
- only used when there is a value present to the left
|
||||
- if unspecified, it is a space (?)
|
||||
* codes -
|
||||
- large units are capitals - =Y= (years), =M= (months), =W= (weeks), =D= (days)
|
||||
- small units are lower-case - =h= (hours), =m= (minutes), =s= (seconds)
|
||||
* if the value is 0, the value and the unit are ignored even if provided in the input string
|
||||
+ optional separator string (=" "= if not provided) is interspersed between each value+unit combination, e.g.
|
||||
#+BEGIN_SRC emacs-lisp :tangle no :load no
|
||||
(format-duration "%m%s" 61 ", ") ;; => "1 minute, 1 second"
|
||||
+ a /unit separator/ is any text between two unit specifiers.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(format-duration "%m, %s" 61) ;; => "1 minute, 1 second"
|
||||
#+END_SRC
|
||||
|
||||
Special cases
|
||||
|
|
Reference in New Issue