Ignore:
Timestamp:
10 Jul 2014, 12:20:30 (10 years ago)
Author:
Henrik Bettermann
Message:

Make all datetimes timezone aware. Otherwise we can't compare.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r11756 r11757  
    2222from datetime import datetime
    2323from zope.component import getUtility
    24 from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser
     24from waeup.kofa.interfaces import (
     25    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
    2526from waeup.kofa.interfaces import MessageFactory as _
    2627from waeup.kofa.students.catalog import StudentsQuery, CourseTicketsQuery
     
    3031from waeup.kofa.students.vocabularies import study_levels
    3132from waeup.kofa.utils.batching import ExporterBase
    32 from waeup.kofa.utils.helpers import iface_names
     33from waeup.kofa.utils.helpers import iface_names, to_timezone
    3334
    3435#: A tuple containing all exporter names referring to students or
     
    104105        payments_start = datetime.strptime(payments_start, date_format)
    105106        payments_end = datetime.strptime(payments_end, date_format)
     107        tz = getUtility(IKofaUtils).tzinfo
     108        payments_start = tz.localize(payments_start)
     109        payments_end = tz.localize(payments_end)
    106110        if paid:
    107111            # Only paid tickets in payment period are considered
    108112            for student in students:
    109113                for payment in student.get('payments', {}).values():
    110                     if payment.payment_date and payment.p_state == 'paid' and \
    111                         payment.payment_date > payments_start and \
    112                         payment.payment_date < payments_end:
    113                         payments.append(payment)
     114                    if payment.payment_date and payment.p_state == 'paid':
     115                        payment_date = to_timezone(payment.payment_date, tz)
     116                        if payment_date > payments_start and \
     117                            payment_date < payments_end:
     118                            payments.append(payment)
    114119        else:
    115120            # All tickets in payment period are considered
    116121            for student in students:
    117122                for payment in student.get('payments', {}).values():
    118                     if payment.payment_date and payment.payment_date > payments_start and \
    119                         payment.payment_date < payments_end:
    120                         payments.append(payment)
     123                    if payment.payment_date:
     124                        payment_date = to_timezone(payment.payment_date, tz)
     125                        if payment_date > payments_start and \
     126                            payment_date < payments_end:
     127                            payments.append(payment)
    121128    else:
    122129        # Payment period not given
Note: See TracChangeset for help on using the changeset viewer.