TruncHour with tzinfo throws AmbiguousTimeError

35 views
Skip to first unread message

Vincent T.

unread,
Oct 30, 2017, 7:14:40 AM10/30/17
to Django users
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?

Reply all
Reply to author
Forward
0 new messages