Repository: fossasia/open-event-server

Issue:
Remove arrow from project
Only 1 line uses the dependency and can be replaced by other dependencies we are using


Discussion:
I am a beginner can I work on this?
Yes
Hello I am also a beginner and start contributing. Can I work on this issue?
@EkanshMangal as @kaushik397 asked first he will be working on this issue for now, if there is no sign of work done after some days feel free to take this up.

Do read FOSSASIA's contributing best practices [here](https://blog.fossasia.org/open-source-developer-guide-and-best-practices-at-fossasia/)
And please stop spamming while you are at it
hi @iamareebjamal  can i take it if its not resolved , even i'm a beginner
Yes, go ahead
Before commenting on any issue please try to read the previous conversation 😀. 
No response for 4 days, likely not going to continue
It's a tradition to just comment `Can I work on this` and leave
hi @snitin315 , i've  just seen the vedio of aman bhai about gsoc , congratulations for being shortlisted , even im passionate about gsoc can u guide me through the upcoming gsoc??
Yes, definitely, I'll also write my autobiography in GitHub issues
 I'm not be able to clone repositories can you guide me.
Have you even installed and configured git locally?
Yes

```
$ git status
On branch development
Your branch is up to date with 'origin/development'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    .circleci/config.yml
        deleted:    .coveragerc
        deleted:    .deepsource.toml
        deleted:    .dockerignore
        deleted:    .editorconfig
        deleted:    .env.example
        deleted:    .flake8
        ...
        deleted:    utils/common.py
        deleted:    yarn.lock

```
You can't see any file because you just deleted every file.
warning: Clone succeeded, but checkout failed.
after cloning it appears in this way
Please think before pasting logs as long as "A la recherche du temps perdu"
Are you by any chance using Windows?
https://github.com/fossasia/open-event-server/issues/6989
yes

Read the linked issue
where do i find the problem
> #6989


Sorry, i didn't get it.
Read the note https://github.com/fossasia/open-event-server#installation
As im a beginner im not be able to get anything can you explain in breif
I dont even know what is #6989
That is something you need to read
Click on the link and read the issue
Bro , Not yet getting anything
After reading?
I've searched , I didnt get what is #6927
I dont find any thing to read
Did you even click on it. Or give me Teamviewer ID and password and I will click the link for you and make you read it
Unfortunately, if you can't even open a link of an issue and read it, then this issue if too advanced for you
Ya ,This is my first project
But is it your first day on the internet? Have you never opened a link? We have a ton of people everyday who contribute for the first time, everyone can click and read. And the password and ID you shared is not of TeamViewer. You have shared your GitHub ID and password. Has no one told you to not share your credentials to anyone? Please don't give your credit card pin to a stranger asking you nicely. I am honestly amazed. I think before contributing to any project, you need to do this course https://www.microsoft.com/en-us/digitalliteracy/home

To protect you from malicious users, I am deleting the comment which contains your ID and password and request you to change your GitHub password immediately. And judging by your "expertise", I'll assume you have the same password for your email as well. Please change it immediately as well, and please use generated passwords from a password manager. And don't forget its master password. And please definitely don't share it to a stranger asking for a teamviewer ID and password :man_shrugging: 
Also, enable two-factor authentication.
Sorry 😅 can u once share me the link
Shared 3 times already
Can I work on this issue?
@mansiag Sure, go ahead.
@prateekj117 @iamareebjamal what I understand is, here arrow takes the timezone aware datetime object and humanizes it. Timezone plays a role in this as the datetime values are stored (in database) in that timezone only, along with an attribute to store the timezone.
For ex - 
`datetime.datetime(2020, 5, 19, 12, 54, 31, 756604, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=330, name=None)) `
So, it calculates the correct time passed by considering the timezone.
We can replace arrow by using humanize library, but humanize library do not consider timezone of the datetime value, it calculates time difference by considering the timezone of the location where the function is being called, so it may give incorrect result.
That can be solved by replacing the tzinfo of both datetimes to utc, then relative time will be correct

Resolving patch:
diff --git a/app/templates/flask_ext/jinja/filters.py b/app/templates/flask_ext/jinja/filters.py
--- a/app/templates/flask_ext/jinja/filters.py
+++ b/app/templates/flask_ext/jinja/filters.py
@@ -1,6 +1,16 @@
-import arrow
+from datetime import datetime
+
 from forex_python.converter import CurrencyCodes
+import humanize
+import pytz
+
+
+def humanize_helper(time):
+    """Returns time passed from now in a human readable duration"""
 
+    if not time:
+        return "N/A"
+    return humanize.naturaltime(datetime.now(pytz.utc) - time.astimezone(pytz.utc))
 
 def init_filters(app):
     @app.template_filter('currency_symbol')
@@ -18,7 +28,4 @@ def simple_datetime_display(date):
 
     @app.template_filter('humanize')
     def humanize_filter(time):
-        if not time:
-            return "N/A"
-        # TODO(Areeb): Only usage of arrow. Remove
-        return arrow.get(time).humanize()
+        return humanize_helper(time)


Test patch:
diff --git a/tests/all/integration/api/helpers/test_humanize_helper.py b/tests/all/integration/api/helpers/test_humanize_helper.py
new file mode 100644
--- /dev/null
+++ b/tests/all/integration/api/helpers/test_humanize_helper.py
@@ -0,0 +1,19 @@
+import datetime
+
+from app.templates.flask_ext.jinja.filters import humanize_helper
+from tests.factories.order import OrderFactory
+
+
+def test_humanize_helper(db):
+    """Method to test humanization of order creation time"""
+
+    test_order = OrderFactory(
+        created_at=datetime.datetime.now() - datetime.timedelta(days=10)
+    )
+    actual_response = humanize_helper(test_order.created_at)
+    expected_response = '10 days ago'
+    assert actual_response == expected_response
+
+    actual_response = humanize_helper(test_order.completed_at)
+    expected_response = 'N/A'
+    assert actual_response == expected_response