Oblivion-Inverse icon indicating copy to clipboard operation
Oblivion-Inverse copied to clipboard

Tracking Email based on the user's timezone!

Open kailashchoudhary11 opened this issue 2 years ago • 11 comments

Currently the emails are being tracked base on the timezone "Asia/Colombo" Instead we can track it using the timezone of the user!

kailashchoudhary11 avatar Oct 15 '22 02:10 kailashchoudhary11

If this seems a valid issue, I would like to work on it!

kailashchoudhary11 avatar Oct 15 '22 02:10 kailashchoudhary11

At the moment, user has to manually edit routes.py to change their timezone. And it is documented within 'Installation' section of the readme. But, more feasible and efficient way can be implemented here. @kailashchoudhary11 you are welcome to propose your changes anytime 😊

Dilshan-H avatar Oct 15 '22 03:10 Dilshan-H

@Dilshan-H isntead of using generatedOn = str(dt.now().astimezone(pytz.timezone('Asia/Colombo')))

can't we directly use generatedOn = str(dt.now().astimezone())

Won't this give the current timezone of the user? Just a doubt I read it here - GeeksforGeeks

saroshfarhan avatar Oct 15 '22 09:10 saroshfarhan

@Dilshan-H isntead of using generatedOn = str(dt.now().astimezone(pytz.timezone('Asia/Colombo')))

can't we directly use generatedOn = str(dt.now().astimezone())

Won't this give the current timezone of the user? Just a doubt I read it here - GeeksforGeeks

If you are planning to host the application in a local environment, this works just fine. But when it comes to remote servers they are maybe located in different timezones. That's why we need to pass timezone parameter specifically. That way we can get the datetime according to our local time zone. Hope this clarifies you issue 😊

Dilshan-H avatar Oct 15 '22 10:10 Dilshan-H

@Dilshan-H isntead of using generatedOn = str(dt.now().astimezone(pytz.timezone('Asia/Colombo'))) can't we directly use generatedOn = str(dt.now().astimezone()) Won't this give the current timezone of the user? Just a doubt I read it here - GeeksforGeeks

If you are planning to host the application in a local environment, this works just fine. But when it comes to remote servers they are maybe located in different timezones. That's why we need to pass timezone parameter specifically. That way we can get the datetime according to our local time zone. Hope this clarifies you issue 😊

Aah, didn't think of it that way, you're absolutely right. Just had one more doubt, do we really need to show the time of creation of thee tracker to the user? What purpose does that information serve and can we not use utc instead?

saroshfarhan avatar Oct 15 '22 11:10 saroshfarhan

@saroshfarhan It's better to show that info as user can quickly refer their corresponding email at a later time. When there are lot of tracking links this might be useful in a way. Also I'm hoping to implement a search functionality inside tracking link list dashboard. So, a user can search for tracking links that were generated in a specific date for example.

Dilshan-H avatar Oct 15 '22 11:10 Dilshan-H

Hey @Dilshan-H,

We could import tzlocal and could get the local time? You can try this on a separate python file.

we would require tzlocal

pip3 install tzlocal

from datetime import datetime as dt
import pytz
from tzlocal import get_localzone


generatedOn = str(dt.now().astimezone(pytz.timezone(str(get_localzone()))))
print(generatedOn)

Gamerited avatar Oct 16 '22 02:10 Gamerited

I think the better way would be to send the timezone from the browser using js!

kailashchoudhary11 avatar Oct 16 '22 03:10 kailashchoudhary11

I think the better way would be to send the timezone from the browser using js!

Actually that seems like a better way to achieve this.

Hey @Dilshan-H,

We could import tzlocal and could get the local time? You can try this on a separate python file.

we would require tzlocal

pip3 install tzlocal

from datetime import datetime as dt
import pytz
from tzlocal import get_localzone


generatedOn = str(dt.now().astimezone(pytz.timezone(str(get_localzone()))))
print(generatedOn)

It will produce the same issue as earlier isn't it? (When used in remote servers)

Dilshan-H avatar Oct 16 '22 07:10 Dilshan-H

I think the better way would be to send the timezone from the browser using js!

Actually that seems like a better way to achieve this.

So can you assign this to me

kailashchoudhary11 avatar Oct 16 '22 07:10 kailashchoudhary11

It will produce the same issue as earlier isn't it? (When used in remote servers)

It does only solve the backend time issue. Not when it runs on the server.

Gamerited avatar Oct 16 '22 13:10 Gamerited