Skip to content

Rendering pkl durations into yaml #371

Answered by bioball
tuck1s asked this question in Q&A
Discussion options

You must be logged in to vote

Yup, an output converter is exactly where to define this!

This seems like what you want:

output {
  renderer = new YamlRenderer {
    converters {
      [Duration] = (it) ->
        let (days = it.toUnit("d").value.toInt())
        let (hours = it.toUnit("h").value.toInt() % 24)
        let (minutes = it.toUnit("min").value.toInt() % 60)
        let (seconds = it.toUnit("s").value % 60)
          new Listing {
            when (days != 0) {
              days
              "d"
            }
            when (hours != 0) {
              hours
              "h"
            }
            when (minutes != 0) {
              minutes
              "m"
            }
            when (seconds != …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tuck1s
Comment options

@bioball
Comment options

@tuck1s
Comment options

@bioball
Comment options

Answer selected by tuck1s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants