Monday, October 30, 2017

TruncHour with tzinfo throws AmbiguousTimeError

I have a model with a datetime field that is filled with UTC datetime values (time_aware)

I am trying to aggregate data by hours on another timezone ('Europe/Paris'). Last sunday at 2am there has been the day-saving-time impact to local time.

pytz.exceptions.AmbiguousTimeError: 2017-10-29 02:00:00


The problem is that there is no way to tell django that is_dst is True

here is my query:

additional_data = query \

        .annotate(

            hour=TruncHour(

                'datetime',

                tzinfo=pytz.timezone(thermostat.structure.timezone),

                output_field=DateTimeField())) \

        .values('hour') \

        .annotate(

            heat=Avg(Case(When(heating=True, then=1), default=0), output_field=FloatField()),

            cool=Avg(Case(When(cooling=True, then=1), default=0), output_field=FloatField())) \

        .values(

            'hour',

            'heat',

            'cool')


Do you have some ideas how I could workaround this issue?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5ce88fb8-4491-42cd-bf73-8ac73186c901%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment