Add support for a custom period formatter

Refactored `formatPeriod` to a util class so that it can be reused with a custom `PeriodFormatter`