-
Notifications
You must be signed in to change notification settings - Fork 8
New tabdils and their tests added to time tabdil #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alibayat73
wants to merge
1
commit into
PwPJ:master
Choose a base branch
from
alibayat73:feature-timeTabdil
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,30 @@ | ||
| import pytest | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And these lines?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.