python - Django DST Time change issue with django datetimefield -
python - Django DST Time change issue with django datetimefield -
i facing problem in django app while working datetimefield
.its because of dst time changes.
i have created event on 30-oct-2015(dst lastly week). created re-create of first event on 06-nov-2015(non dst day)
i applied timedelta
of 7 days , chaned days 7+. did not aplly timedelta hours.
due day lite saving , reduced one hour. dont need this. want have same hours. how can that.?
i tried , did not help me.
dst timezone issue in django app
please see screenshot
my models.py
from django.db import models datetime import timedelta class event(models.model): name = models.charfield(max_length=100) created = models.datetimefield(auto_now_add=true) start_date = models.datetimefield() def __unicode__(self): homecoming self.name def copy_event(self, add_days=timedelta(days=7)): start_date = self.start_date + add_days name = self.name +' (copy)' new_event = event(name = name,created = self.created,start_date=start_date,) new_event.save() homecoming new_event
since use_tz=true
dealing aware datetimes, represent precise moment in time. moment in time will, in general, displayed differently depending on current time zone. time zones have dst , don't, in general there's no way can store datetime such users in timezones see clock time want (i.e. same clock time event beingness copied).
i can think of couple workarounds:
if it's case you're serving 1 time zone (that is, current time zone going same), can arithmetic in time zone.
from django.utils.timezone import localtime new_start_date = localtime(self.start_date) + add_days
the add-on of add_days
maintain clock time same (that is, doesn't take dst account). new_start_date
converted , stored in utc, , converted desired local time display.
what you're trying represent particular clock time on particular day, not exact moment in time. perhaps don't want using aware datetimes @ all. 1 alternative set use_tz=false
, that's global, far-reaching alter may not want make. alternative utilize different representation field. example, utilize datefield
, timefield
instead of datetimefield
.
python django dst
Comments
Post a Comment