Provide encoding/decoding functions for TimePeriod

The following discussion from !1660 (closed) should be addressed:

  • @nickm started a discussion: (+1 comment)

    Should TimePeriod have a set of encode/decode functions that we can use for this encoding? It seems like otherwise we risk duplicating it a lot.