-
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
#10
base: master
Are you sure you want to change the base?
Conversation
This doesn't take into account that either class can be "from now" or "ago" depending on whether the time is in the future or the past. When printing, you need to look at the current state of the datetime and determine whether it's in the future or past to know whether to print "from now" or "ago". |
…s to check if the time is in the future or the past
What if the date is actually today? You don't take that into account. |
This needs to be redone to actually add those changes into the code itself, not just the README. |
Modify prettytime.py to take into account if the day is today, and add a print_stdout: bool parameter to the _print() function, defaulting to False, where if False we return string and if True does a true print() |
@@ -139,6 +145,12 @@ def __str__(self): | |||
|
|||
class PrettyDelta(expandeddelta, DeltaMixin): | |||
|
|||
def _print(self): | |||
if datetime.datetime.today() < self.today: |
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.
Modify prettytime.py to take into account if the day is today
Description
This PR adds a new feature to the PrettyTime library that allows users to pretty-print the time when calling
._print()
on any PrettyTime object. The._print()
method returns a string that represents the time in a human-readable format.Summary of Changes
_print()
to thet
class in theprettytime.py
file. This method returns a string that represents the time in a pretty format._print()
to thePrettyDelta
class in theprettytime.py
file. This method returns a string that represents the time in a pretty format._print()
to thePrettyDelta2
class in theprettytime.py
file. This method returns a string that represents the time in a pretty format.README.md
file to include information about the new._print()
method. Added a new section called "Pretty Printing" that explains how to use the._print()
method and provided examples.Please review and merge this PR. Thank you!
Fixes #8.
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.