Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sweep-ai[bot]
Copy link

@sweep-ai sweep-ai bot commented Aug 15, 2023

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

  • Added a new method, ._print(), to the parent class (t) in prettytime.py.
  • The ._print() method returns a string representation of the PrettyTime object in a human-readable format.
  • Updated the README.md file to document the new feature, including usage instructions for the ._print() method.

Fixes #11.


To checkout this PR branch, run the following command in your terminal:

git checkout sweep/add-time-pretty-printing_1

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.

@sweep-ai sweep-ai bot added the sweep Assigns Sweep to an issue or pull request. label Aug 15, 2023
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]
Copy link

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"
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Assigns Sweep to an issue or pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sweep: add time pretty-printing functionality when you call ._print() on any PrettyTime object
1 participant