atomica.utils.format_duration

atomica.utils.format_duration(t, pluralize=False)[source]

User-friendly string format of a duration

This helper function is used when displaying durations in plots. It takes in a duration in units of years, and returns a string representation in user-friendly units. This function is mainly intended to be used to format denominators e.g., going from ‘probability’ and ‘1/365’ to ‘probability/day’

Parameters:
  • t (float) – A duration in units of years

  • pluralize – Always return a plural suffix

Return type:

str

Returns:

A string

Example usage:

>>> format_duration(1)
'year'
>>> format_duration(1, pluralize=True)
'years'
>>> format_duration(1/365)
'day'
>>> format_duration(2/365)
'2 days'
>>> format_duration(1.5/52)
'1.5 weeks'
>>> format_duration(2/52)
'fortnight'
>>> format_duration(2.5/12)
'2.5 months'