barber icon indicating copy to clipboard operation
barber copied to clipboard

Add a customized localized formatters for DocumentData Duration, Instant, Money types

Open adrw opened this issue 4 years ago • 1 comments

For example, a DocumentData with a paramter of type Money could include a lambda on how to format that anytime it is rendered removing the need for every DocumentData constructor to format before construction.

data class RecipientReceipt(
  val sender: String,
  @BarberField(fomat = { amount ->
    Money.of(amount).asCasual()
  })
  val amount: Money,
  val cancelUrl: String,
  @BarberField(format = { dateTime -> Instant.of(dateTime).format("YYYY-MM-DD") })
  val deposit_expected_at: Instant
) : DocumentData

adrw avatar Apr 11 '20 14:04 adrw

Instead of this, we can make DocumentData a proto and accept Duration, Instant, and Amount/Money as non-string types, then add configurable formatters as configuration methods to the Barbershop

https://github.com/cashapp/barber/pull/51

adrw avatar Oct 05 '20 21:10 adrw