Skip to content

Conversation

@sweep-ai-deprecated
Copy link

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.

prettytime.py Outdated
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

2 participants