-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add time pretty-printing functionality when calling ._print() on any PrettyTime object #12
base: master
Are you sure you want to change the base?
Conversation
prettytime.py
Outdated
@@ -110,6 +110,10 @@ def __init__(self, num=None): | |||
self.num = None | |||
self.today = datetime.datetime.today() | |||
|
|||
def _print(self): | |||
time_units = [attr for attr in dir(self) if attr in self.TIME_LIST and getattr(self, attr) != 0] |
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.
use this logic in print instead:
if datetime.datetime.today() < self.today:
return str(self.num) + " " + self.attr + " from now"
else:
return str(self.num) + " " + self.attr + " ago"
prettytime.py
Outdated
if datetime.datetime.today() < self.today: | ||
return str(self.num) + " " + self.attr + " from now" | ||
else: | ||
return str(self.num) + " " + self.attr + " ago" |
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.
fix the duplicate in this function and also add the case when the time is today
Description
This PR adds the functionality to pretty-print time when calling the ._print() method on any PrettyTime object. It introduces a new method, ._print(), in the parent class (t) that handles the pretty-printing of time. This method returns a string representation of the PrettyTime object in a human-readable format.
Summary
Fixes #11.
To checkout this PR branch, run the following command in your terminal:
To get Sweep to edit this pull request, leave a comment below or in the code. Leaving a comment in the code will only modify the file but commenting below can change the entire PR.