How to handle date difference between client and server?
- by daydreamer
I have an API which looks like
/summary/yyyy/mm
Which returns the summary of their data for the year and month requested.
One of the things it returns the number of days left if this is current year and month. For example: days_left: 9 for 2013 and 10 and current date on server is 21 Oct 2013
How I calculate remaining days?
This is implemented in python as
def current_financial_month_details(self):
time_from, time_to = self \
.get_start_end_time_current_financial_month()
today = datetime.today()
from_time = datetime(year=today.year, month=today.month,
day=today.day)
return {
'time_from': time_from,
'time_to': time_to,
'remaining_days': (time_to - from_time).days
}
The problem?
The server is in east coast and the client(me with browser) is on pacific time zone
When its 9PM PST the time changes in east coast, so if I run hit /summary/2013/10 and if it is Oct 21 2013 for me on PST, the date has already changed on EST, so days_left: 8 which is incorrect on client end. right?
How do I handle this situation?