Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 61 additions & 19 deletions tabdil/time.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove these lines?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't precisely remove any line. I just added some new lines like the comments.
But the way the GitHub shows the differences made you think that I removed anything.


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
46 changes: 30 additions & 16 deletions test/test_time.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import pytest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And these lines?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My answer is the same, didn't remove anything, I swear :)

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