-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
chore(refactor): Remove arrow dependency from the project #7022
Changes from 2 commits
49f6fce
17abde7
e4290e4
16d0296
c122c2b
26f0c54
4e51df4
ca2ee7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from datetime import datetime | ||
|
||
import humanize | ||
import pytz | ||
|
||
|
||
def humanize_helper(time): | ||
"""Returns time passed from now in a human readable duration""" | ||
|
||
return humanize.naturaldelta(datetime.now(pytz.utc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Black would make changes. |
||
- time.astimezone(pytz.utc)) + ' ago' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continuation line under-indented for visual indent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Humanize adds ago automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it adds ago with naturaltime, not with naturaldelta . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use naturaltime with timedelta
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import arrow | ||
from forex_python.converter import CurrencyCodes | ||
|
||
from app.api.helpers.humanize_helper import humanize_helper | ||
|
||
|
||
def init_filters(app): | ||
@app.template_filter('currency_symbol') | ||
|
@@ -20,5 +21,4 @@ def simple_datetime_display(date): | |
def humanize_filter(time): | ||
if not time: | ||
return "N/A" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can move this logic to the function as well and add a test for it too |
||
# TODO(Areeb): Only usage of arrow. Remove | ||
return arrow.get(time).humanize() | ||
return humanize_helper(time) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no newline at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import datetime | ||
|
||
from app.api.helpers.humanize_helper import humanize_helper | ||
from tests.factories.order import OrderFactory | ||
|
||
|
||
class TestHumanizeHelper(OpenEventTestCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Black would make changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use new pytest style test |
||
def test_humanize_helper(self): | ||
"""Method to test humanization of order creation time""" | ||
|
||
with self.app.test_request_context(): | ||
test_order = OrderFactory(created_at=datetime.datetime.now() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
- datetime.timedelta(days=10)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continuation line over-indented for visual indent |
||
actual_response = humanize_helper(test_order.created_at) | ||
expected_response = '10 days ago' | ||
self.assertEqual(actual_response, expected_response) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no newline at end of file |
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.
No need to create a new file for it, add this function in
filters.py