format_timedelta Function

public pure function format_timedelta(td) result(str)

Format a timedelta_type as a readable string.

Arguments

Type IntentOptional Attributes Name
type(timedelta_type), intent(in) :: td

Return Value character(len=:), allocatable


Source Code

    pure function format_timedelta(td) result(str)
        !! version: experimental
        !!
        !! Format a timedelta_type as a readable string.
        type(timedelta_type), intent(in) :: td
        character(:), allocatable :: str
        integer :: h, m, s

        h = td%seconds / 3600
        m = mod(td%seconds, 3600) / 60
        s = mod(td%seconds, 60)

        str = to_string(td%days, '(I0)') // ' days, ' // &
              to_string(h, '(I2.2)') // ':' // &
              to_string(m, '(I2.2)') // ':' // &
              to_string(s, '(I2.2)')

        if (td%milliseconds /= 0) then
            str = str // '.' // to_string(td%milliseconds, '(I3.3)')
        end if
    end function format_timedelta