Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function human-readable-duration now outputs only two significant parts by default. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svetlyak40wt
Copy link

@svetlyak40wt svetlyak40wt commented May 10, 2019

This can be configurable by second optional argument.

LTD> (human-readable-duration (duration :week 42 :day 0 :hour 2 :minute 3 :sec 15 :nsec 214354))
"42 weeks 2 hours"

instead of:

LTD> (human-readable-duration (duration :week 42 :day 0 :hour 2 :minute 3 :sec 15 :nsec 214354))
"42 weeks 2 hours 3 minutes 15 seconds 214354 nsecs"

Using second optional argument, you can set a number of parts to output:

LTD> (human-readable-duration (duration :week 42 :day 0 :hour 2 :minute 3 :sec 15 :nsec 214354)
                              nil
                              4)
"42 weeks 2 hours 3 minutes 15 seconds"

Using third optional argument, you can add support for another language
with proper pluralization:

LTD> (defun russian-format-part (stream part-type value)
       (format stream
               "~A ~A"
               value
               (ecase part-type
                 (:weeks (cl-inflector:pluralize value "неделя" "недель"))
                 (:days (cl-inflector:pluralize value "день" "дней"))
                 (:hours (cl-inflector:pluralize value "час" "часов"))
                 (:minutes (cl-inflector:pluralize value "минута" "минут"))
                 (:secs (cl-inflector:pluralize value "секунда" "секунд"))
                 (:nsecs (cl-inflector:pluralize value "наносекунда" "наносекунд")))))
RUSSIAN-FORMAT-PART
LTD> (human-readable-duration (duration :week 42 :day 0 :hour 2 :minute 3 :sec 15 :nsec 214354)
                              nil
                              4
                              'russian-format-part)
"42 недель 2 часов 3 минут 15 секунд"

…ts by default.

This can be configurable by second optional argument.

Also, third optional argument was added to add ability to translate representation into
other languages. See README for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant