You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does 0.6 or later support users in different time zones?
I need to support this, but when I set Django to EST (Toronto) I got lots of naive date warnings.
I think I fixed it by adding in use of django.utils.timezone.make_aware(). I added a function to utils.py that "upgrades" any naive dates passed in to use the current TZ setting.
I assume later, when I allow each user to specify their local time zone, this will automatically update the active DJango TZ and allow them to see all events in their local time, and also to correctly interpret any created dates.
Have I totally missed the boat on how this should be handled? Or should I carry on - make some tests and issue a pull request?
Regards,
Rich.
UTILS.py:
# To fix niave datetimes:
from django.utils.timezone import make_aware, is_naive
#-------------------------------------------------------------------------------
def my_make_aware(dt):
'''
Upgrade any naive date/times to current active timezone.
If the passed in date/time already has a time zone setting,
return it as-is. (we don't want to override its TZINFO)
'''
if is_naive(dt):
return make_aware(dt)
else:
return dt
The function is used in the create timeslot table function. In 0.6 the "start_time=" line is not present. I migrated my changes to 0.7.2 but do not know yet if there is a conflict with your changes.
create_timeslot_table()::
dt = dt or datetime.now()
start_time = start_time.replace(tzinfo=dt.tzinfo) if not start_time.tzinfo else start_time
dtstart = my_make_aware(datetime.combine(dt.date(), start_time))
I also made an improvement to the STR value for the Occurrence model:
Does 0.6 or later support users in different time zones?
I need to support this, but when I set Django to EST (Toronto) I got lots of naive date warnings.
I think I fixed it by adding in use of django.utils.timezone.make_aware(). I added a function to utils.py that "upgrades" any naive dates passed in to use the current TZ setting.
I assume later, when I allow each user to specify their local time zone, this will automatically update the active DJango TZ and allow them to see all events in their local time, and also to correctly interpret any created dates.
Have I totally missed the boat on how this should be handled? Or should I carry on - make some tests and issue a pull request?
Regards,
Rich.
UTILS.py:
The function is used in the create timeslot table function. In 0.6 the "start_time=" line is not present. I migrated my changes to 0.7.2 but do not know yet if there is a conflict with your changes.
create_timeslot_table()::
I also made an improvement to the STR value for the Occurrence model:
Using django.utils.localtime() to convert values to the user's TZ and I think a better layout.
The text was updated successfully, but these errors were encountered: