kyu_4.human_readable_duration_format package

Submodules

kyu_4.human_readable_duration_format.format_duration module

A function which formats a duration, given as a number of seconds, in a human-friendly way.

kyu_4.human_readable_duration_format.format_duration.calc_days(seconds: int) → int[source]

Calculate days

Parameters

seconds

Returns

kyu_4.human_readable_duration_format.format_duration.calc_hours(seconds: int) → int[source]

Calculate hours

Parameters

seconds

Returns

kyu_4.human_readable_duration_format.format_duration.calc_minutes(seconds: int) → int[source]

calculate minutes

Parameters

seconds

Returns

kyu_4.human_readable_duration_format.format_duration.calc_seconds(seconds: int) → int[source]

Calculate seconds

Parameters

seconds

Returns

kyu_4.human_readable_duration_format.format_duration.calc_years(seconds: int) → int[source]

Calculate years

Parameters

seconds

Returns

kyu_4.human_readable_duration_format.format_duration.format_duration(seconds: int) → str[source]

A function which formats a duration, given as a number of seconds, in a human-friendly way.

The resulting expression is made of components like 4 seconds, 1 year, etc. In general, a positive integer and one of the valid units of time, separated by a space. The unit of time is used in plural if the integer is greater than 1.

The components are separated by a comma and a space (“, “). Except the last component, which is separated by ” and “, just like it would be written in English.

A more significant units of time will occur before than a least significant one. Therefore, 1 second and 1 year is not correct, but 1 year and 1 second is.

Different components have different unit of times. So there is not repeated units like in 5 seconds and 1 second.

A component will not appear at all if its value happens to be zero. Hence, 1 minute and 0 seconds is not valid, but it should be just 1 minute.

A unit of time must be used “as much as possible”. It means that the function should not return 61 seconds, but 1 minute and 1 second instead. Formally, the duration specified by of a component must not be greater than any valid more significant unit of time.

Parameters

seconds

Returns

kyu_4.human_readable_duration_format.format_duration.get_string(number: int, string: str) → str[source]

Concatenate string result

Parameters
  • number

  • string

Returns

kyu_4.human_readable_duration_format.test_format_duration module

class kyu_4.human_readable_duration_format.test_format_duration.FormatDurationTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Testing format_duration

test_format_duration()[source]

Test a function which formats a duration, given as a number of seconds, in a human-friendly way.

The function must accept a non-negative integer. If it is zero, it just returns “now”. Otherwise, the duration is expressed as a combination of years, days, hours, minutes and seconds. :return:

Module contents