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 #10

Open
wants to merge 5 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 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

  • Added a new method called _print() to the t class in the prettytime.py file. This method returns a string that represents the time in a pretty format.
  • Added a new method called _print() to the PrettyDelta class in the prettytime.py file. This method returns a string that represents the time in a pretty format.
  • Added a new method called _print() to the PrettyDelta2 class in the prettytime.py file. This method returns a string that represents the time in a pretty format.
  • Updated the 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:

git checkout sweep/add-time-pretty-printing

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
@jdotjdot
Copy link
Owner

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
@jdotjdot
Copy link
Owner

What if the date is actually today? You don't take that into account.
Also, can you add a print_stdout: bool parameter to the _print() function, defaulting to False, that False returns string and if True actually does a true print()?

@jdotjdot
Copy link
Owner

This needs to be redone to actually add those changes into the code itself, not just the README.

@wwzeng1
Copy link

wwzeng1 commented Aug 15, 2023

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

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

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