Reputation: 3113
Assuming the server (gae) is on the US west coast (PST), an appointment is in New York City (EST) at 10:00am and a person in Chicago (CST) is using his device to know the time of the appointment in NYC.
How can the the person in Chicago's device in CST see that the appointment is at 10am when she goes to the website that resides in EST, and does it matter how the developer, who was in MST, sets up parameters in datetime, time, and calendar using python?
Also, what timezone is "local time" here?
Upvotes: 1
Views: 426
Reputation: 879083
The third-party module, pytz, provides an easy way to convert between timezones. For example,
import datetime as dt
import pytz
utc = pytz.utc
western = pytz.timezone('US/Pacific')
newyork = pytz.timezone('America/New_York')
chicago = pytz.timezone('America/Chicago')
Suppose someone creates an appointment at 10am in New York:
date = dt.datetime(2012, 8, 12, 10) # naive datetime
print(date)
# 2012-08-12 10:00:00
# localize converts naive datetimes to timezone-aware datetimes.
date_in_newyork = newyork.localize(date) # timezone-aware datetime
print(date_in_newyork)
# 2012-08-12 10:00:00-04:00
Your server on the west coast should store this datetime in UTC:
# astimezone converts timezone-aware datetimes to other timezones.
date_in_utc = date_in_newyork.astimezone(utc)
print(date_in_utc)
# 2012-08-12 14:00:00+00:00
Now when the person in Chicago wants to know what time the appointment is, the server can convert UTC to Chicago time, or New York time, or whatever:
date_in_chicago = date_in_utc.astimezone(chicago)
print(date_in_chicago)
# 2012-08-12 09:00:00-05:00
date_in_newyork2 = date_in_utc.astimezone(newyork)
print(date_in_newyork2)
# 2012-08-12 10:00:00-04:00
Upvotes: 2