diff --git a/tabdil/time.py b/tabdil/time.py index 8c96b81..7a4dd89 100644 --- a/tabdil/time.py +++ b/tabdil/time.py @@ -1,19 +1,61 @@ - - -def seconds(time_unit): - unit_name = time_unit[0].lower() - number = 1 - if unit_name == 'w': - number = 7 * 24 * 60 * 60 - elif unit_name == 'd': - number = 24 * 60 * 60 - elif unit_name == 'h': - number = 60 * 60 - elif unit_name == 'm': - number = 60 - elif unit_name == 's': - pass - else: - raise ValueError('unknown unit name {!r}'.format(unit_name)) - unit_number = time_unit[1] - return unit_number * number + + +#The function below converts different sorts of time units (weeks,days,hours,minutes) to seconds. + +def second(time_unit): + unit_name = time_unit[0].lower() + number = 1 + if unit_name == 'w': + number = 7 * 24 * 60 * 60 + elif unit_name == 'd': + number = 24 * 60 * 60 + elif unit_name == 'h': + number = 60 * 60 + elif unit_name == 'm': + number = 60 + elif unit_name == 's': + pass + else: + raise ValueError('unknown unit name {!r}'.format(unit_name)) + unit_number = time_unit[1] + return unit_number * number + +#The function below converts different sorts of time units (weeks,days,hours,seconds) to minutes. + +def minute(time_unit): + unit_name = time_unit[0].lower() + number = 1 + if unit_name == 'w': + number = 7 * 24 * 60 + elif unit_name == 'd': + number = 24 * 60 + elif unit_name == 'h': + number = 60 + elif unit_name == 'm': + pass + elif unit_name == 's': + number = 1/60 + else: + raise ValueError('unknown unit name {!r}'.format(unit_name)) + unit_number = time_unit[1] + return unit_number * number + +#The function below converts different sorts of time units (weeks,days,minutes,seconds) to hours. + +def hour(time_unit): + unit_name = time_unit[0].lower() + number = 1 + if unit_name == 'w': + number = 7 * 24 + elif unit_name == 'd': + number = 24 + elif unit_name == 'h': + pass + elif unit_name == 'm': + number = 1/60 + elif unit_name == 's': + number = 1/3600 + else: + raise ValueError('unknown unit name {!r}'.format(unit_name)) + unit_number = time_unit[1] + return unit_number * number diff --git a/test/test_time.py b/test/test_time.py index 9c47db1..8dfb9d0 100644 --- a/test/test_time.py +++ b/test/test_time.py @@ -1,16 +1,30 @@ -import pytest -import sys -from os import getcwd - -# Add module path to python's search path: -sys.path.append(getcwd()) - - -import tabdil - - -def test_seconds(): - assert tabdil.time.seconds(('d', 5)) == 432000 - assert tabdil.time.seconds(('H', 10)) == 36000 - assert tabdil.time.seconds(('m', 13)) == 780 - assert tabdil.time.seconds(('S', 987654321)) == 987654321 +import pytest +import sys +from os import getcwd + +# Add module path to python's search path: +sys.path.append(getcwd()) + + +import tabdil + + +def test_second(): + assert tabdil.time.second(('w', 2)) == 1209600 + assert tabdil.time.second(('d', 5)) == 432000 + assert tabdil.time.second(('H', 10)) == 36000 + assert tabdil.time.second(('m', 13)) == 780 + assert tabdil.time.second(('S', 987654321)) == 987654321 + +def test_minute(): + assert tabdil.time.minute(('w', 2)) == 20160 + assert tabdil.time.minute(('d', 5)) == 7200 + assert tabdil.time.minute(('H', 10)) == 600 + assert tabdil.time.minute(('m', 13)) == 13 + assert tabdil.time.minute(('S', 395340)) == 6589 + +def test_hour(): + assert tabdil.time.hour(('d', 5)) == 120 + assert tabdil.time.hour(('H', 10)) == 10 + assert tabdil.time.hour(('m', 60)) == 1 + assert tabdil.time.hour(('S', 32400)) == 9